function ViewsTest::testGetView

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Unit/ViewsTest.php \Drupal\Tests\views\Unit\ViewsTest::testGetView()
  2. 10 core/modules/views/tests/src/Unit/ViewsTest.php \Drupal\Tests\views\Unit\ViewsTest::testGetView()
  3. 11.x core/modules/views/tests/src/Unit/ViewsTest.php \Drupal\Tests\views\Unit\ViewsTest::testGetView()

Tests the getView() method.

@covers ::getView

File

core/modules/views/tests/src/Unit/ViewsTest.php, line 52

Class

ViewsTest
@coversDefaultClass \Drupal\views\Views @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testGetView() {
    $view = new View([
        'id' => 'test_view',
    ], 'view');
    $view_storage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')
        ->disableOriginalConstructor()
        ->getMock();
    $view_storage->expects($this->once())
        ->method('load')
        ->with('test_view')
        ->willReturn($view);
    $entity_type_manager = $this->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
    $entity_type_manager->expects($this->once())
        ->method('getStorage')
        ->with('view')
        ->willReturn($view_storage);
    $this->container
        ->set('entity_type.manager', $entity_type_manager);
    $executable = Views::getView('test_view');
    $this->assertInstanceOf('Drupal\\views\\ViewExecutable', $executable);
    $this->assertEquals($view->id(), $executable->storage
        ->id());
    $this->assertEquals(spl_object_hash($view), spl_object_hash($executable->storage));
}

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