<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

use Kufer\Web\Classes\Addfunctions;

class PlzOperationsTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var \Addfunctions\PlzOperations
   */
  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\Classes\Addfunctions\PlzOperations();
  }

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

  /**
   * @covers PlzOperations::getOrtStrFromPlzOrt
   * @test
   */
  public function getOrtStrFromPlzOrt_NoPlzValidationOnlyOrtIsGiven_ReturnsOrt()
  {
    //don't double up
    $this->object::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;
    $expected = 'myOrt';
    $res = $this->object->getOrtStrFromPlzOrt('', '', $expected);
    $this->assertEquals($expected, $res);
    $this->object::$enforcePlzValidationSetting = false;
  }

  /**
   * @covers PlzOperations::getPlzOhneOrt
   * @test
   */
  public function getPlzOhneOrt_NoPlzValidationOrtWithoutNumber_ReturnsEmptyString()
  {
    $this->object::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;
    $ort = 'myOrt';
    $res = $this->object->getPlzOhneOrt($ort);
    $this->assertEquals('', $res);
    $this->object::$enforcePlzValidationSetting = false;
  }

  /**
   * @covers PlzOperations::getPlzOhneOrt
   * @test
   */
  public function getPlzOhneOrt_NoPlzValidationOrtContainingNumber_ReturnsOrt()
  {
    $this->object::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;
    $ort = 'myOrt1';
    $res = $this->object->getPlzOhneOrt($ort);
    $this->assertEquals($ort, $res);
    $this->object::$enforcePlzValidationSetting = false;
  }

  /**
   * @covers PlzOperations::getOrtOhnePlz
   * @test
   */
  public function getOrtOhnePlz_NoPlzValidationOrtWithoutNumber_ReturnsOrt()
  {
    $this->object::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;
    $ort = 'myOrt';
    $res = $this->object->getOrtOhnePlz($ort);
    $this->assertEquals($ort, $res);
    $this->object::$enforcePlzValidationSetting = false;
  }

  /**
   * @covers PlzOperations::getOrtOhnePlz
   * @test
   */
  public function getOrtOhnePlz_NoPlzValidationOrtContainingNumber_ReturnsEmptyString()
  {
    $this->object::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;
    $ort = 'myOrt1';
    $res = $this->object->getOrtOhnePlz($ort);
    $this->assertEquals('', $res);
    $this->object::$enforcePlzValidationSetting = false;
  }
}
