class LocaleProjectRepositoryTest
Tests Drupal\locale\LocaleProjectRepository.
Attributes
#[CoversClass(LocaleProjectRepository::class)]
#[Group('locale')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\locale\Unit\LocaleProjectRepositoryTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of LocaleProjectRepositoryTest
File
-
core/
modules/ locale/ tests/ src/ Unit/ LocaleProjectRepositoryTest.php, line 23
Namespace
Drupal\Tests\locale\UnitView source
class LocaleProjectRepositoryTest extends UnitTestCase {
/**
* The local project storage.
*
* @var \Drupal\locale\LocaleProjectRepository
*/
private LocaleProjectRepository $localeProjectRepository;
/**
* The key value memory factory.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
private CacheBackendInterface $cache;
/**
* The key value memory factory.
*
* @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory
*/
private KeyValueMemoryFactory $keyValueMemoryFactory;
/**
* The key value memory factory.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
private ModuleHandlerInterface $moduleHandler;
/**
* The key value memory factory.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
private ModuleExtensionList $moduleExtensionList;
/**
* The key value memory factory.
*
* @var \Drupal\Core\Extension\ThemeExtensionList
*/
private ThemeExtensionList $themeExtensionList;
/**
* The key value memory factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
private ConfigFactoryInterface $config;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->cache = $this->createStub(CacheBackendInterface::class);
$this->keyValueMemoryFactory = new KeyValueMemoryFactory();
$this->moduleHandler = $this->createStub(ModuleHandlerInterface::class);
$this->moduleExtensionList = $this->createStub(ModuleExtensionList::class);
$this->themeExtensionList = $this->createStub(ThemeExtensionList::class);
$this->config = $this->createStub(ConfigFactoryInterface::class);
$this->localeProjectRepository = new LocaleProjectRepository($this->cache, $this->keyValueMemoryFactory, $this->moduleHandler, $this->moduleExtensionList, $this->themeExtensionList, $this->config);
}
/**
* Tests that projects are sorted by weight and key.
*/
public function testSorting() : void {
// Add project 'b'.
$b = new LocaleTranslatableProject('b', 'b', 'b', 'b', 'b');
$this->localeProjectRepository
->set($b);
$this->assertSame([
'b',
], array_keys($this->localeProjectRepository
->getAll()));
// Add project 'c' and confirm alphabetical order.
$c = new LocaleTranslatableProject('c', 'c', 'c', 'c', 'c');
$this->localeProjectRepository
->set($c);
$this->assertSame([
'b',
'c',
], array_keys($this->localeProjectRepository
->getAll()));
// Add project 'a' and confirm 'a' is first.
$a = new LocaleTranslatableProject('a', 'a', 'a', 'a', 'a');
$this->localeProjectRepository
->set($a);
$this->assertSame([
'a',
'b',
'c',
], array_keys($this->localeProjectRepository
->getAll()));
// Add project 'd' with a negative weight and confirm 'd' is first.
$d = new LocaleTranslatableProject('d', 'd', 'd', 'd', 'd', weight: -1);
$this->localeProjectRepository
->set($d);
$this->assertSame([
'd',
'a',
'b',
'c',
], array_keys($this->localeProjectRepository
->getAll()));
// Add project 'aa' with a positive weight and confirm 'aa' is last.
$aa = new LocaleTranslatableProject('aa', 'aa', 'aa', 'aa', 'aa', weight: 1);
$this->localeProjectRepository
->set($aa);
$this->assertSame([
'd',
'a',
'b',
'c',
'aa',
], array_keys($this->localeProjectRepository
->getAll()));
// Delete project 'a'.
$this->localeProjectRepository
->deleteMultiple([
'a',
]);
$this->assertSame([
'd',
'b',
'c',
'aa',
], array_keys($this->localeProjectRepository
->getAll()));
// Add project 'e' with a lower negative weight than 'd' and confirm 'e' is
// first.
$e = new LocaleTranslatableProject('e', 'e', 'e', 'e', 'e', weight: -5);
$this->localeProjectRepository
->set($e);
$this->assertSame([
'e',
'd',
'b',
'c',
'aa',
], array_keys($this->localeProjectRepository
->getAll()));
// Pretend there is a container rebuild by generating a new
// LocaleProjectRepository object with the same data.
$this->localeProjectRepository = new LocaleProjectRepository($this->cache, $this->keyValueMemoryFactory, $this->moduleHandler, $this->moduleExtensionList, $this->themeExtensionList, $this->config);
$z = new LocaleTranslatableProject('z', 'z', 'z', 'z', 'z');
$this->localeProjectRepository
->set($z);
$this->assertSame([
'e',
'd',
'b',
'c',
'z',
'aa',
], array_keys($this->localeProjectRepository
->getAll()));
// Now delete all projects.
$this->localeProjectRepository
->deleteAll();
// Add project 'z' before project 'a' and confirm 'a' is first.
$this->localeProjectRepository
->set($z);
$this->localeProjectRepository
->set($a);
$this->assertSame([
'a',
'z',
], array_keys($this->localeProjectRepository
->getAll()));
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|---|
| DrupalTestCaseTrait::$root | protected | property | The Drupal root directory. | |||
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | 1 | ||
| DrupalTestCaseTrait::getDrupalRoot | Deprecated | protected static | function | Returns the Drupal root directory. | 1 | |
| DrupalTestCaseTrait::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |||
| DrupalTestCaseTrait::setUpRoot | final protected | function | Ensure that the $root property is set initially. | |||
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. | ||
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | ||||
| LocaleProjectRepositoryTest::$cache | private | property | The key value memory factory. | |||
| LocaleProjectRepositoryTest::$config | private | property | The key value memory factory. | |||
| LocaleProjectRepositoryTest::$keyValueMemoryFactory | private | property | The key value memory factory. | |||
| LocaleProjectRepositoryTest::$localeProjectRepository | private | property | The local project storage. | |||
| LocaleProjectRepositoryTest::$moduleExtensionList | private | property | The key value memory factory. | |||
| LocaleProjectRepositoryTest::$moduleHandler | private | property | The key value memory factory. | |||
| LocaleProjectRepositoryTest::$themeExtensionList | private | property | The key value memory factory. | |||
| LocaleProjectRepositoryTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
| LocaleProjectRepositoryTest::testSorting | public | function | Tests that projects are sorted by weight and key. | |||
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.