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

class TeilnehmerPflichtTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var TeilnehmerPflicht
   */
  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 TeilnehmerPflicht();
  }

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

  /**
   * @covers TeilnehmerPflicht::getVarValue
   * @test
   */
  public function getVarValue_nurPLZ_valid()
  {
    $this->object->setValue2Var('ort', '84453 Mühldorf');
    $this->assertEquals('84453', $this->object->getVarValue('nurplz'));
  }

  /**
   * @covers TeilnehmerPflicht::getVarValue
   * @test
   */
  public function getVarValue_nurPLZ_noPlzInOrt_ReturnsNothing()
  {
    if (\ToolSettingsAPI::getToolSettings(4)->plzValidierung == VALIDIERUNG_PLZ_KEINE) {
      $this->assertTrue(false, 'Momentan keine Test hier wenn keine Validierung');
    }

    $this->object->setValue2Var('ort', 'Mühldorf');
    $this->assertEquals('', $this->object->getVarValue('nurplz'));
  }

  /**
   * @covers TeilnehmerPflicht::gleicheMehrfacheInfosAb
   * @test
   */
  public function gleicheMehrfacheInfosAb_nurOrtIsGiven_ortIsSetCorrectly()
  {
    $expected = 'myOrt';
    $this->object->nurort = $expected;
    \Kufer\Web\Classes\Addfunctions\PlzOperations::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;

    $this->object->gleicheMehrfacheInfosAb();
    $this->assertEquals($expected, $this->object->getVarValue('ort'));
    $this->assertEquals('', $this->object->getVarValue('nurplz'));
    $this->assertEquals($expected, $this->object->getVarValue('nurort'));
    \Kufer\Web\Classes\Addfunctions\PlzOperations::$enforcePlzValidationSetting = false;
  }

  /**
   * @covers TeilnehmerPflicht::getVarValue
   * @test
   */
  public function getVarValue_nurOrtIsGiven_nurPlzIsCorrect()
  {
    $this->object->nurort = 'myOrt';
    \Kufer\Web\Classes\Addfunctions\PlzOperations::$enforcePlzValidationSetting = VALIDIERUNG_PLZ_KEINE;

    $this->assertEquals('', $this->object->getVarValue('nurplz'));
    \Kufer\Web\Classes\Addfunctions\PlzOperations::$enforcePlzValidationSetting = false;
  }
}
