<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

use Kufer\Web\KuferTools\Utils\FilterSearch\TeilnehmerSearchFilter;

class TeilnehmerSearchFilterIntegrationTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var \Kufer\Web\KuferTools\Utils\FilterSearch\TeilnehmerSearchFilter
   */
  protected $object;

  /**
   * Sets up the fixture, for example, opens a network connection.
   * This method is called before a test is executed.
   */
  protected function setUp(): void
  {
    $this->object = new TeilnehmerSearchFilter();
  }

  /**
   * Tears down the fixture, for example, closes a network connection.
   * This method is called after a test is executed.
   */
  protected function tearDown(): void
  {
  }

  protected function assertSearchMapAndQuery(array $searchMap)
  {
    $dbwTeilnehmer = \DBWorkTeilnehmer::getDefaultInstance();
    $filter = \Kufer\Web\Classes\Dbfilter\TeilnehmerSQLFilter::create();
    $filter = $this->object->applySearch($filter, $searchMap);
    $dbwTeilnehmer->countByFilter($filter);

    $this->assertNotEmpty($filter->createSql($dbwTeilnehmer->dboperation));
    $this->assertTrue(true); // Hier kommt man nur an wenn keine Exception
  }

  /**
   * @test
   */
  public function testName()
  {
    $this->assertSearchMapAndQuery(array('name' => 'Mustermann'));
  }

  /**
   * @test
   */
  public function testVorname()
  {
    $this->assertSearchMapAndQuery(array('vorname' => 'Max'));
  }

  /**
   * @test
   */
  public function testTnr()
  {
    $this->assertSearchMapAndQuery(array('tnr' => '1'));
    $this->assertSearchMapAndQuery(array('tnr' => 1));
  }

  /**
   * @test
   */
  public function testPersonalnummer()
  {
    $this->assertSearchMapAndQuery(array('pnr' => 'Personalnummer'));
  }

  /**
   * @test
   */
  public function testAusweisnummer()
  {
    $this->assertSearchMapAndQuery(array('ausweisnr' => 'Ausweisnummer'));
  }

  /**
   * @test
   */
  public function testWohnort()
  {
    $this->assertSearchMapAndQuery(array('wohnort' => 'Mühldorf'));
  }

  /**
   * @test
   */
  public function testStrasse()
  {
    $this->assertSearchMapAndQuery(array('strasse' => 'Straße'));
  }

  /**
   * @test
   */
  public function testZusatz()
  {
    $this->assertSearchMapAndQuery(array('zusatz' => 'Zusatz'));
  }
}
