<?php

namespace KupShop\KupShopBundle\Tests;

use KupShop\DevelopmentBundle\Util\Tests\ContainerAwareTestTrait;
use KupShop\KupShopBundle\Util\Mail\Preprocessor;

class PreprocessorTest extends \PHPUnit\Framework\TestCase
{
    use ContainerAwareTestTrait;

    /** @var Preprocessor */
    protected $preprocessor;

    protected function setUp(): void
    {
        $this->preprocessor = $this->get(Preprocessor::class);
    }

    public function testAbsolutizeUrls()
    {
        $html = 'test <a href="/relativni/">odkaz</a> pokus <a href="http://test.cz">odkaz</a> test2';
        $absoluteHtml = 'test <a href="https://www.kupshop.local/relativni/">odkaz</a> pokus <a href="http://test.cz">odkaz</a> test2';

        $this->assertEquals($absoluteHtml, $this->preprocessor->absolutizeUrls($html));
    }

    public function testAbsolutizeUrlsUTMCampaign()
    {
        $html = '
1:a czdomena 
<a href="http://www.czdomena.cz">odkaz</a> 
2:a relativni 
<a href="/relativni/">odkaz</a> 
3:a test.cz 
<a href="https://test.cz">odkaz</a>  
4:img relativni 
<img src="/relativni/tmp/image.jpg"> 
5:a kupshop.local ? 
<a href="https://www.kupshop.local/relativni/test.php?s=qwerty&a=asdfg">odkaz</a> 
6:a test.cz
<a href="http://test.cz/?s=qwerty">odkaz</a> 
7:img relativni 
<img src="/relativni/tmp/image.jpg"> 
8:a skdomena 
<a href="https://www.skdomena.sk/relativni/test.php">odkaz</a>';
        $absoluteHtml = '
1:a czdomena 
<a href="http://www.czdomena.cz/?utm_source=notification&utm_medium=email&utm_campaign=utm_campaign">odkaz</a> 
2:a relativni 
<a href="https://www.kupshop.local/relativni/?utm_source=notification&utm_medium=email&utm_campaign=utm_campaign">odkaz</a> 
3:a test.cz 
<a href="https://test.cz">odkaz</a>  
4:img relativni 
<img src="https://www.kupshop.local/relativni/tmp/image.jpg"> 
5:a kupshop.local ? 
<a href="https://www.kupshop.local/relativni/test.php?s=qwerty&a=asdfg&utm_source=notification&utm_medium=email&utm_campaign=utm_campaign">odkaz</a> 
6:a test.cz
<a href="http://test.cz/?s=qwerty">odkaz</a> 
7:img relativni 
<img src="https://www.kupshop.local/relativni/tmp/image.jpg"> 
8:a skdomena 
<a href="https://www.skdomena.sk/relativni/test.php?utm_source=notification&utm_medium=email&utm_campaign=utm_campaign">odkaz</a>';

        $this->assertEquals($absoluteHtml, $this->preprocessor->absolutizeUrls($html, 'utm_campaign'));
    }
}
