<?php

namespace goodboyalex\php_components_pack\tests\extensions;

use goodboyalex\php_components_pack\extensions\StringExtension;
use PHPUnit\Framework\TestCase;

class StringExtensionTest extends TestCase
{

    public function testIsNullOrWhitespace ()
    {
        $this->PrepareForTest();

        $this->assertTrue(StringExtension::isNullOrWhitespace(''));
        $this->assertTrue(StringExtension::isNullOrWhitespace(' '));
        $this->assertTrue(StringExtension::isNullOrWhitespace(null));
        $this->assertFalse(StringExtension::isNullOrWhitespace('TEST'));

    }

    private function PrepareForTest (): void
    {
        require_once __DIR__ . '/../../sources/extensions/StringExtension.php';
    }

    public function testConvertToLatin ()
    {
        $this->PrepareForTest();

        $this->assertEquals('test', StringExtension::ConvertToLatin('тест'));
        $this->assertEquals('test', StringExtension::ConvertToLatin('test'));

    }

    public function testIsNullOrEmpty ()
    {
        $this->PrepareForTest();

        $this->assertTrue(StringExtension::isNullOrEmpty(''));
        $this->assertTrue(StringExtension::isNullOrEmpty(null));
        $this->assertFalse(StringExtension::isNullOrEmpty('TEST'));

    }

    public function testCompare ()
    {
        $this->PrepareForTest();

        $this->assertEquals(0, StringExtension::Compare('test', 'test'));
        $this->assertEquals(-1, StringExtension::Compare('test', 'test1'));
        $this->assertEquals(1, StringExtension::Compare('test2', 'test'));
    }

    public function testGetShortText ()
    {
        $this->PrepareForTest();

        $this->assertEquals('test', StringExtension::GetShortText('test', 4));
        $this->assertEquals('test', StringExtension::GetShortText('test', 10));
        $this->assertEquals('test', StringExtension::GetShortText('test of this', 4));
        $this->assertEquals('t', StringExtension::GetShortText('test', 1));
        $this->assertEquals('', StringExtension::GetShortText('test', 0));

    }
}
