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

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

class DozentenSearchFilterIntegrationTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var \Kufer\Web\KuferTools\Utils\FilterSearch\DozentenSearchFilter
   */
  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 DozentenSearchFilter();
  }

  /**
   * 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)
  {
    $dbwDozenten = \DBWorkDozenten::getDefaultInstance();
    $filter = \Kufer\Web\Classes\Dbfilter\DozentenSQLFilter::create();
    $filter = $this->object->applySearch($filter, $searchMap);
    $dbwDozenten->countByFilter($filter);

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

  /**
   * @test
   */
  public function testDozNr()
  {
    $this->assertSearchMapAndQuery(array('doznr' => 10));
  }

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

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

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

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

  /**
   * @test
   */
  public function testFachbereich()
  {
    $this->assertSearchMapAndQuery(array('fachbereich' => '35'));
    $this->assertSearchMapAndQuery(array('fachbereich' => 35));
  }

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

  /**
   * @test
   */
  public function testFreidef()
  {
    $this->assertSearchMapAndQuery(array('krit1' => 'W'));
    $this->assertSearchMapAndQuery(array('krit1' => 'F'));
    $this->assertSearchMapAndQuery(array('krit2' => 'F'));
  }

  /**
   * @test
   */
  public function testFach()
  {
    $this->assertSearchMapAndQuery(array('fach' => 10));
  }

  /**
   * @test
   */
  public function testBranchenName()
  {
    $this->assertSearchMapAndQuery(array('branchen_name' => 'Something'));
  }

  /**
   * @test
   */
  public function testGemeinde()
  {
    $this->assertSearchMapAndQuery(array('gemeinde' => 'Gemeinde'));
  }

  /**
   * @test
   */
  public function testBezirk()
  {
    $this->assertSearchMapAndQuery(array('bezirk' => 'Bezirk'));
  }

  /**
   * @test
   */
  public function testEinsatzbezirk()
  {
    $this->assertSearchMapAndQuery(array('einsatzbezirk' => 'Bezirk'));
  }

  /**
   * @test
   */
  public function testStadtteil()
  {
    $this->assertSearchMapAndQuery(array('stadtteil' => 'Stadtteil'));
  }

  /**
   * @test
   */
  public function testBundesland()
  {
    $this->assertSearchMapAndQuery(array('bundesland' => 'Bayern'));
  }

  /**
   * @test
   */
  public function testVeranstalterDozNr()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_doznr' => 10));
  }

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

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

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

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

  /**
   * @test
   */
  public function testVeranstalterFachbereich()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_fachbereich' => '35'));
    $this->assertSearchMapAndQuery(array('veranstalter_fachbereich' => 35));
  }

  /**
   * @test
   */
  public function testVeranstalterPersonalnummer()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_pnr' => 'SC-131256'));
  }

  /**
   * @test
   */
  public function testVeranstalterFreidef()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_krit1' => 'W'));
    $this->assertSearchMapAndQuery(array('veranstalter_krit1' => 'F'));
    $this->assertSearchMapAndQuery(array('veranstalter_krit2' => 'F'));
  }

  /**
   * @test
   */
  public function testVeranstalterBranchenName()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_fach' => 10));
  }

  /**
   * @test
   */
  public function testVeranstalterGemeinde()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_gemeinde' => 'Gemeinde'));
  }

  /**
   * @test
   */
  public function testVeranstalterBezirk()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_bezirk' => 'Bezirk'));
  }

  /**
   * @test
   */
  public function testVeranstalterStadtteil()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_stadtteil' => 'Stadtteil'));
  }

  /**
   * @test
   */
  public function testVeranstalterBundesland()
  {
    $this->assertSearchMapAndQuery(array('veranstalter_bundesland' => 'Bayern'));
  }

  /**
   * @test
   */
  public function testKennzeichenKennz()
  {
    $this->assertSearchMapAndQuery(array('kennzeichen_kennz' => '10'));
    $this->assertSearchMapAndQuery(array('kennzeichen_kennz' => 10));
  }

  /**
   * @test
   */
  public function testKennzeichenNotKennz()
  {
    $this->assertSearchMapAndQuery(array('kennzeichen_not_kennz' => '10'));
    $this->assertSearchMapAndQuery(array('kennzeichen_not_kennz' => 10));
  }

  /**
   * @test
   */
  public function testKrit()
  {
    for ($i = 1; $i <= 16; $i++) {
      $this->assertSearchMapAndQuery(array("krit$i" => 'W'));
    }
  }

  /**
   * @test
   */
  public function testKursStichwort()
  {
    $this->assertSearchMapAndQuery(array('kurs_stichwort' => '211-'));
  }

  /**
   * @test
   */
  public function testKennzeichenNummer()
  {
    $this->assertSearchMapAndQuery(array('kennzeichen_nummer' => 12));
  }

  /**
   * @test
   */
  public function testNichtKennzeichenNummer()
  {
    $this->assertSearchMapAndQuery(array('nicht_kennzeichen_nummer' => 12));
  }

  /**
   * @test
   */
  public function testNameVorname()
  {
    $this->assertSearchMapAndQuery(array('namevorname' => 'Lex Andrea'));
    $this->assertSearchMapAndQuery(array('namevorname' => 'Lex'));
    $this->assertSearchMapAndQuery(array('namevorname' => 'Andrea'));
  }
}
