You are here

public function ViewUIObjectTest::testIsLocked in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest::testIsLocked()
  2. 10 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest::testIsLocked()

Tests the isLocked method.

File

core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php, line 76

Class

ViewUIObjectTest
@coversDefaultClass \Drupal\views_ui\ViewUI @group views_ui

Namespace

Drupal\Tests\views_ui\Unit

Code

public function testIsLocked() {
  $storage = $this
    ->getMockBuilder('Drupal\\views\\Entity\\View')
    ->setConstructorArgs([
    [],
    'view',
  ])
    ->getMock();
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->setConstructorArgs([
    $storage,
  ])
    ->getMock();
  $storage
    ->set('executable', $executable);
  $account = $this
    ->createMock('Drupal\\Core\\Session\\AccountInterface');
  $account
    ->expects($this
    ->exactly(2))
    ->method('id')
    ->will($this
    ->returnValue(1));
  $container = new ContainerBuilder();
  $container
    ->set('current_user', $account);
  \Drupal::setContainer($container);
  $view_ui = new ViewUI($storage);

  // A view_ui without a lock object is not locked.
  $this
    ->assertFalse($view_ui
    ->isLocked());

  // Set the lock object with a different owner than the mocked account above.
  $lock = new Lock(2, (int) $_SERVER['REQUEST_TIME']);
  $view_ui
    ->setLock($lock);
  $this
    ->assertTrue($view_ui
    ->isLocked());

  // Set a different lock object with the same object as the mocked account.
  $lock = new Lock(1, (int) $_SERVER['REQUEST_TIME']);
  $view_ui
    ->setLock($lock);
  $this
    ->assertFalse($view_ui
    ->isLocked());
  $view_ui
    ->unsetLock(NULL);
  $this
    ->assertFalse($view_ui
    ->isLocked());
}