Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
229
Merge Requests
229
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
9a83d214
Commit
9a83d214
authored
May 30, 2012
by
jhodgdon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1597630
by Rob Loach: Convert actions.test to
PSR-0
parent
876d410c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
65 deletions
+84
-65
core/modules/system/lib/Drupal/system/Tests/Actions/ConfigurationTest.php
...tem/lib/Drupal/system/Tests/Actions/ConfigurationTest.php
+11
-64
core/modules/system/lib/Drupal/system/Tests/Actions/LoopTest.php
...dules/system/lib/Drupal/system/Tests/Actions/LoopTest.php
+73
-0
core/modules/system/system.info
core/modules/system/system.info
+0
-1
No files found.
core/modules/system/
tests/actions.test
→
core/modules/system/
lib/Drupal/system/Tests/Actions/ConfigurationTest.php
View file @
9a83d214
<?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.'
));
}
}
core/modules/system/lib/Drupal/system/Tests/Actions/LoopTest.php
0 → 100644
View file @
9a83d214
<?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.'
));
}
}
core/modules/system/system.info
View file @
9a83d214
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment