ViewTest.php in Drupal 9
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;
class ViewTest extends UnitTestCase {
protected $entityStorage;
protected $viewHandler;
protected function setUp() : void {
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();
}
public function testCalculateDependencies() {
$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
->assertEquals([
'config' => [
'view.other',
],
], $this->viewHandler
->calculateDependencies());
$this->viewHandler->options['view_to_insert'] = 'this:default';
$this
->assertSame([], $this->viewHandler
->calculateDependencies());
}
}