public function NodeBulkFormTest::testConstructor in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Unit/Plugin/views/field/NodeBulkFormTest.php \Drupal\Tests\node\Unit\Plugin\views\field\NodeBulkFormTest::testConstructor()
Tests the constructor assignment of actions.
File
- core/
modules/ node/ tests/ src/ Unit/ Plugin/ views/ field/ NodeBulkFormTest.php, line 29
Class
- NodeBulkFormTest
- @coversDefaultClass \Drupal\node\Plugin\views\field\NodeBulkForm @group node
Namespace
Drupal\Tests\node\Unit\Plugin\views\fieldCode
public function testConstructor() {
$actions = [];
for ($i = 1; $i <= 2; $i++) {
$action = $this
->createMock('\\Drupal\\system\\ActionConfigEntityInterface');
$action
->expects($this
->any())
->method('getType')
->will($this
->returnValue('node'));
$actions[$i] = $action;
}
$action = $this
->createMock('\\Drupal\\system\\ActionConfigEntityInterface');
$action
->expects($this
->any())
->method('getType')
->will($this
->returnValue('user'));
$actions[] = $action;
$entity_storage = $this
->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
$entity_storage
->expects($this
->any())
->method('loadMultiple')
->will($this
->returnValue($actions));
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this
->once())
->method('getStorage')
->with('action')
->will($this
->returnValue($entity_storage));
$entity_repository = $this
->createMock(EntityRepositoryInterface::class);
$language_manager = $this
->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$messenger = $this
->createMock('Drupal\\Core\\Messenger\\MessengerInterface');
$views_data = $this
->getMockBuilder('Drupal\\views\\ViewsData')
->disableOriginalConstructor()
->getMock();
$views_data
->expects($this
->any())
->method('get')
->with('node')
->will($this
->returnValue([
'table' => [
'entity type' => 'node',
],
]));
$container = new ContainerBuilder();
$container
->set('views.views_data', $views_data);
$container
->set('string_translation', $this
->getStringTranslationStub());
\Drupal::setContainer($container);
$storage = $this
->createMock('Drupal\\views\\ViewEntityInterface');
$storage
->expects($this
->any())
->method('get')
->with('base_table')
->will($this
->returnValue('node'));
$executable = $this
->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->getMock();
$executable->storage = $storage;
$display = $this
->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')
->disableOriginalConstructor()
->getMock();
$definition['title'] = '';
$options = [];
$node_bulk_form = new NodeBulkForm([], 'node_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository);
$node_bulk_form
->init($executable, $display, $options);
$reflected_actions = (new \ReflectionObject($node_bulk_form))
->getProperty('actions');
$reflected_actions
->setAccessible(TRUE);
$this
->assertEquals(array_slice($actions, 0, -1, TRUE), $reflected_actions
->getValue($node_bulk_form));
}