protected function RoleFilterTest::setUp in Search API 8
Creates a new processor object for use in the tests.
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Processor/ RoleFilterTest.php, line 42
Class
- RoleFilterTest
- Tests the "Role filter" processor.
Namespace
Drupal\Tests\search_api\Unit\ProcessorCode
protected function setUp() {
parent::setUp();
$this
->setUpMockContainer();
$this->processor = new RoleFilter([], 'role_filter', []);
/** @var \Drupal\search_api\IndexInterface $index */
$index = $this
->createMock(IndexInterface::class);
$node_datasource = $this
->createMock(DatasourceInterface::class);
$node_datasource
->expects($this
->any())
->method('getEntityTypeId')
->will($this
->returnValue('node'));
/** @var \Drupal\search_api\Datasource\DatasourceInterface $node_datasource */
$user_datasource = $this
->createMock(DatasourceInterface::class);
$user_datasource
->expects($this
->any())
->method('getEntityTypeId')
->will($this
->returnValue('user'));
/** @var \Drupal\search_api\Datasource\DatasourceInterface $user_datasource */
$fields_helper = \Drupal::getContainer()
->get('search_api.fields_helper');
$item = $fields_helper
->createItem($index, Utility::createCombinedId('entity:node', '1:en'), $node_datasource);
$node = $this
->getMockBuilder(TestNodeInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var \Drupal\node\NodeInterface $node */
$item
->setOriginalObject(EntityAdapter::createFromEntity($node));
$this->items[$item
->getId()] = $item;
$item = $fields_helper
->createItem($index, Utility::createCombinedId('entity:user', '1:en'), $user_datasource);
$account1 = $this
->getMockBuilder(TestUserInterface::class)
->disableOriginalConstructor()
->getMock();
$account1
->expects($this
->any())
->method('getRoles')
->will($this
->returnValue([
'authenticated' => 'authenticated',
'editor' => 'editor',
]));
/** @var \Drupal\user\UserInterface $account1 */
$item
->setOriginalObject(EntityAdapter::createFromEntity($account1));
$this->items[$item
->getId()] = $item;
$item = $fields_helper
->createItem($index, Utility::createCombinedId('entity:user', '2:en'), $user_datasource);
$account2 = $this
->getMockBuilder(TestUserInterface::class)
->disableOriginalConstructor()
->getMock();
$account2
->expects($this
->any())
->method('getRoles')
->will($this
->returnValue([
'authenticated' => 'authenticated',
]));
/** @var \Drupal\user\UserInterface $account2 */
$item
->setOriginalObject(EntityAdapter::createFromEntity($account2));
$this->items[$item
->getId()] = $item;
}