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

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

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

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

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

  /**
   * @test
   */
  public function testMkText()
  {
    $this->assertSearchMapAndQuery(array('mktext' => 'vhs-Haus'));
  }

  /**
   * @test
   */
  public function testGebaeude()
  {
    $this->assertSearchMapAndQuery(array('gebaeude' => 'Gymnasium'));
  }

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

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

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

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

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

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