class UidToUserNameCallbackProcessorTest in Facets 8
Unit test for processor.
@group facets
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets\Unit\Plugin\processor\UidToUserNameCallbackProcessorTest
Expanded class hierarchy of UidToUserNameCallbackProcessorTest
File
- tests/
src/ Unit/ Plugin/ processor/ UidToUserNameCallbackProcessorTest.php, line 20
Namespace
Drupal\Tests\facets\Unit\Plugin\processorView source
class UidToUserNameCallbackProcessorTest extends UnitTestCase {
/**
* The processor to be tested.
*
* @var \Drupal\facets\processor\SortProcessorInterface
*/
protected $processor;
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
$this->processor = new UidToUserNameCallbackProcessor([], 'uid_to_username_callback', []);
}
/**
* Tests that results were correctly changed.
*/
public function testResultsChanged() {
$user_storage = $this
->createMock(EntityStorageInterface::class);
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_repository = $this
->createMock(EntityTypeRepositoryInterface::class);
$entity_repository
->expects($this
->any())
->method('getEntityTypeFromClass')
->willReturn('user');
$entity_type_manager
->expects($this
->any())
->method('getStorage')
->willReturn($user_storage);
$user1 = $this
->createMock(AccountInterface::class);
$user1
->method('getDisplayName')
->willReturn('Admin');
$user_storage
->method('load')
->willReturn($user1);
$container = new ContainerBuilder();
$container
->set('entity_type.repository', $entity_repository);
$container
->set('entity_type.manager', $entity_type_manager);
\Drupal::setContainer($container);
$facet = new Facet([], 'facets_facet');
$original_results = [
new Result($facet, 1, 1, 5),
];
$facet
->setResults($original_results);
$expected_results = [
[
'uid' => 1,
'name' => 'Admin',
],
];
foreach ($expected_results as $key => $expected) {
$this
->assertEquals($expected['uid'], $original_results[$key]
->getRawValue());
$this
->assertEquals($expected['uid'], $original_results[$key]
->getDisplayValue());
}
$filtered_results = $this->processor
->build($facet, $original_results);
foreach ($expected_results as $key => $expected) {
$this
->assertEquals($expected['uid'], $filtered_results[$key]
->getRawValue());
$this
->assertEquals($expected['name'], $filtered_results[$key]
->getDisplayValue());
}
}
/**
* Tests that deleted entity results were correctly handled.
*/
public function testDeletedEntityResults() {
$user_storage = $this
->createMock(EntityStorageInterface::class);
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_repository = $this
->createMock(EntityTypeRepositoryInterface::class);
$entity_repository
->expects($this
->any())
->method('getEntityTypeFromClass')
->willReturn('user');
$entity_type_manager
->expects($this
->any())
->method('getStorage')
->willReturn($user_storage);
$user_storage
->method('load')
->willReturn(NULL);
$container = new ContainerBuilder();
$container
->set('entity_type.repository', $entity_repository);
$container
->set('entity_type.manager', $entity_type_manager);
\Drupal::setContainer($container);
$facet = new Facet([], 'facets_facet');
$original_results = [
new Result($facet, 1, 1, 5),
];
$facet
->setResults($original_results);
$filtered_results = $this->processor
->build($facet, $original_results);
$this
->assertEmpty($filtered_results);
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor
->defaultConfiguration();
$this
->assertEquals([], $config);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UidToUserNameCallbackProcessorTest:: |
protected | property | The processor to be tested. | |
UidToUserNameCallbackProcessorTest:: |
protected | function |
Creates a new processor object for use in the tests. Overrides UnitTestCase:: |
|
UidToUserNameCallbackProcessorTest:: |
public | function | Tests configuration. | |
UidToUserNameCallbackProcessorTest:: |
public | function | Tests that deleted entity results were correctly handled. | |
UidToUserNameCallbackProcessorTest:: |
public | function | Tests that results were correctly changed. | |
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 | Mocks a block with a block plugin. | 1 |
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. |