class LingotekFilterManagerUnitTest in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.0.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.1.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.2.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.3.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.4.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.5.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.6.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.7.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
- 3.8.x tests/src/Unit/LingotekFilterManagerUnitTest.php \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
@coversDefaultClass \Drupal\lingotek\LingotekFilterManager @group lingotek @preserveGlobalState disabled
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\lingotek\Unit\LingotekFilterManagerUnitTest
Expanded class hierarchy of LingotekFilterManagerUnitTest
File
- tests/
src/ Unit/ LingotekFilterManagerUnitTest.php, line 16
Namespace
Drupal\Tests\lingotek\UnitView source
class LingotekFilterManagerUnitTest extends UnitTestCase {
/**
* The Lingotek Filter manager.
*
* @var \Drupal\lingotek\LingotekFilterManagerInterface
*/
protected $filterManager;
/**
* The Lingotek account settings.
*
* @var \Drupal\Core\Config\Config
*/
protected $accountConfig;
/**
* The config object.
*
* @var \Drupal\Core\Config\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $config;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->accountConfig = $this
->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$this->config = $this
->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$configFactory = $this
->createMock(ConfigFactoryInterface::class);
$configFactory
->expects($this
->any())
->method('get')
->will($this
->returnCallback(function ($config_name) {
return $config_name === 'lingotek.account' ? $this->accountConfig : $this->config;
}));
$this->filterManager = new LingotekFilterManager($configFactory);
}
/**
* @covers ::getLocallyAvailableFilters
*/
public function testGetLocallyAvailableFilters() {
// Test with no local filters.
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('resources.filter')
->will($this
->returnValue([]));
$filters = $this->filterManager
->getLocallyAvailableFilters();
$this
->assertNotEmpty($filters);
$this
->assertArrayEquals($filters, [
'project_default' => 'Project Default',
'drupal_default' => 'Drupal Default',
]);
// Test with some filters.
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('resources.filter')
->will($this
->returnValue([
'aaa' => 'Test filter',
]));
$filters = $this->filterManager
->getLocallyAvailableFilters();
$this
->assertNotEmpty($filters);
$this
->assertEquals([
'project_default' => 'Project Default',
'drupal_default' => 'Drupal Default',
'aaa' => 'Test filter',
], $filters);
}
public function getDefaultFilterProvider() {
return [
[
'bbb',
[
'aaa' => 'Test label',
'bbb' => 'Another label',
],
'bbb',
],
[
'aaa',
[
'aaa' => 'Test label',
'bbb' => 'Another label',
],
'aaa',
],
[
'xxx',
[
'aaa' => 'Test label',
'bbb' => 'Another label',
],
NULL,
],
[
'xxx',
[],
NULL,
],
];
}
/**
* @covers ::getDefaultSubfilter
* @dataProvider getDefaultFilterProvider
*/
public function testGetDefaultFilter($id, $filters, $expectedFilter) {
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('default.filter')
->will($this
->returnValue($id));
$this->accountConfig
->expects($this
->at(1))
->method('get')
->with('resources.filter')
->will($this
->returnValue($filters));
$filter = $this->filterManager
->getDefaultFilter();
$this
->assertEquals($expectedFilter, $filter);
}
/**
* @covers ::getDefaultSubfilter
* @dataProvider getDefaultFilterProvider
*/
public function testGetDefaultSubfilter($id, $filters, $expectedFilter) {
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('default.subfilter')
->will($this
->returnValue($id));
$this->accountConfig
->expects($this
->at(1))
->method('get')
->with('resources.filter')
->will($this
->returnValue($filters));
$filter = $this->filterManager
->getDefaultSubfilter();
$this
->assertEquals($expectedFilter, $filter);
}
public function getDefaultFilterLabelProvider() {
return [
[
'bbb',
[
'aaa' => 'Test label',
'bbb' => 'Another label',
],
'Another label',
],
[
'aaa',
[
'aaa' => 'Test label',
'bbb' => 'Another label',
],
'Test label',
],
[
'xxx',
[
'aaa' => 'Test label',
'bbb' => 'Another label',
],
'',
],
[
'xxx',
[],
'',
],
];
}
/**
* @covers ::getDefaultFilterLabel
* @dataProvider getDefaultFilterLabelProvider
*/
public function testGetDefaultFilterLabel($id, $filters, $expectedLabel) {
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('default.filter')
->will($this
->returnValue($id));
$this->accountConfig
->expects($this
->at(1))
->method('get')
->with('resources.filter')
->will($this
->returnValue($filters));
$this->accountConfig
->expects($this
->at(2))
->method('get')
->with('resources.filter')
->will($this
->returnValue($filters));
$label = $this->filterManager
->getDefaultFilterLabel();
$this
->assertEquals($expectedLabel, $label);
}
/**
* @covers ::getDefaultSubfilterLabel
* @dataProvider getDefaultFilterLabelProvider
*/
public function testGetDefaultSubfilterLabel($id, $filters, $expectedLabel) {
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('default.subfilter')
->will($this
->returnValue($id));
$this->accountConfig
->expects($this
->at(1))
->method('get')
->with('resources.filter')
->will($this
->returnValue($filters));
$this->accountConfig
->expects($this
->at(2))
->method('get')
->with('resources.filter')
->will($this
->returnValue($filters));
$label = $this->filterManager
->getDefaultSubfilterLabel();
$this
->assertEquals($expectedLabel, $label);
}
/**
* @covers ::getSubfilterId
*/
public function testGetFilterId() {
// Filter id has the original value.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'filter' => 'my_filter',
], 'lingotek_profile');
$filter = $this->filterManager
->getFilterId($profile);
$this
->assertEquals('my_filter', $filter);
// Filter is replaced with project default.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'filter' => 'project_default',
], 'lingotek_profile');
$filter = $this->filterManager
->getFilterId($profile);
$this
->assertEquals(NULL, $filter);
// Filter is replaced with drupal default.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'filter' => 'drupal_default',
], 'lingotek_profile');
$filter = $this->filterManager
->getFilterId($profile);
$this
->assertEquals('4f91482b-5aa1-4a4a-a43f-712af7b39625', $filter);
// Filter is replaced with the default.
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('default.filter')
->will($this
->returnValue('another_different_filter'));
$this->accountConfig
->expects($this
->at(1))
->method('get')
->with('resources.filter')
->will($this
->returnValue([
'another_different_filter' => 'Another different filter',
]));
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'filter' => 'default',
], 'lingotek_profile');
$filter = $this->filterManager
->getFilterId($profile);
$this
->assertEquals('another_different_filter', $filter);
}
/**
* @covers ::getSubfilterId
*/
public function testGetSubfilterId() {
// Filter id has the original value.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'subfilter' => 'my_filter',
], 'lingotek_profile');
$filter = $this->filterManager
->getSubfilterId($profile);
$this
->assertEquals('my_filter', $filter);
// Filter is replaced with project default.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'subfilter' => 'project_default',
], 'lingotek_profile');
$filter = $this->filterManager
->getSubfilterId($profile);
$this
->assertEquals(NULL, $filter);
// Filter is replaced with drupal default.
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'subfilter' => 'drupal_default',
], 'lingotek_profile');
$filter = $this->filterManager
->getSubfilterId($profile);
$this
->assertEquals('0e79f34d-f27b-4a0c-880e-cd9181a5d265', $filter);
// Filter is replaced with the default.
$this->accountConfig
->expects($this
->at(0))
->method('get')
->with('default.subfilter')
->will($this
->returnValue('another_different_filter'));
$this->accountConfig
->expects($this
->at(1))
->method('get')
->with('resources.filter')
->will($this
->returnValue([
'another_different_filter' => 'Another different filter',
]));
$profile = new LingotekProfile([
'id' => 'profile1',
'project' => 'my_test_project',
'vault' => 'my_test_vault',
'subfilter' => 'default',
], 'lingotek_profile');
$filter = $this->filterManager
->getSubfilterId($profile);
$this
->assertEquals('another_different_filter', $filter);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LingotekFilterManagerUnitTest:: |
protected | property | The Lingotek account settings. | |
LingotekFilterManagerUnitTest:: |
protected | property | The config object. | |
LingotekFilterManagerUnitTest:: |
protected | property | The Lingotek Filter manager. | |
LingotekFilterManagerUnitTest:: |
public | function | ||
LingotekFilterManagerUnitTest:: |
public | function | ||
LingotekFilterManagerUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getDefaultSubfilter @dataProvider getDefaultFilterProvider | |
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getDefaultFilterLabel @dataProvider getDefaultFilterLabelProvider | |
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getDefaultSubfilter @dataProvider getDefaultFilterProvider | |
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getDefaultSubfilterLabel @dataProvider getDefaultFilterLabelProvider | |
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getSubfilterId | |
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getLocallyAvailableFilters | |
LingotekFilterManagerUnitTest:: |
public | function | @covers ::getSubfilterId | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |