4e86bb7ef032bb2b74b02dec8b929e0b51cceab1
[yaffs-website] / web / core / modules / comment / tests / src / Unit / Plugin / views / field / CommentBulkFormTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Unit\Plugin\views\field;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\comment\Plugin\views\field\CommentBulkForm;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\comment\Plugin\views\field\CommentBulkForm
11  * @group comment
12  */
13 class CommentBulkFormTest 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('comment'));
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('user'));
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     $views_data = $this->getMockBuilder('Drupal\views\ViewsData')
58       ->disableOriginalConstructor()
59       ->getMock();
60     $views_data->expects($this->any())
61       ->method('get')
62       ->with('comment')
63       ->will($this->returnValue(['table' => ['entity type' => 'comment']]));
64     $container = new ContainerBuilder();
65     $container->set('views.views_data', $views_data);
66     $container->set('string_translation', $this->getStringTranslationStub());
67     \Drupal::setContainer($container);
68
69     $storage = $this->getMock('Drupal\views\ViewEntityInterface');
70     $storage->expects($this->any())
71       ->method('get')
72       ->with('base_table')
73       ->will($this->returnValue('comment'));
74
75     $executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
76       ->disableOriginalConstructor()
77       ->getMock();
78     $executable->storage = $storage;
79
80     $display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
81       ->disableOriginalConstructor()
82       ->getMock();
83
84     $definition['title'] = '';
85     $options = [];
86
87     $comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_manager, $language_manager);
88     $comment_bulk_form->init($executable, $display, $options);
89
90     $this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $comment_bulk_form);
91   }
92
93 }