diff --git a/core/modules/system/src/Tests/Lock/LockFunctionalTest.php b/core/modules/system/src/Tests/Lock/LockFunctionalTest.php index 846b44d..cece86d 100644 --- a/core/modules/system/src/Tests/Lock/LockFunctionalTest.php +++ b/core/modules/system/src/Tests/Lock/LockFunctionalTest.php @@ -28,8 +28,8 @@ class LockFunctionalTest extends WebTestBase { */ public function testLockAcquire() { $lock = $this->container->get('lock'); - $lock_acquired = 'TRUE: Lock successfully acquired in system_test_lock_acquire()'; - $lock_not_acquired = 'FALSE: Lock not acquired in system_test_lock_acquire()'; + $lock_acquired = 'TRUE: Lock successfully acquired in \Drupal\system_test\Controller\SystemTestController::lockAcquire()'; + $lock_not_acquired = 'FALSE: Lock not acquired in \Drupal\system_test\Controller\SystemTestController::lockAcquire()'; $this->assertTrue($lock->acquire('system_test_lock_acquire'), 'Lock acquired by this request.', 'Lock'); $this->assertTrue($lock->acquire('system_test_lock_acquire'), 'Lock extended by this request.', 'Lock'); $lock->release('system_test_lock_acquire'); @@ -54,7 +54,7 @@ public function testLockAcquire() { $this->assertFalse($lock->acquire('system_test_lock_acquire'), 'Lock cannot be extended by this request.', 'Lock'); // Check the shut-down function. - $lock_acquired_exit = 'TRUE: Lock successfully acquired in system_test_lock_exit()'; + $lock_acquired_exit = 'TRUE: Lock successfully acquired in \Drupal\system_test\Controller\SystemTestController::lockExit()'; $this->drupalGet('system-test/lock-exit'); $this->assertText($lock_acquired_exit, 'Lock acquired by the other request before exit.', 'Lock'); $this->assertTrue($lock->acquire('system_test_lock_exit'), 'Lock acquired by this request after the other request exits.', 'Lock'); diff --git a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php index 492f425..5b4bf73 100644 --- a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php +++ b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php @@ -8,6 +8,8 @@ namespace Drupal\system_test\Controller; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Url; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Lock\LockBackendInterface; @@ -19,6 +21,13 @@ class SystemTestController extends ControllerBase { /** + * The lock service. + * + * @var \Drupal\Core\Lock\LockBackendInterface + */ + protected $lock; + + /** * The persistent lock service. * * @var \Drupal\Core\Lock\LockBackendInterface @@ -28,10 +37,13 @@ class SystemTestController extends ControllerBase { /** * Constructs the SystemTestController. * + * @param \Drupal\Core\Lock\LockBackendInterface $lock + * The lock service. * @param \Drupal\Core\Lock\LockBackendInterface $persistent_lock * The persistent lock service. */ - public function __construct(LockBackendInterface $persistent_lock) { + public function __construct(LockBackendInterface $lock, LockBackendInterface $persistent_lock) { + $this->lock = $lock; $this->persistentLock = $persistent_lock; } @@ -39,7 +51,7 @@ public function __construct(LockBackendInterface $persistent_lock) { * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('lock.persistent')); + return new static($container->get('lock'), $container->get('lock.persistent')); } /** @@ -76,17 +88,30 @@ public function drupalSetMessageTest() { } /** - * @todo Remove system_test_lock_acquire(). + * Try to acquire a named lock and report the outcome. */ public function lockAcquire() { - return system_test_lock_acquire(); + if ($this->lock->acquire('system_test_lock_acquire')) { + $this->lock->release('system_test_lock_acquire'); + return ['#markup' => 'TRUE: Lock successfully acquired in \Drupal\system_test\Controller\SystemTestController::lockAcquire()']; + } + else { + return ['#markup' => 'FALSE: Lock not acquired in \Drupal\system_test\Controller\SystemTestController::lockAcquire()']; + } } /** - * @todo Remove system_test_lock_exit(). + * Try to acquire a specific lock, and then exit. */ public function lockExit() { - return system_test_lock_exit(); + if ($this->lock->acquire('system_test_lock_exit', 900)) { + echo 'TRUE: Lock successfully acquired in \Drupal\system_test\Controller\SystemTestController::lockExit()'; + // The shut-down function should release the lock. + exit(); + } + else { + return ['#markup' => 'FALSE: Lock not acquired in system_test_lock_exit()']; + } } /** @@ -132,10 +157,14 @@ public static function preRenderCacheTags($elements) { } /** - * @todo Remove system_test_authorize_init_page(). + * Initialize authorize.php during testing. + * + * @see system_authorized_init(). */ public function authorizeInit($page_title) { - return system_test_authorize_init_page($page_title); + $authorize_url = Url::fromUri('base:core/authorize.php', array('absolute' => TRUE))->toString(); + system_authorized_init('system_test_authorize_run', drupal_get_path('module', 'system_test') . '/system_test.module', array(), $page_title); + return new RedirectResponse($authorize_url); } /** @@ -151,10 +180,10 @@ public function setHeader(Request $request) { } /** - * @todo Remove system_test_page_shutdown_functions(). + * A simple page callback which adds a register shutdown function. */ public function shutdownFunctions($arg1, $arg2) { - system_test_page_shutdown_functions($arg1, $arg2); + drupal_register_shutdown_function('_system_test_first_shutdown_function', $arg1, $arg2); // If using PHP-FPM then fastcgi_finish_request() will have been fired // preventing further output to the browser which means that the escaping of // the exception message can not be tested. diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module index b44e0a0..5e8a552 100644 --- a/core/modules/system/tests/modules/system_test/system_test.module +++ b/core/modules/system/tests/modules/system_test/system_test.module @@ -1,7 +1,6 @@ acquire('system_test_lock_acquire')) { - \Drupal::lock()->release('system_test_lock_acquire'); - return ['#markup' => 'TRUE: Lock successfully acquired in system_test_lock_acquire()']; - } - else { - return ['#markup' => 'FALSE: Lock not acquired in system_test_lock_acquire()']; - } -} - -/** - * Try to acquire a specific lock, and then exit. - * - * @deprecated \Drupal\system_test\Controller\SystemTestController::lockExit() - */ -function system_test_lock_exit() { - if (\Drupal::lock()->acquire('system_test_lock_exit', 900)) { - echo 'TRUE: Lock successfully acquired in system_test_lock_exit()'; - // The shut-down function should release the lock. - exit(); - } - else { - return ['#markup' => 'FALSE: Lock not acquired in system_test_lock_exit()']; - } -} - -/** * Implements hook_page_attachments(). */ function system_test_page_attachments(array &$page) { @@ -107,15 +75,6 @@ function system_test_page_attachments(array &$page) { } /** - * A simple page callback which adds a register shutdown function. - * - * @deprecated \Drupal\system_test\Controller\SystemTestController::shutdownFunctions() - */ -function system_test_page_shutdown_functions($arg1, $arg2) { - drupal_register_shutdown_function('_system_test_first_shutdown_function', $arg1, $arg2); -} - -/** * Dummy shutdown function which registers another shutdown function. */ function _system_test_first_shutdown_function($arg1, $arg2) { @@ -152,19 +111,6 @@ function system_test_filetransfer_info() { } /** - * Page callback to initialize authorize.php during testing. - * - * @see system_authorized_init(). - * - * @deprecated \Drupal\system_test\Controller\SystemTestController::authorizeInit() - */ -function system_test_authorize_init_page($page_title) { - $authorize_url = $GLOBALS['base_url'] . '/core/authorize.php'; - system_authorized_init('system_test_authorize_run', drupal_get_path('module', 'system_test') . '/system_test.module', array(), $page_title); - return new RedirectResponse($authorize_url); -} - -/** * Implements hook_module_preinstall(). */ function system_test_module_preinstall($module) {