From 9a83d2142b5f65819a9f3a55cdea5ff6a08ce4ed Mon Sep 17 00:00:00 2001 From: Jennifer Hodgdon <yahgrp@poplarware.com> Date: Wed, 30 May 2012 15:19:13 -0700 Subject: [PATCH] Issue #1597630 by Rob Loach: Convert actions.test to PSR-0 --- .../Tests/Actions/ConfigurationTest.php} | 75 +++---------------- .../Drupal/system/Tests/Actions/LoopTest.php | 73 ++++++++++++++++++ core/modules/system/system.info | 1 - 3 files changed, 84 insertions(+), 65 deletions(-) rename core/modules/system/{tests/actions.test => lib/Drupal/system/Tests/Actions/ConfigurationTest.php} (56%) create mode 100644 core/modules/system/lib/Drupal/system/Tests/Actions/LoopTest.php diff --git a/core/modules/system/tests/actions.test b/core/modules/system/lib/Drupal/system/Tests/Actions/ConfigurationTest.php similarity index 56% rename from core/modules/system/tests/actions.test rename to core/modules/system/lib/Drupal/system/Tests/Actions/ConfigurationTest.php index 469b16e13d51..1a31fb4ff1cd 100644 --- a/core/modules/system/tests/actions.test +++ b/core/modules/system/lib/Drupal/system/Tests/Actions/ConfigurationTest.php @@ -1,8 +1,18 @@ <?php +/** + * @file + * Definition of Drupal\system\Tests\Actions\ConfigurationTest. + */ + +namespace Drupal\system\Tests\Actions; + use Drupal\simpletest\WebTestBase; -class ActionsConfigurationTestCase extends WebTestBase { +/** + * Actions configuration. + */ +class ConfigurationTest extends WebTestBase { public static function getInfo() { return array( 'name' => 'Actions configuration', @@ -64,66 +74,3 @@ function testActionConfiguration() { $this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.')); } } - -/** - * Test actions executing in a potential loop, and make sure they abort properly. - */ -class ActionLoopTestCase extends WebTestBase { - protected $aid; - - public static function getInfo() { - return array( - 'name' => 'Actions executing in a potentially infinite loop', - 'description' => 'Tests actions executing in a loop, and makes sure they abort properly.', - 'group' => 'Actions', - ); - } - - function setUp() { - parent::setUp('dblog', 'actions_loop_test'); - } - - /** - * Set up a loop with 3 - 12 recursions, and see if it aborts properly. - */ - function testActionLoop() { - $user = $this->drupalCreateUser(array('administer actions')); - $this->drupalLogin($user); - - $info = actions_loop_test_action_info(); - $this->aid = actions_save('actions_loop_test_log', $info['actions_loop_test_log']['type'], array(), $info['actions_loop_test_log']['label']); - - // Delete any existing watchdog messages to clear the plethora of - // "Action added" messages from when Drupal was installed. - db_delete('watchdog')->execute(); - // To prevent this test from failing when xdebug is enabled, the maximum - // recursion level should be kept low enough to prevent the xdebug - // infinite recursion protection mechanism from aborting the request. - // See http://drupal.org/node/587634. - variable_set('actions_max_stack', mt_rand(3, 12)); - $this->triggerActions(); - } - - /** - * Create an infinite loop by causing a watchdog message to be set, - * which causes the actions to be triggered again, up to actions_max_stack - * times. - */ - protected function triggerActions() { - $this->drupalGet('<front>', array('query' => array('trigger_actions_on_watchdog' => $this->aid))); - $expected = array(); - $expected[] = 'Triggering action loop'; - for ($i = 1; $i <= variable_get('actions_max_stack', 35); $i++) { - $expected[] = "Test log #$i"; - } - $expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.'; - - $result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid"); - $loop_started = FALSE; - foreach ($result as $row) { - $expected_message = array_shift($expected); - $this->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array('%expected' => $expected_message, '%message' => $row->message))); - } - $this->assertTrue(empty($expected), t('All expected messages found.')); - } -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Actions/LoopTest.php b/core/modules/system/lib/Drupal/system/Tests/Actions/LoopTest.php new file mode 100644 index 000000000000..97667c0cea5d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Actions/LoopTest.php @@ -0,0 +1,73 @@ +<?php + +/** + * @file + * Definition of Drupal\system\Tests\Actions\LoopTest. + */ + +namespace Drupal\system\Tests\Actions; + +use Drupal\simpletest\WebTestBase; + +/** + * Test actions executing in a potential loop, and make sure they abort properly. + */ +class LoopTest extends WebTestBase { + protected $aid; + + public static function getInfo() { + return array( + 'name' => 'Actions executing in a potentially infinite loop', + 'description' => 'Tests actions executing in a loop, and makes sure they abort properly.', + 'group' => 'Actions', + ); + } + + function setUp() { + parent::setUp('dblog', 'actions_loop_test'); + } + + /** + * Set up a loop with 3 - 12 recursions, and see if it aborts properly. + */ + function testActionLoop() { + $user = $this->drupalCreateUser(array('administer actions')); + $this->drupalLogin($user); + + $info = actions_loop_test_action_info(); + $this->aid = actions_save('actions_loop_test_log', $info['actions_loop_test_log']['type'], array(), $info['actions_loop_test_log']['label']); + + // Delete any existing watchdog messages to clear the plethora of + // "Action added" messages from when Drupal was installed. + db_delete('watchdog')->execute(); + // To prevent this test from failing when xdebug is enabled, the maximum + // recursion level should be kept low enough to prevent the xdebug + // infinite recursion protection mechanism from aborting the request. + // See http://drupal.org/node/587634. + variable_set('actions_max_stack', mt_rand(3, 12)); + $this->triggerActions(); + } + + /** + * Create an infinite loop by causing a watchdog message to be set, + * which causes the actions to be triggered again, up to actions_max_stack + * times. + */ + protected function triggerActions() { + $this->drupalGet('<front>', array('query' => array('trigger_actions_on_watchdog' => $this->aid))); + $expected = array(); + $expected[] = 'Triggering action loop'; + for ($i = 1; $i <= variable_get('actions_max_stack', 35); $i++) { + $expected[] = "Test log #$i"; + } + $expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.'; + + $result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid"); + $loop_started = FALSE; + foreach ($result as $row) { + $expected_message = array_shift($expected); + $this->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array('%expected' => $expected_message, '%message' => $row->message))); + } + $this->assertTrue(empty($expected), t('All expected messages found.')); + } +} diff --git a/core/modules/system/system.info b/core/modules/system/system.info index a95825c0bd18..1b87b854f238 100644 --- a/core/modules/system/system.info +++ b/core/modules/system/system.info @@ -8,7 +8,6 @@ required = TRUE configure = admin/config/system ; Tests in tests directory. -files[] = tests/actions.test files[] = tests/ajax.test files[] = tests/batch.test files[] = tests/bootstrap.test -- GitLab