public function UidToUserNameCallbackProcessorTest::testResultsChanged in Facets 8
Tests that results were correctly changed.
File
- tests/
src/ Unit/ Plugin/ processor/ UidToUserNameCallbackProcessorTest.php, line 41
Class
- UidToUserNameCallbackProcessorTest
- Unit test for processor.
Namespace
Drupal\Tests\facets\Unit\Plugin\processorCode
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());
}
}