Commit ed06280e authored by catch's avatar catch

Issue #2061925 by alweb, Albert Volkman, dawehner: Remove calls to deprecated...

Issue #2061925 by alweb, Albert Volkman, dawehner: Remove calls to deprecated global  in views_ui module.
parent 384aae19
......@@ -807,7 +807,7 @@ public function cacheSet() {
* TRUE if the view is locked, FALSE otherwise.
*/
public function isLocked() {
return is_object($this->lock) && ($this->lock->owner != $GLOBALS['user']->id());
return is_object($this->lock) && ($this->lock->owner != \Drupal::currentUser()->id());
}
/**
......
......@@ -12,6 +12,7 @@
use Drupal\views\ViewExecutable;
use Drupal\views_ui\ViewUI;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Tests the ViewUI class.
......@@ -75,4 +76,46 @@ public function testEntityDecoration() {
$view_ui->isNew();
}
/**
* Tests the isLocked method.
*/
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();
$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, $executable);
// 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' => 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' => REQUEST_TIME,
);
$view_ui->lock = $lock;
$this->assertFalse($view_ui->isLocked());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment