function ViewUIObjectTest::testIsLocked
Tests the isLocked method.
File
- 
              core/
modules/ views_ui/ tests/ src/ Unit/ ViewUIObjectTest.php, line 78  
Class
- ViewUIObjectTest
 - @coversDefaultClass \Drupal\views_ui\ViewUI[[api-linebreak]] @group views_ui
 
Namespace
Drupal\Tests\views_ui\UnitCode
public function testIsLocked() : void {
  $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')
    ->willReturn(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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.