SuiteCRM-Core/tests/unit/core/legacy/AppStringsHandlerTest.php
Dillon-Brown 674af51eea Update test namespaces
Signed-off-by: Dillon-Brown <dillon.brown@salesagility.com>
2021-03-30 19:22:42 +01:00

86 lines
2.6 KiB
PHP

<?php
namespace App\Tests\unit\core\legacy;
use ApiPlatform\Core\Exception\ItemNotFoundException;
use App\Languages\Entity\AppStrings;
use App\Tests\UnitTester;
use Codeception\Test\Unit;
use App\Languages\LegacyHandler\AppStringsHandler;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
/**
* Class AppStringsHandlerTest
* @package App\Tests\unit\core\legacy
*/
class AppStringsHandlerTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
/**
* @var AppStringsHandler
*/
protected $handler;
protected function _before(): void
{
$session = new Session(new MockArraySessionStorage('PHPSESSID'));
$session->start();
$this->handler = new AppStringsHandler(
$this->tester->getProjectDir(),
$this->tester->getLegacyDir(),
$this->tester->getLegacySessionName(),
$this->tester->getDefaultSessionName(),
$this->tester->getLegacyScope(),
$session
);
}
// tests
/**
* Test Invalid language handling in AppStringsHandler
*/
public function testInvalidLanguageCheck(): void
{
$this->expectException(ItemNotFoundException::class);
$this->handler->getAppStrings('invalid_lang');
}
/**
* Test default language retrieval in AppStringsHandler
*/
public function testDefaultLanguageKey(): void
{
$appStrings = $this->handler->getAppStrings('en_us');
static::assertNotNull($appStrings);
static::assertEquals('en_us', $appStrings->getId());
static::assertIsArray($appStrings->getItems());
$this->assertLanguageKey('LBL_LOGOUT', $appStrings);
$this->assertLanguageKey('LBL_LOGIN_BUTTON_LABEL', $appStrings);
$this->assertLanguageKey('LBL_LOGIN_BUTTON_TITLE', $appStrings);
$this->assertLanguageKey('LBL_LOGIN_FORGOT_PASSWORD', $appStrings);
$this->assertLanguageKey('LBL_LOGIN_SUBMIT', $appStrings);
$this->assertLanguageKey('LBL_USER_NAME', $appStrings);
$this->assertLanguageKey('LBL_USER_NAME', $appStrings);
$this->assertLanguageKey('ERR_INVALID_PASSWORD', $appStrings);
$this->assertLanguageKey('LBL_PASSWORD', $appStrings);
}
/**
* Asserts that the given label $key exists in appStrings
* @param string $key
* @param AppStrings $appStrings
*/
protected function assertLanguageKey($key, AppStrings $appStrings): void
{
static::assertArrayHasKey($key, $appStrings->getItems());
static::assertNotEmpty($appStrings->getItems()[$key]);
}
}