Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
25f081af
Commit
25f081af
authored
11 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2051385
by jhedstrom: Expand phpunit tests for \Drupal\Component\PhpStorage.
parent
89773d1a
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
+62
-4
62 additions, 4 deletions
...sts/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
with
62 additions
and
4 deletions
core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
+
62
−
4
View file @
25f081af
...
...
@@ -2,7 +2,7 @@
/**
* @file
*
Definition of
Drupal\Tests\Component\PhpStorage\FileStorageTest.
*
Contains \
Drupal\Tests\Component\PhpStorage\FileStorageTest.
*/
namespace
Drupal\Tests\Component\PhpStorage
;
...
...
@@ -20,7 +20,7 @@ public static function getInfo() {
);
}
function
setUp
()
{
public
function
setUp
()
{
global
$conf
;
parent
::
setUp
();
$dir_path
=
sys_get_temp_dir
()
.
'/php'
;
...
...
@@ -38,8 +38,11 @@ function setUp() {
/**
* Tests basic load/save/delete operations.
*
* @group Drupal
* @group PhpStorage
*/
function
testCRUD
()
{
public
function
testCRUD
()
{
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$this
->
assertInstanceOf
(
'Drupal\Component\PhpStorage\FileStorage'
,
$php
);
$this
->
assertCRUD
(
$php
);
...
...
@@ -47,8 +50,11 @@ function testCRUD() {
/**
* Tests writing with one class and reading with another.
*
* @group Drupal
* @group PhpStorage
*/
function
testReadOnly
()
{
public
function
testReadOnly
()
{
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$name
=
$this
->
randomName
()
.
'/'
.
$this
->
randomName
()
.
'.php'
;
...
...
@@ -72,4 +78,56 @@ function testReadOnly() {
$this
->
assertFalse
(
$php_read
->
save
(
$name
,
$code
));
$this
->
assertFalse
(
$php_read
->
delete
(
$name
));
}
/**
* Tests writeable() method.
*
* @group Drupal
* @group PhpStorage
*/
public
function
testWriteable
()
{
$php_read
=
$this
->
storageFactory
->
get
(
'readonly'
);
$this
->
assertFalse
(
$php_read
->
writeable
());
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$this
->
assertTrue
(
$php
->
writeable
());
}
/**
* Tests deleteAll() method.
*
* @group Drupal
* @group PhpStorage
*/
public
function
testDeleteAll
()
{
$php_read
=
$this
->
storageFactory
->
get
(
'readonly'
);
$this
->
assertFalse
(
$php_read
->
deleteAll
());
// Make sure directory exists prior to removal.
$this
->
assertTrue
(
file_exists
(
sys_get_temp_dir
()
.
'/php/simpletest'
),
'File storage directory does not exist.'
);
// Write out some files.
$php
=
$this
->
storageFactory
->
get
(
'simpletest'
);
$name
=
$this
->
randomName
()
.
'/'
.
$this
->
randomName
()
.
'.php'
;
// Find a global that doesn't exist.
do
{
$random
=
mt_rand
(
10000
,
100000
);
}
while
(
isset
(
$GLOBALS
[
$random
]));
// Write out a PHP file and ensure it's successfully loaded.
$code
=
"<?php
\n\$
GLOBALS[
$random
] = TRUE;"
;
$success
=
$php
->
save
(
$name
,
$code
);
$this
->
assertSame
(
$success
,
TRUE
);
$php
->
load
(
$name
);
$this
->
assertTrue
(
$GLOBALS
[
$random
]);
$this
->
assertTrue
(
$php
->
deleteAll
());
$this
->
assertFalse
(
$php
->
load
(
$name
));
$this
->
assertFalse
(
file_exists
(
sys_get_temp_dir
()
.
'/php/simpletest'
),
'File storage directory still exists after call to deleteAll().'
);
// Should still return TRUE if directory has already been deleted.
$this
->
assertTrue
(
$php
->
deleteAll
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment