91d52829c5a1321e7c40181aaecc99bd577b141f
[yaffs-website] / web / core / modules / views / tests / src / Unit / Plugin / area / ViewTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Unit\Plugin\area;
4
5 use Drupal\Tests\UnitTestCase;
6 use Drupal\views\Plugin\views\area\View as ViewAreaPlugin;
7
8 /**
9  * @coversDefaultClass \Drupal\views\Plugin\views\area\View
10  * @group views
11  */
12 class ViewTest extends UnitTestCase {
13
14   /**
15    * The mocked entity storage.
16    *
17    * @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject
18    */
19   protected $entityStorage;
20
21   /**
22    * The view handler.
23    *
24    * @var \Drupal\views\Plugin\views\area\View
25    */
26   protected $viewHandler;
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33     $this->entityStorage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
34     $this->viewHandler = new ViewAreaPlugin([], 'view', [], $this->entityStorage);
35     $this->viewHandler->view = $this->getMockBuilder('Drupal\views\ViewExecutable')
36       ->disableOriginalConstructor()
37       ->getMock();
38   }
39
40   /**
41    * @covers ::calculateDependencies
42    */
43   public function testCalculateDependencies() {
44     /* @var $view_this \Drupal\views\Entity\View */
45     /* @var $view_other \Drupal\views\Entity\View */
46     $view_this = $this->getMock('Drupal\views\ViewEntityInterface');
47     $view_this->expects($this->any())->method('getConfigDependencyKey')->willReturn('config');
48     $view_this->expects($this->any())->method('getConfigDependencyName')->willReturn('view.this');
49     $view_this->expects($this->any())->method('id')->willReturn('this');
50     $view_other = $this->getMock('Drupal\views\ViewEntityInterface');
51     $view_other->expects($this->any())->method('getConfigDependencyKey')->willReturn('config');
52     $view_other->expects($this->any())->method('getConfigDependencyName')->willReturn('view.other');
53     $this->entityStorage->expects($this->any())
54       ->method('load')
55       ->willReturnMap([
56         ['this', $view_this],
57         ['other', $view_other]
58     ]);
59     $this->viewHandler->view->storage = $view_this;
60
61
62     $this->viewHandler->options['view_to_insert'] = 'other:default';
63     $this->assertArrayEquals(['config' => ['view.other']], $this->viewHandler->calculateDependencies());
64
65     $this->viewHandler->options['view_to_insert'] = 'this:default';
66     $this->assertArrayEquals([], $this->viewHandler->calculateDependencies());
67   }
68
69 }