You are here

public function ViewUIObjectTest::testIsLocked in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 77
Contains \Drupal\Tests\views_ui\Unit\ViewUIObjectTest.

Class

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

Namespace

Drupal\Tests\views_ui\Unit

Code

public function testIsLocked() {
  $storage = $this
    ->getMock('Drupal\\views\\Entity\\View', array(), array(
    array(),
    'view',
  ));
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->setConstructorArgs(array(
    $storage,
  ))
    ->getMock();
  $storage
    ->set('executable', $executable);
  $account = $this
    ->getMock('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) array(
    'owner' => 2,
    'data' => array(),
    '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) array(
    'owner' => 1,
    'data' => array(),
    'updated' => (int) $_SERVER['REQUEST_TIME'],
  );
  $view_ui->lock = $lock;
  $this
    ->assertFalse($view_ui
    ->isLocked());
}