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
220
Merge Requests
220
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
0d3968ee
Commit
0d3968ee
authored
Mar 17, 2013
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1935922
by msonnabaum: Convert PhpStorage tests to phpunit.
parent
c0475473
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
30 deletions
+30
-30
core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
...sts/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
+6
-6
core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFastFileStorageTest.php
...omponent/PhpStorage/MTimeProtectedFastFileStorageTest.php
+2
-2
core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageTest.php
...ts/Component/PhpStorage/MTimeProtectedFileStorageTest.php
+12
-12
core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php
.../Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php
+10
-10
No files found.
core/
modules/system/lib/Drupal/system/Tests
/PhpStorage/FileStorageTest.php
→
core/
tests/Drupal/Tests/Component
/PhpStorage/FileStorageTest.php
View file @
0d3968ee
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\
system\Tests
\PhpStorage\FileStorageTest.
* Definition of Drupal\
Tests\Component
\PhpStorage\FileStorageTest.
*/
namespace
Drupal\
system\Tests
\PhpStorage
;
namespace
Drupal\
Tests\Component
\PhpStorage
;
/**
* Tests the simple file storage.
...
...
@@ -23,7 +23,7 @@ public static function getInfo() {
function
setUp
()
{
global
$conf
;
parent
::
setUp
();
$dir_path
=
DRUPAL_ROOT
.
'/'
.
$this
->
public_files_directory
.
'/php'
;
$dir_path
=
sys_get_temp_dir
()
.
'/php'
;
$conf
[
'php_storage'
][
'simpletest'
]
=
array
(
'class'
=>
'Drupal\Component\PhpStorage\FileStorage'
,
'directory'
=>
$dir_path
,
...
...
@@ -41,7 +41,7 @@ function setUp() {
*/
function
testCRUD
()
{
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$this
->
assertI
dentical
(
get_class
(
$php
),
'Drupal\Component\PhpStorage\FileStorage'
);
$this
->
assertI
nstanceOf
(
'Drupal\Component\PhpStorage\FileStorage'
,
$php
);
$this
->
assertCRUD
(
$php
);
}
...
...
@@ -60,14 +60,14 @@ function testReadOnly() {
// Write out a PHP file and ensure it's successfully loaded.
$code
=
"<?php
\n\$
GLOBALS[
$random
] = TRUE;"
;
$success
=
$php
->
save
(
$name
,
$code
);
$this
->
assert
Identical
(
$success
,
TRUE
);
$this
->
assert
Same
(
$success
,
TRUE
);
$php_read
=
$this
->
storageFactory
->
get
(
'readonly'
);
$php_read
->
load
(
$name
);
$this
->
assertTrue
(
$GLOBALS
[
$random
]);
// If the file was successfully loaded, it must also exist, but ensure the
// exists() method returns that correctly.
$this
->
assert
Identical
(
$php_read
->
exists
(
$name
),
TRUE
);
$this
->
assert
Same
(
$php_read
->
exists
(
$name
),
TRUE
);
// Saving and deleting should always fail.
$this
->
assertFalse
(
$php_read
->
save
(
$name
,
$code
));
$this
->
assertFalse
(
$php_read
->
delete
(
$name
));
...
...
core/
modules/system/lib/Drupal/system/Tests
/PhpStorage/MTimeProtectedFastFileStorageTest.php
→
core/
tests/Drupal/Tests/Component
/PhpStorage/MTimeProtectedFastFileStorageTest.php
View file @
0d3968ee
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\
system\Tests
\PhpStorage\MTimeProtectedFileStorageTest.
* Definition of Drupal\
Tests\Component
\PhpStorage\MTimeProtectedFileStorageTest.
*/
namespace
Drupal\
system\Tests
\PhpStorage
;
namespace
Drupal\
Tests\Component
\PhpStorage
;
/**
* Tests the directory mtime based PHP loader implementation.
...
...
core/
modules/system/lib/Drupal/system/Tests
/PhpStorage/MTimeProtectedFileStorageTest.php
→
core/
tests/Drupal/Tests/Component
/PhpStorage/MTimeProtectedFileStorageTest.php
View file @
0d3968ee
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\
system\Tests
\PhpStorage\MTimeProtectedFileStorageTest.
* Definition of Drupal\
Tests\Component
\PhpStorage\MTimeProtectedFileStorageTest.
*/
namespace
Drupal\
system\Tests
\PhpStorage
;
namespace
Drupal\
Tests\Component
\PhpStorage
;
use
Drupal\Component\PhpStorage\PhpStorageFactory
;
...
...
@@ -38,7 +38,7 @@ function setUp() {
$this
->
secret
=
$this
->
randomName
();
$conf
[
'php_storage'
][
'simpletest'
]
=
array
(
'class'
=>
$this
->
storageClass
,
'directory'
=>
DRUPAL_ROOT
.
'/'
.
$this
->
public_files_directory
.
'/php'
,
'directory'
=>
sys_get_temp_dir
()
.
'/php'
,
'secret'
=>
$this
->
secret
,
);
}
...
...
@@ -48,7 +48,7 @@ function setUp() {
*/
function
testCRUD
()
{
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$this
->
assert
Identical
(
get_class
(
$php
),
$this
->
storageClass
);
$this
->
assert
Same
(
get_class
(
$php
),
$this
->
storageClass
);
$this
->
assertCRUD
(
$php
);
}
...
...
@@ -62,7 +62,7 @@ function testSecurity() {
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$name
=
'simpletest.php'
;
$php
->
save
(
$name
,
'<?php'
);
$expected_root_directory
=
DRUPAL_ROOT
.
'/'
.
$this
->
public_files_directory
.
'/php/simpletest'
;
$expected_root_directory
=
sys_get_temp_dir
()
.
'/php/simpletest'
;
$expected_directory
=
$expected_root_directory
.
'/'
.
$name
;
$directory_mtime
=
filemtime
(
$expected_directory
);
$expected_filename
=
$expected_directory
.
'/'
.
hash_hmac
(
'sha256'
,
$name
,
$this
->
secret
.
$directory_mtime
)
.
'.php'
;
...
...
@@ -71,12 +71,12 @@ function testSecurity() {
// minimal permissions. fileperms() can return high bits unrelated to
// permissions, so mask with 0777.
$this
->
assertTrue
(
file_exists
(
$expected_filename
));
$this
->
assert
Identical
(
fileperms
(
$expected_filename
)
&
0777
,
0400
);
$this
->
assert
Identical
(
fileperms
(
$expected_directory
)
&
0777
,
0100
);
$this
->
assert
Same
(
fileperms
(
$expected_filename
)
&
0777
,
0400
);
$this
->
assert
Same
(
fileperms
(
$expected_directory
)
&
0777
,
0100
);
// Ensure the root directory for the bin has a .htaccess file denying web
// access.
$this
->
assert
Identical
(
file_get_contents
(
$expected_root_directory
.
'/.htaccess'
),
"SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
\n
Deny from all
\n
Options None
\n
Options +FollowSymLinks"
);
$this
->
assert
Same
(
file_get_contents
(
$expected_root_directory
.
'/.htaccess'
),
"SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
\n
Deny from all
\n
Options None
\n
Options +FollowSymLinks"
);
// Ensure that if the file is replaced with an untrusted one (due to another
// script's file upload vulnerability), it does not get loaded. Since mtime
...
...
@@ -103,10 +103,10 @@ function testSecurity() {
}
chmod
(
$expected_filename
,
0400
);
chmod
(
$expected_directory
,
0100
);
$this
->
assert
Identical
(
file_get_contents
(
$expected_filename
),
$untrusted_code
);
$this
->
assert
Identical
(
$php
->
exists
(
$name
),
$this
->
expected
[
$i
]);
$this
->
assert
Identical
(
$php
->
load
(
$name
),
$this
->
expected
[
$i
]);
$this
->
assert
Identical
(
$GLOBALS
[
'hacked'
],
$this
->
expected
[
$i
]);
$this
->
assert
Same
(
file_get_contents
(
$expected_filename
),
$untrusted_code
);
$this
->
assert
Same
(
$php
->
exists
(
$name
),
$this
->
expected
[
$i
]);
$this
->
assert
Same
(
$php
->
load
(
$name
),
$this
->
expected
[
$i
]);
$this
->
assert
Same
(
$GLOBALS
[
'hacked'
],
$this
->
expected
[
$i
]);
}
}
}
core/
modules/system/lib/Drupal/system/Tests
/PhpStorage/PhpStorageTestBase.php
→
core/
tests/Drupal/Tests/Component
/PhpStorage/PhpStorageTestBase.php
View file @
0d3968ee
...
...
@@ -2,18 +2,18 @@
/**
* @file
* Definition of Drupal\
system\Tests
\PhpStorage\PhpStorageTestBase.
* Definition of Drupal\
Tests\Component
\PhpStorage\PhpStorageTestBase.
*/
namespace
Drupal\
system\Tests
\PhpStorage
;
namespace
Drupal\
Tests\Component
\PhpStorage
;
use
Drupal\
simpletest\UnitTestB
ase
;
use
Drupal\
Tests\UnitTestC
ase
;
use
Drupal\Component\PhpStorage\PhpStorageFactory
;
/**
* Base test for PHP storage controllers.
*/
abstract
class
PhpStorageTestBase
extends
UnitTest
B
ase
{
abstract
class
PhpStorageTestBase
extends
UnitTest
C
ase
{
/**
* The storage factory object.
...
...
@@ -23,7 +23,7 @@ abstract class PhpStorageTestBase extends UnitTestBase {
protected
$storageFactory
;
/**
* Overrides \Drupal\
simpletest\UnitTestB
ase::setUp()
* Overrides \Drupal\
Tests\UnitTestC
ase::setUp()
*/
function
setUp
()
{
parent
::
setUp
();
...
...
@@ -44,21 +44,21 @@ public function assertCRUD($php) {
// Write out a PHP file and ensure it's successfully loaded.
$code
=
"<?php
\n\$
GLOBALS[
$random
] = TRUE;"
;
$success
=
$php
->
save
(
$name
,
$code
);
$this
->
assert
Identical
(
$success
,
TRUE
);
$this
->
assert
Same
(
$success
,
TRUE
);
$php
->
load
(
$name
);
$this
->
assertTrue
(
$GLOBALS
[
$random
]);
// If the file was successfully loaded, it must also exist, but ensure the
// exists() method returns that correctly.
$this
->
assert
Identical
(
$php
->
exists
(
$name
),
TRUE
);
$this
->
assert
Same
(
$php
->
exists
(
$name
),
TRUE
);
// Delete the file, and then ensure exists() returns FALSE.
$success
=
$php
->
delete
(
$name
);
$this
->
assert
Identical
(
$success
,
TRUE
);
$this
->
assert
Identical
(
$php
->
exists
(
$name
),
FALSE
);
$this
->
assert
Same
(
$success
,
TRUE
);
$this
->
assert
Same
(
$php
->
exists
(
$name
),
FALSE
);
// Ensure delete() can be called on a non-existing file. It should return
// FALSE, but not trigger errors.
$this
->
assert
Identical
(
$php
->
delete
(
$name
),
FALSE
);
$this
->
assert
Same
(
$php
->
delete
(
$name
),
FALSE
);
}
}
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