Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
d29d6b27
Commit
d29d6b27
authored
Aug 02, 2012
by
catch
Browse files
Issue
#1611430
by Berdir: Fixed verbose debug output in unit tests relied on the database.
parent
09dd0eb9
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
View file @
d29d6b27
...
...
@@ -90,6 +90,36 @@ abstract class TestBase {
protected
$setupEnvironment
=
FALSE
;
/**
* TRUE if verbose debugging is enabled.
*
* @var boolean
*/
protected
$verbose
=
FALSE
;
/**
* Incrementing identifier for verbose output filenames.
*
* @var integer
*/
protected
$verboseId
=
0
;
/**
* Safe class name for use in verbose output filenames.
*
* Namespaces separator (\) replaced with _.
*
* @var string
*/
protected
$verboseClassName
;
/**
* Directory where verbose output files are put.
*
* @var string
*/
protected
$verboseDirectory
;
/**
* Constructor for Test.
*
...
...
@@ -457,11 +487,21 @@ protected function error($message = '', $group = 'Other', array $caller = NULL)
* @see simpletest_verbose()
*/
protected
function
verbose
(
$message
)
{
if
(
$id
=
simpletest_verbose
(
$message
))
{
$class
=
str_replace
(
'\\'
,
'_'
,
get_class
(
$this
));
$url
=
file_create_url
(
$this
->
originalFileDirectory
.
'/simpletest/verbose/'
.
$class
.
'-'
.
$id
.
'.html'
);
$this
->
error
(
l
(
t
(
'Verbose message'
),
$url
,
array
(
'attributes'
=>
array
(
'target'
=>
'_blank'
))),
'User notice'
);
// Do nothing if verbose debugging is disabled.
if
(
!
$this
->
verbose
)
{
return
;
}
$message
=
'<hr />ID #'
.
$this
->
verboseId
.
' (<a href="'
.
$this
->
verboseClassName
.
'-'
.
(
$this
->
verboseId
-
1
)
.
'.html">Previous</a> | <a href="'
.
$this
->
verboseClassName
.
'-'
.
(
$this
->
verboseId
+
1
)
.
'.html">Next</a>)<hr />'
.
$message
;
$verbose_filename
=
$this
->
verboseDirectory
.
'/'
.
$this
->
verboseClassName
.
'-'
.
$this
->
verboseId
.
'.html'
;
if
(
file_put_contents
(
$verbose_filename
,
$message
,
FILE_APPEND
))
{
$url
=
file_create_url
(
$this
->
originalFileDirectory
.
'/simpletest/verbose/'
.
$this
->
verboseClassName
.
'-'
.
$this
->
verboseId
.
'.html'
);
// Not using l() to avoid invoking the theme system, so that unit tests
// can use verbose() as well.
$url
=
'<a href="'
.
$url
.
'" target="_blank">'
.
t
(
'Verbose message'
)
.
'</a>'
;
$this
->
error
(
$url
,
'User notice'
);
}
$this
->
verboseId
++
;
}
/**
...
...
@@ -477,10 +517,16 @@ protected function verbose($message) {
* methods during debugging.
*/
public
function
run
(
array
$methods
=
array
())
{
// Initialize verbose debugging.
$class
=
get_class
(
$this
);
simpletest_verbose
(
NULL
,
variable_get
(
'file_public_path'
,
conf_path
()
.
'/files'
),
str_replace
(
'\\'
,
'_'
,
$class
));
if
(
variable_get
(
'simpletest_verbose'
,
TRUE
))
{
// Initialize verbose debugging.
$this
->
verbose
=
TRUE
;
$this
->
verboseDirectory
=
variable_get
(
'file_public_path'
,
conf_path
()
.
'/files'
)
.
'/simpletest/verbose'
;
if
(
file_prepare_directory
(
$this
->
verboseDirectory
,
FILE_CREATE_DIRECTORY
)
&&
!
file_exists
(
$this
->
verboseDirectory
.
'/.htaccess'
))
{
file_put_contents
(
$this
->
verboseDirectory
.
'/.htaccess'
,
"<IfModule mod_expires.c>
\n
ExpiresActive Off
\n
</IfModule>
\n
"
);
}
$this
->
verboseClassName
=
str_replace
(
"
\\
"
,
"_"
,
$class
);
}
// HTTP auth settings (<username>:<password>) for the simpletest browser
// when sending requests to the test site.
$this
->
httpauth_method
=
variable_get
(
'simpletest_httpauth_method'
,
CURLAUTH_BASIC
);
...
...
core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
View file @
d29d6b27
...
...
@@ -55,12 +55,6 @@ protected function setUp() {
// Enforce an empty module list.
module_list
(
NULL
,
array
());
// Re-implant theme registry.
// Required for l() and other functions to work correctly and not trigger
// database lookups.
$theme_get_registry
=
&
drupal_static
(
'theme_get_registry'
);
$theme_get_registry
[
FALSE
]
=
$this
->
originalThemeRegistry
;
$conf
[
'file_public_path'
]
=
$this
->
public_files_directory
;
// Change the database prefix.
...
...
core/modules/simpletest/simpletest.module
View file @
d29d6b27
...
...
@@ -566,51 +566,3 @@ function simpletest_mail_alter(&$message) {
$message
[
'send'
]
=
FALSE
;
}
}
/**
* Logs verbose message in a text file.
*
* If verbose mode is enabled then page requests will be dumped to a file and
* presented on the test result screen. The messages will be placed in a file
* located in the simpletest directory in the original file system.
*
* @param $message
* The verbose message to be stored.
* @param $original_file_directory
* The original file directory, before it was changed for testing purposes.
* @param $test_class
* The active test case class.
*
* @return
* The ID of the message to be placed in related assertion messages.
*
* @see Drupal\simpletest\TestBase->originalFileDirectory()
* @see Drupal\simpletest\WebTestBase->verbose()
*/
function
simpletest_verbose
(
$message
,
$original_file_directory
=
NULL
,
$test_class
=
NULL
)
{
static
$file_directory
=
NULL
,
$class
=
NULL
,
$id
=
1
,
$verbose
=
NULL
;
// Will pass first time during setup phase, and when verbose is TRUE.
if
(
!
isset
(
$original_file_directory
)
&&
!
$verbose
)
{
return
FALSE
;
}
if
(
$message
&&
$file_directory
)
{
$message
=
'<hr />ID #'
.
$id
.
' (<a href="'
.
$class
.
'-'
.
(
$id
-
1
)
.
'.html">Previous</a> | <a href="'
.
$class
.
'-'
.
(
$id
+
1
)
.
'.html">Next</a>)<hr />'
.
$message
;
file_put_contents
(
$file_directory
.
"/simpletest/verbose/
$class
-
$id
.html"
,
$message
,
FILE_APPEND
);
return
$id
++
;
}
if
(
$original_file_directory
)
{
$file_directory
=
$original_file_directory
;
$class
=
$test_class
;
$verbose
=
variable_get
(
'simpletest_verbose'
,
TRUE
);
$directory
=
$file_directory
.
'/simpletest/verbose'
;
$writable
=
file_prepare_directory
(
$directory
,
FILE_CREATE_DIRECTORY
);
if
(
$writable
&&
!
file_exists
(
$directory
.
'/.htaccess'
))
{
file_put_contents
(
$directory
.
'/.htaccess'
,
"<IfModule mod_expires.c>
\n
ExpiresActive Off
\n
</IfModule>
\n
"
);
}
return
$writable
;
}
return
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