function ViewUIObjectTest::testIsLockedLegacy

Tests the isLocked method.

@expectedDeprecation Using the "lock" public property of a View is deprecated in Drupal 8.7.0 and will not be allowed in Drupal 9.0.0. Use \Drupal\views_ui\ViewUI::setLock() instead. See https://www.drupal.org/node/3025869. @group legacy

File

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

Class

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

Namespace

Drupal\Tests\views_ui\Unit

Code

public function testIsLockedLegacy() {
    $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 = (object) [
        'owner' => 2,
        'data' => [],
        'updated' => (int) $_SERVER['REQUEST_TIME'],
    ];
    $view_ui->lock = $lock;
    $this->assertTrue($view_ui->isLocked());
    // Set a different lock object with the same object as the mocked account.
    $lock = (object) [
        'owner' => 1,
        'data' => [],
        'updated' => (int) $_SERVER['REQUEST_TIME'],
    ];
    $view_ui->lock = $lock;
    $this->assertFalse($view_ui->isLocked());
}

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