function ViewUIObjectTest::testIsLocked

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()
  3. 11.x 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 <a href="/api/drupal/core%21modules%21views_ui%21src%21ViewUI.php/class/ViewUI/8.9.x" title="Stores UI related temporary settings." class="local">\Drupal\views_ui\ViewUI</a> @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());
}

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