<?php /** @noinspection HttpUrlsUsage */

namespace App\Tests\Unit\Service\Utils;

use App\Service\Utils\UrlBuilder;
use PHPUnit\Framework\TestCase;

class UrlBuilderTest extends TestCase
{
    /**
     * @see UrlBuilder::concatPath()
     */
    public function testConcatPath(): void
    {
        $this->assertEquals(
            'https://domain.org/abc/def',
            UrlBuilder::concatPath('https://domain.org', 'abc/def')
        );
        $this->assertEquals(
            'https://domain.org/abc/def',
            UrlBuilder::concatPath('https://domain.org/', '/abc/def')
        );
        $this->assertEquals(
            'https://domain.org/',
            UrlBuilder::concatPath('https://domain.org', '')
        );
    }

    /**
     * @see UrlBuilder::concatParameters()
     */
    public function testConcatParameters(): void
    {
        $this->assertEquals(
            'https://domain.org/abc',
            UrlBuilder::concatParameters('https://domain.org/abc', [])
        );
        $this->assertEquals(
            'https://domain.org/abc?a=1&b&c=d%3De',
            UrlBuilder::concatParameters('https://domain.org/abc', ['a' => 1, 'b' => '', 'c' => 'd=e'])
        );
        $this->assertEquals(
            'https://domain.org/abc?a=1&b=2',
            UrlBuilder::concatParameters('https://domain.org/abc?a=1', ['b' => 2])
        );
    }

    /**
     * @see UrlBuilder::prependHttps()
     */
    public function testPrependHttps(): void
    {
        $this->assertEquals(
            'https://domain.org/abc',
            UrlBuilder::prependHttps('https://domain.org/abc')
        );
        $this->assertEquals(
            'http://domain.org/abc',
            UrlBuilder::prependHttps('http://domain.org/abc')
        );
        $this->assertEquals(
            'https://domain.org/abc',
            UrlBuilder::prependHttps('domain.org/abc')
        );
    }

    /**
     * @see UrlBuilder::concat()
     */
    public function testConcat(): void
    {
        $this->assertEquals(
            'https://domain.org/abc?a=1',
            UrlBuilder::concat('domain.org', 'abc', ['a' => 1], true)
        );
    }
}
