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

class StornoLinkTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var URL
   */
  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
  {
  }

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

  /**
   * @covers StornoLink::getStornoLink
   * @test
   */
  public function getStornoLink_CorrectPattern_ReplacesBelegidStornohashCorrectly()
  {
    $sut = new \Kufer\Web\Classes\Anmeldung\OnlinePortal\StornoLink(123, 'abcd324ef');
    $pattern = 'https://service.kufer.de/abmelden?b=<BELEGID>&h=<STORNOHASH>';
    $expected = 'https://service.kufer.de/abmelden?b=123&h=abcd324ef';

    $result = $sut->getStornoLink($pattern);

    $this->assertEquals($expected, $result);
  }

  /**
   * @covers StornoLink::getStornoLink
   * @test
   */
  public function getStornoLink_IncorrectPlaceholder_PlaceholderIsNotReplaced()
  {
    $sut = new \Kufer\Web\Classes\Anmeldung\OnlinePortal\StornoLink(123, 'abcd324ef');
    $pattern = 'https://service.kufer.de/abmelden?b=<BELEGUNGSNR>&h=<STORNOHASH>';
    $expected = 'https://service.kufer.de/abmelden?b=<BELEGUNGSNR>&h=abcd324ef';

    $result = $sut->getStornoLink($pattern);

    $this->assertEquals($expected, $result);
  }
}
