Commit e132a971 authored by alexpott's avatar alexpott

Issue #1987832 by aspilicious, disasm, webflo, vijaycs85, adci_contributor,...

Issue #1987832 by aspilicious, disasm, webflo, vijaycs85, adci_contributor, vks7056: Convert system_test callbacks to a new style controller
parent f100d942
......@@ -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');
......
......@@ -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;
......@@ -18,6 +20,13 @@
*/
class SystemTestController extends ControllerBase {
/**
* The lock service.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lock;
/**
* The persistent lock service.
*
......@@ -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.
......
<?php
use Drupal\Core\Extension\Extension;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Implements hook_modules_installed().
......@@ -64,37 +63,6 @@ function system_test_system_info_alter(&$info, Extension $file, $type) {
}
}
/**
* Try to acquire a named lock and report the outcome.
*
* @deprecated \Drupal\system_test\Controller\SystemTestController::lockAcquire()
*/
function system_test_lock_acquire() {
if (\Drupal::lock()->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().
*/
......@@ -106,15 +74,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.
*/
......@@ -151,19 +110,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().
*/
......
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