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

class KursorteUebersichtSearchFilterIntegrationTest 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 \Kufer\Web\KuferTools\Utils\FilterSearch\KursorteUebersichtSearchFilter();
  }

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

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

  public function testGebauedeEmpty()
  {
    $this->assertSearchMapAndQuery(array('gebaeude' => array()), true);
    $this->assertSearchMapAndQuery(array('gebaeude' => ''), true);
  }

  public function testGebaeude()
  {
    $this->assertSearchMapAndQuery(array('gebaeude' => array('-')));
  }
}
