Issue #2061925 by alweb, Albert Volkman, dawehner: Remove calls to deprecated global in views_ui module.

8.0.x
Nathaniel Catchpole 2013-12-10 14:14:49 +00:00
parent 384aae19c0
commit ed06280e8b
2 changed files with 44 additions and 1 deletions

View File

@ -807,7 +807,7 @@ class ViewUI implements ViewStorageInterface {
* 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());
}
/**

View File

@ -12,6 +12,7 @@ use Drupal\Tests\UnitTestCase;
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 @@ class ViewUIObjectTest extends UnitTestCase {
$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());
}
}