You are here

public function ViewsTest::testGetView in Drupal 8

Same name and namespace in other branches
  1. 9 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')
    ->will($this
    ->returnValue($view));
  $entity_type_manager = $this
    ->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $entity_type_manager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with('view')
    ->will($this
    ->returnValue($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));
}