2023-06-14 19:54:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Joomla.UnitTest
|
|
|
|
* @subpackage Base
|
|
|
|
*
|
|
|
|
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Joomla\Tests\Unit\Libraries\Cms\Language;
|
|
|
|
|
|
|
|
use Joomla\CMS\Language\Language;
|
2023-08-23 10:06:44 +00:00
|
|
|
use Joomla\CMS\Language\LanguageAwareTrait;
|
2023-06-14 19:54:12 +00:00
|
|
|
use Joomla\Tests\Unit\UnitTestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test class for \Joomla\CMS\Language\LanguageAwareTrait
|
|
|
|
*
|
|
|
|
* @package Joomla.UnitTest
|
|
|
|
* @subpackage MVC
|
2023-06-24 13:18:57 +00:00
|
|
|
* @since 4.4.0
|
2023-06-14 19:54:12 +00:00
|
|
|
*/
|
|
|
|
class LanguageAwareTraitTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @testdox The user language can be set and accessed by the trait
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2023-06-24 13:18:57 +00:00
|
|
|
* @since 4.4.0
|
2023-06-14 19:54:12 +00:00
|
|
|
*/
|
|
|
|
public function testGetSetLanguage()
|
|
|
|
{
|
|
|
|
$language = new Language();
|
|
|
|
$trait = new class () {
|
|
|
|
use LanguageAwareTrait;
|
|
|
|
|
|
|
|
public function get(): Language
|
|
|
|
{
|
|
|
|
return $this->getLanguage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$trait->setLanguage($language);
|
|
|
|
|
|
|
|
$this->assertEquals($language, $trait->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @testdox The user language can be set and accessed by the trait
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2023-06-24 13:18:57 +00:00
|
|
|
* @since 4.4.0
|
2023-06-14 19:54:12 +00:00
|
|
|
*/
|
|
|
|
public function testGetLanguageThrowsException()
|
|
|
|
{
|
2023-06-28 12:01:50 +00:00
|
|
|
$this->expectException(\UnexpectedValueException::class);
|
2023-06-14 19:54:12 +00:00
|
|
|
|
|
|
|
$trait = new class () {
|
|
|
|
use LanguageAwareTrait;
|
|
|
|
|
|
|
|
public function get(): Language
|
|
|
|
{
|
|
|
|
return $this->getLanguage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$trait->get();
|
|
|
|
}
|
|
|
|
}
|