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

class DBWorkKennzTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var DBWorkKennz
   */
  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
  {
    System::setOverrideDbName('MYSQL');

    $this->object = new DBWorkKennz();
    $this->object->dboperation->dbparser->servertyp = 'MYSQL';

    $this->object->newSearch();
  }

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

  /**
   * @covers DBWorkKurse::setOrderByValues
   * @test
   */
  public function getSearchSql_kennz_fromAndTo()
  {
    $this->object->fromobject->kennz = 5;
    $this->object->toobject->kennz = 10;
    $prefix = 'ke.';
    $expected = ' ke.kennz >= 5 AND ke.kennz <= 10';

    $actual = $this->object->getSearchSQL($prefix);
    $this->assertEquals($expected, $actual);
  }

  /**
   * @covers DBWorkKurse::setOrderByValues
   * @test
   */
  public function getSearchSql_kennz_from()
  {
    $this->object->fromobject->kennz = 5;
    $prefix = 'ke.';
    $expected = ' ke.kennz >= 5';

    $actual = $this->object->getSearchSQL($prefix);
    $this->assertEquals($expected, $actual);
  }

  /**
   * @covers DBWorkKurse::setOrderByValues
   * @test
   */
  public function getSearchSql_kennz_To()
  {
    $this->object->toobject->kennz = 10;
    $prefix = 'ke.';
    $expected = ' ke.kennz <= 10';

    $actual = $this->object->getSearchSQL($prefix);
    $this->assertEquals($expected, $actual);
  }

  /**
   * @covers DBWorkKurse::getSearchSql
   * @test
   */
  public function getSearchSql_noCriteria()
  {
    $prefix = 'ke.';
    $expected = '';

    $actual = $this->object->getSearchSQL($prefix);
    $this->assertEquals($expected, $actual);
  }
}
