a6b2f543f014976fe2a82a3565e85507fb6e7f6c
[yaffs-website] / web / core / modules / user / tests / src / Unit / Plugin / views / field / UserBulkFormTest.php
1 <?php
2
3 namespace Drupal\Tests\user\Unit\Plugin\views\field;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\user\Plugin\views\field\UserBulkForm;
8
9 /**
10  * @coversDefaultClass \Drupal\user\Plugin\views\field\UserBulkForm
11  * @group user
12  */
13 class UserBulkFormTest extends UnitTestCase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function tearDown() {
19     parent::tearDown();
20     $container = new ContainerBuilder();
21     \Drupal::setContainer($container);
22   }
23
24   /**
25    * Tests the constructor assignment of actions.
26    */
27   public function testConstructor() {
28     $actions = [];
29
30     for ($i = 1; $i <= 2; $i++) {
31       $action = $this->getMock('\Drupal\system\ActionConfigEntityInterface');
32       $action->expects($this->any())
33         ->method('getType')
34         ->will($this->returnValue('user'));
35       $actions[$i] = $action;
36     }
37
38     $action = $this->getMock('\Drupal\system\ActionConfigEntityInterface');
39     $action->expects($this->any())
40       ->method('getType')
41       ->will($this->returnValue('node'));
42     $actions[] = $action;
43
44     $entity_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
45     $entity_storage->expects($this->any())
46       ->method('loadMultiple')
47       ->will($this->returnValue($actions));
48
49     $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
50     $entity_manager->expects($this->once())
51       ->method('getStorage')
52       ->with('action')
53       ->will($this->returnValue($entity_storage));
54
55     $language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
56
57     $messenger = $this->getMock('Drupal\Core\Messenger\MessengerInterface');
58
59     $views_data = $this->getMockBuilder('Drupal\views\ViewsData')
60       ->disableOriginalConstructor()
61       ->getMock();
62     $views_data->expects($this->any())
63       ->method('get')
64       ->with('users')
65       ->will($this->returnValue(['table' => ['entity type' => 'user']]));
66     $container = new ContainerBuilder();
67     $container->set('views.views_data', $views_data);
68     $container->set('string_translation', $this->getStringTranslationStub());
69     \Drupal::setContainer($container);
70
71     $storage = $this->getMock('Drupal\views\ViewEntityInterface');
72     $storage->expects($this->any())
73       ->method('get')
74       ->with('base_table')
75       ->will($this->returnValue('users'));
76
77     $executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
78       ->disableOriginalConstructor()
79       ->getMock();
80     $executable->storage = $storage;
81
82     $display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
83       ->disableOriginalConstructor()
84       ->getMock();
85
86     $definition['title'] = '';
87     $options = [];
88
89     $user_bulk_form = new UserBulkForm([], 'user_bulk_form', $definition, $entity_manager, $language_manager, $messenger);
90     $user_bulk_form->init($executable, $display, $options);
91
92     $this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $user_bulk_form);
93   }
94
95 }