Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
c034303b
Commit
c034303b
authored
May 29, 2012
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1593402
by Rob Loach, aspilicious: Convert php tests to
PSR-0
.
parent
8b9b034c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
1 deletion
+143
-1
core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php
core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php
+39
-0
core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php
core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php
+49
-0
core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php
core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php
+55
-0
core/modules/php/php.info
core/modules/php/php.info
+0
-1
No files found.
core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php
0 → 100644
View file @
c034303b
<?php
/**
* @file
* Definition of Drupal\php\Tests\PhpAccessTest.
*/
namespace
Drupal\php\Tests
;
/**
* Tests to make sure access to the PHP filter is properly restricted.
*/
class
PhpAccessTest
extends
PhpTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'PHP filter access check'
,
'description'
=>
'Make sure that users who don\'t have access to the PHP filter can\'t see it.'
,
'group'
=>
'PHP'
,
);
}
/**
* Makes sure that the user can't use the PHP filter when not given access.
*/
function
testNoPrivileges
()
{
// Create node with PHP filter enabled.
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
'create page content'
,
'edit own page content'
));
$this
->
drupalLogin
(
$web_user
);
$node
=
$this
->
createNodeWithCode
();
// Make sure that the PHP code shows up as text.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertText
(
'print'
,
t
(
'PHP code was not evaluated.'
));
// Make sure that user doesn't have access to filter.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
.
'/edit'
);
$this
->
assertNoRaw
(
'<option value="'
.
$this
->
php_code_format
->
format
.
'">'
,
t
(
'PHP code format not available.'
));
}
}
core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php
0 → 100644
View file @
c034303b
<?php
/**
* @file
* Definition of Drupal\php\Tests\PhpFilterTest.
*/
namespace
Drupal\php\Tests
;
/**
* Tests to make sure the PHP filter actually evaluates PHP code when used.
*/
class
PhpFilterTest
extends
PhpTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'PHP filter functionality'
,
'description'
=>
'Make sure that PHP filter properly evaluates PHP code when enabled.'
,
'group'
=>
'PHP'
,
);
}
/**
* Makes sure that the PHP filter evaluates PHP code when used.
*/
function
testPhpFilter
()
{
// Log in as a user with permission to use the PHP code text format.
$php_code_permission
=
filter_permission_name
(
filter_format_load
(
'php_code'
));
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
'create page content'
,
'edit own page content'
,
$php_code_permission
));
$this
->
drupalLogin
(
$web_user
);
// Create a node with PHP code in it.
$node
=
$this
->
createNodeWithCode
();
// Make sure that the PHP code shows up as text.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertText
(
'php print'
);
// Change filter to PHP filter and see that PHP code is evaluated.
$edit
=
array
();
$langcode
=
LANGUAGE_NOT_SPECIFIED
;
$edit
[
"body[
$langcode
][0][format]"
]
=
$this
->
php_code_format
->
format
;
$this
->
drupalPost
(
'node/'
.
$node
->
nid
.
'/edit'
,
$edit
,
t
(
'Save'
));
$this
->
assertRaw
(
t
(
'Basic page %title has been updated.'
,
array
(
'%title'
=>
$node
->
title
)),
t
(
'PHP code filter turned on.'
));
// Make sure that the PHP code shows up as text.
$this
->
assertNoText
(
'print "SimpleTest PHP was executed!"'
,
t
(
"PHP code isn't displayed."
));
$this
->
assertText
(
'SimpleTest PHP was executed!'
,
t
(
'PHP code has been evaluated.'
));
}
}
core/modules/php/
php.test
→
core/modules/php/
lib/Drupal/php/Tests/PhpTestBase.php
View file @
c034303b
...
...
@@ -2,15 +2,17 @@
/**
* @file
*
Tests for php.modul
e.
*
Definition of Drupal\php\Tests\PhpTestBas
e.
*/
namespace
Drupal\php\Tests
;
use
Drupal\simpletest\WebTestBase
;
/**
* Defines a base PHP test case class.
*/
class
P
HP
Test
C
ase
extends
WebTestBase
{
class
P
hp
Test
B
ase
extends
WebTestBase
{
protected
$php_code_format
;
function
setUp
()
{
...
...
@@ -51,75 +53,3 @@ function createNodeWithCode() {
return
$this
->
drupalCreateNode
(
array
(
'body'
=>
array
(
LANGUAGE_NOT_SPECIFIED
=>
array
(
array
(
'value'
=>
'<?php print "SimpleTest PHP was executed!"; ?>'
)))));
}
}
/**
* Tests to make sure the PHP filter actually evaluates PHP code when used.
*/
class
PHPFilterTestCase
extends
PHPTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'PHP filter functionality'
,
'description'
=>
'Make sure that PHP filter properly evaluates PHP code when enabled.'
,
'group'
=>
'PHP'
,
);
}
/**
* Makes sure that the PHP filter evaluates PHP code when used.
*/
function
testPHPFilter
()
{
// Log in as a user with permission to use the PHP code text format.
$php_code_permission
=
filter_permission_name
(
filter_format_load
(
'php_code'
));
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
'create page content'
,
'edit own page content'
,
$php_code_permission
));
$this
->
drupalLogin
(
$web_user
);
// Create a node with PHP code in it.
$node
=
$this
->
createNodeWithCode
();
// Make sure that the PHP code shows up as text.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertText
(
'php print'
);
// Change filter to PHP filter and see that PHP code is evaluated.
$edit
=
array
();
$langcode
=
LANGUAGE_NOT_SPECIFIED
;
$edit
[
"body[
$langcode
][0][format]"
]
=
$this
->
php_code_format
->
format
;
$this
->
drupalPost
(
'node/'
.
$node
->
nid
.
'/edit'
,
$edit
,
t
(
'Save'
));
$this
->
assertRaw
(
t
(
'Basic page %title has been updated.'
,
array
(
'%title'
=>
$node
->
title
)),
t
(
'PHP code filter turned on.'
));
// Make sure that the PHP code shows up as text.
$this
->
assertNoText
(
'print "SimpleTest PHP was executed!"'
,
t
(
"PHP code isn't displayed."
));
$this
->
assertText
(
'SimpleTest PHP was executed!'
,
t
(
'PHP code has been evaluated.'
));
}
}
/**
* Tests to make sure access to the PHP filter is properly restricted.
*/
class
PHPAccessTestCase
extends
PHPTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'PHP filter access check'
,
'description'
=>
'Make sure that users who don\'t have access to the PHP filter can\'t see it.'
,
'group'
=>
'PHP'
,
);
}
/**
* Makes sure that the user can't use the PHP filter when not given access.
*/
function
testNoPrivileges
()
{
// Create node with PHP filter enabled.
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
'create page content'
,
'edit own page content'
));
$this
->
drupalLogin
(
$web_user
);
$node
=
$this
->
createNodeWithCode
();
// Make sure that the PHP code shows up as text.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertText
(
'print'
,
t
(
'PHP code was not evaluated.'
));
// Make sure that user doesn't have access to filter.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
.
'/edit'
);
$this
->
assertNoRaw
(
'<option value="'
.
$this
->
php_code_format
->
format
.
'">'
,
t
(
'PHP code format not available.'
));
}
}
core/modules/php/php.info
View file @
c034303b
...
...
@@ -3,4 +3,3 @@ description = Allows embedded PHP code/snippets to be evaluated.
package
=
Core
version
=
VERSION
core
=
8.
x
files
[]
=
php
.
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