ViewTest.php

Same filename in this branch
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ViewTest.php
Same filename in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ViewTest.php
  2. 9 core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php
  3. 10 core/modules/jsonapi/tests/src/Functional/ViewTest.php
  4. 10 core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php
  5. 11.x core/modules/jsonapi/tests/src/Functional/ViewTest.php
  6. 11.x core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php

Namespace

Drupal\Tests\views\Unit\Plugin\area

File

core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php

View source
<?php

namespace Drupal\Tests\views\Unit\Plugin\area;

use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\area\View as ViewAreaPlugin;

/**
 * @coversDefaultClass \Drupal\views\Plugin\views\area\View
 * @group views
 */
class ViewTest extends UnitTestCase {
    
    /**
     * The mocked entity storage.
     *
     * @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $entityStorage;
    
    /**
     * The view handler.
     *
     * @var \Drupal\views\Plugin\views\area\View
     */
    protected $viewHandler;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() {
        parent::setUp();
        $this->entityStorage = $this->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
        $this->viewHandler = new ViewAreaPlugin([], 'view', [], $this->entityStorage);
        $this->viewHandler->view = $this->getMockBuilder('Drupal\\views\\ViewExecutable')
            ->disableOriginalConstructor()
            ->getMock();
    }
    
    /**
     * @covers ::calculateDependencies
     */
    public function testCalculateDependencies() {
        
        /* @var $view_this \Drupal\views\Entity\View */
        
        /* @var $view_other \Drupal\views\Entity\View */
        $view_this = $this->createMock('Drupal\\views\\ViewEntityInterface');
        $view_this->expects($this->any())
            ->method('getConfigDependencyKey')
            ->willReturn('config');
        $view_this->expects($this->any())
            ->method('getConfigDependencyName')
            ->willReturn('view.this');
        $view_this->expects($this->any())
            ->method('id')
            ->willReturn('this');
        $view_other = $this->createMock('Drupal\\views\\ViewEntityInterface');
        $view_other->expects($this->any())
            ->method('getConfigDependencyKey')
            ->willReturn('config');
        $view_other->expects($this->any())
            ->method('getConfigDependencyName')
            ->willReturn('view.other');
        $this->entityStorage
            ->expects($this->any())
            ->method('load')
            ->willReturnMap([
            [
                'this',
                $view_this,
            ],
            [
                'other',
                $view_other,
            ],
        ]);
        $this->viewHandler->view->storage = $view_this;
        $this->viewHandler->options['view_to_insert'] = 'other:default';
        $this->assertArrayEquals([
            'config' => [
                'view.other',
            ],
        ], $this->viewHandler
            ->calculateDependencies());
        $this->viewHandler->options['view_to_insert'] = 'this:default';
        $this->assertArrayEquals([], $this->viewHandler
            ->calculateDependencies());
    }

}

Classes

Title Deprecated Summary
ViewTest @coversDefaultClass \Drupal\views\Plugin\views\area\View @group views

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.