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
fbe34afe
Commit
fbe34afe
authored
Jun 08, 2012
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1598564
by Niklas Fiekas: Convert common.test to
PSR-0
.
parent
f6f33a19
Changes
25
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
3052 additions
and
2819 deletions
+3052
-2819
core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
...les/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
+92
-0
core/modules/system/lib/Drupal/system/Tests/Common/AlterTest.php
...dules/system/lib/Drupal/system/Tests/Common/AlterTest.php
+73
-0
core/modules/system/lib/Drupal/system/Tests/Common/ArrayUnitTest.php
...s/system/lib/Drupal/system/Tests/Common/ArrayUnitTest.php
+122
-0
core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php
...tem/lib/Drupal/system/Tests/Common/AttributesUnitTest.php
+50
-0
core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php
...b/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php
+67
-0
core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php
...b/Drupal/system/Tests/Common/CascadingStylesheetsTest.php
+244
-0
core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsUnitTest.php
...upal/system/Tests/Common/CascadingStylesheetsUnitTest.php
+62
-0
core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php
.../system/lib/Drupal/system/Tests/Common/FormatDateTest.php
+139
-0
core/modules/system/lib/Drupal/system/Tests/Common/GotoTest.php
...odules/system/lib/Drupal/system/Tests/Common/GotoTest.php
+79
-0
core/modules/system/lib/Drupal/system/Tests/Common/HtmlIdentifierUnitTest.php
...lib/Drupal/system/Tests/Common/HtmlIdentifierUnitTest.php
+70
-0
core/modules/system/lib/Drupal/system/Tests/Common/HttpRequestTest.php
...system/lib/Drupal/system/Tests/Common/HttpRequestTest.php
+142
-0
core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php
.../system/lib/Drupal/system/Tests/Common/JavaScriptTest.php
+501
-0
core/modules/system/lib/Drupal/system/Tests/Common/JsonUnitTest.php
...es/system/lib/Drupal/system/Tests/Common/JsonUnitTest.php
+74
-0
core/modules/system/lib/Drupal/system/Tests/Common/ParseInfoFileUnitTest.php
.../lib/Drupal/system/Tests/Common/ParseInfoFileUnitTest.php
+33
-0
core/modules/system/lib/Drupal/system/Tests/Common/RegionContentTest.php
...stem/lib/Drupal/system/Tests/Common/RegionContentTest.php
+55
-0
core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
...ules/system/lib/Drupal/system/Tests/Common/RenderTest.php
+329
-0
core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php
...upal/system/Tests/Common/SimpleTestErrorCollectorTest.php
+101
-0
core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php
...es/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php
+110
-0
core/modules/system/lib/Drupal/system/Tests/Common/SystemListingTest.php
...stem/lib/Drupal/system/Tests/Common/SystemListingTest.php
+65
-0
core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php
...modules/system/lib/Drupal/system/Tests/Common/UrlTest.php
+220
-0
core/modules/system/lib/Drupal/system/Tests/Common/ValidNumberStepUnitTest.php
...ib/Drupal/system/Tests/Common/ValidNumberStepUnitTest.php
+77
-0
core/modules/system/lib/Drupal/system/Tests/Common/ValidUrlUnitTest.php
...ystem/lib/Drupal/system/Tests/Common/ValidUrlUnitTest.php
+118
-0
core/modules/system/lib/Drupal/system/Tests/Common/WriteRecordTest.php
...system/lib/Drupal/system/Tests/Common/WriteRecordTest.php
+147
-0
core/modules/system/lib/Drupal/system/Tests/Common/XssUnitTest.php
...les/system/lib/Drupal/system/Tests/Common/XssUnitTest.php
+82
-0
core/modules/system/tests/common.test
core/modules/system/tests/common.test
+0
-2819
No files found.
core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
0 → 100644
View file @
fbe34afe
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\AddFeedTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\WebTestBase
;
/**
* Basic tests for drupal_add_feed().
*/
class
AddFeedTest
extends
WebTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'drupal_add_feed() tests'
,
'description'
=>
'Make sure that drupal_add_feed() works correctly with various constructs.'
,
'group'
=>
'Common'
,
);
}
/**
* Test drupal_add_feed() with paths, URLs, and titles.
*/
function
testBasicFeedAddNoTitle
()
{
$path
=
$this
->
randomName
(
12
);
$external_url
=
'http://'
.
$this
->
randomName
(
12
)
.
'/'
.
$this
->
randomName
(
12
);
$fully_qualified_local_url
=
url
(
$this
->
randomName
(
12
),
array
(
'absolute'
=>
TRUE
));
$path_for_title
=
$this
->
randomName
(
12
);
$external_for_title
=
'http://'
.
$this
->
randomName
(
12
)
.
'/'
.
$this
->
randomName
(
12
);
$fully_qualified_for_title
=
url
(
$this
->
randomName
(
12
),
array
(
'absolute'
=>
TRUE
));
// Possible permutations of drupal_add_feed() to test.
// - 'input_url': the path passed to drupal_add_feed(),
// - 'output_url': the expected URL to be found in the header.
// - 'title' == the title of the feed as passed into drupal_add_feed().
$urls
=
array
(
'path without title'
=>
array
(
'input_url'
=>
$path
,
'output_url'
=>
url
(
$path
,
array
(
'absolute'
=>
TRUE
)),
'title'
=>
''
,
),
'external url without title'
=>
array
(
'input_url'
=>
$external_url
,
'output_url'
=>
$external_url
,
'title'
=>
''
,
),
'local url without title'
=>
array
(
'input_url'
=>
$fully_qualified_local_url
,
'output_url'
=>
$fully_qualified_local_url
,
'title'
=>
''
,
),
'path with title'
=>
array
(
'input_url'
=>
$path_for_title
,
'output_url'
=>
url
(
$path_for_title
,
array
(
'absolute'
=>
TRUE
)),
'title'
=>
$this
->
randomName
(
12
),
),
'external url with title'
=>
array
(
'input_url'
=>
$external_for_title
,
'output_url'
=>
$external_for_title
,
'title'
=>
$this
->
randomName
(
12
),
),
'local url with title'
=>
array
(
'input_url'
=>
$fully_qualified_for_title
,
'output_url'
=>
$fully_qualified_for_title
,
'title'
=>
$this
->
randomName
(
12
),
),
);
foreach
(
$urls
as
$description
=>
$feed_info
)
{
drupal_add_feed
(
$feed_info
[
'input_url'
],
$feed_info
[
'title'
]);
}
$this
->
drupalSetContent
(
drupal_get_html_head
());
foreach
(
$urls
as
$description
=>
$feed_info
)
{
$this
->
assertPattern
(
$this
->
urlToRSSLinkPattern
(
$feed_info
[
'output_url'
],
$feed_info
[
'title'
]),
t
(
'Found correct feed header for %description'
,
array
(
'%description'
=>
$description
)));
}
}
/**
* Create a pattern representing the RSS feed in the page.
*/
function
urlToRSSLinkPattern
(
$url
,
$title
=
''
)
{
// Escape any regular expression characters in the url ('?' is the worst).
$url
=
preg_replace
(
'/([+?.*])/'
,
'[$0]'
,
$url
);
$generated_pattern
=
'%<link +rel="alternate" +type="application/rss.xml" +title="'
.
$title
.
'" +href="'
.
$url
.
'" */>%'
;
return
$generated_pattern
;
}
}
core/modules/system/lib/Drupal/system/Tests/Common/AlterTest.php
0 → 100644
View file @
fbe34afe
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\AlterTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\WebTestBase
;
use
stdClass
;
/**
* Tests alteration of arguments passed to drupal_alter().
*/
class
AlterTest
extends
WebTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Alter hook functionality'
,
'description'
=>
'Tests alteration of arguments passed to drupal_alter().'
,
'group'
=>
'Common'
,
);
}
function
setUp
()
{
parent
::
setUp
(
array
(
'block'
,
'common_test'
));
}
function
testDrupalAlter
()
{
// This test depends on Bartik, so make sure that it is always the current
// active theme.
global
$theme
,
$base_theme_info
;
$theme
=
'bartik'
;
$base_theme_info
=
array
();
$array
=
array
(
'foo'
=>
'bar'
);
$entity
=
new
stdClass
();
$entity
->
foo
=
'bar'
;
// Verify alteration of a single argument.
$array_copy
=
$array
;
$array_expected
=
array
(
'foo'
=>
'Drupal theme'
);
drupal_alter
(
'drupal_alter'
,
$array_copy
);
$this
->
assertEqual
(
$array_copy
,
$array_expected
,
t
(
'Single array was altered.'
));
$entity_copy
=
clone
$entity
;
$entity_expected
=
clone
$entity
;
$entity_expected
->
foo
=
'Drupal theme'
;
drupal_alter
(
'drupal_alter'
,
$entity_copy
);
$this
->
assertEqual
(
$entity_copy
,
$entity_expected
,
t
(
'Single object was altered.'
));
// Verify alteration of multiple arguments.
$array_copy
=
$array
;
$array_expected
=
array
(
'foo'
=>
'Drupal theme'
);
$entity_copy
=
clone
$entity
;
$entity_expected
=
clone
$entity
;
$entity_expected
->
foo
=
'Drupal theme'
;
$array2_copy
=
$array
;
$array2_expected
=
array
(
'foo'
=>
'Drupal theme'
);
drupal_alter
(
'drupal_alter'
,
$array_copy
,
$entity_copy
,
$array2_copy
);
$this
->
assertEqual
(
$array_copy
,
$array_expected
,
t
(
'First argument to drupal_alter() was altered.'
));
$this
->
assertEqual
(
$entity_copy
,
$entity_expected
,
t
(
'Second argument to drupal_alter() was altered.'
));
$this
->
assertEqual
(
$array2_copy
,
$array2_expected
,
t
(
'Third argument to drupal_alter() was altered.'
));
// Verify alteration order when passing an array of types to drupal_alter().
// common_test_module_implements_alter() places 'block' implementation after
// other modules.
$array_copy
=
$array
;
$array_expected
=
array
(
'foo'
=>
'Drupal block theme'
);
drupal_alter
(
array
(
'drupal_alter'
,
'drupal_alter_foo'
),
$array_copy
);
$this
->
assertEqual
(
$array_copy
,
$array_expected
,
t
(
'hook_TYPE_alter() implementations ran in correct order.'
));
}
}
core/modules/system/lib/Drupal/system/Tests/Common/ArrayUnitTest.php
0 → 100644
View file @
fbe34afe
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\ArrayUnitTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\UnitTestBase
;
/**
* Tests the various drupal_array_* helper functions.
*/
class
ArrayUnitTest
extends
UnitTestBase
{
/**
* Form array to check.
*/
protected
$form
;
/**
* Array of parents for the nested element.
*/
protected
$parents
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'drupal_array_*() tests'
,
'description'
=>
'Tests the various drupal_array_* helper functions.'
,
'group'
=>
'System'
,
);
}
function
setUp
()
{
parent
::
setUp
();
// Create a form structure with a nested element.
$this
->
form
[
'fieldset'
][
'element'
]
=
array
(
'#value'
=>
'Nested element'
,
);
// Set up parent array.
$this
->
parents
=
array
(
'fieldset'
,
'element'
);
}
/**
* Tests getting nested array values.
*/
function
testGet
()
{
// Verify getting a value of a nested element.
$value
=
drupal_array_get_nested_value
(
$this
->
form
,
$this
->
parents
);
$this
->
assertEqual
(
$value
[
'#value'
],
'Nested element'
,
'Nested element value found.'
);
// Verify changing a value of a nested element by reference.
$value
=
&
drupal_array_get_nested_value
(
$this
->
form
,
$this
->
parents
);
$value
[
'#value'
]
=
'New value'
;
$value
=
drupal_array_get_nested_value
(
$this
->
form
,
$this
->
parents
);
$this
->
assertEqual
(
$value
[
'#value'
],
'New value'
,
'Nested element value was changed by reference.'
);
$this
->
assertEqual
(
$this
->
form
[
'fieldset'
][
'element'
][
'#value'
],
'New value'
,
'Nested element value was changed by reference.'
);
// Verify that an existing key is reported back.
$key_exists
=
NULL
;
drupal_array_get_nested_value
(
$this
->
form
,
$this
->
parents
,
$key_exists
);
$this
->
assertIdentical
(
$key_exists
,
TRUE
,
'Existing key found.'
);
// Verify that a non-existing key is reported back and throws no errors.
$key_exists
=
NULL
;
$parents
=
$this
->
parents
;
$parents
[]
=
'foo'
;
drupal_array_get_nested_value
(
$this
->
form
,
$parents
,
$key_exists
);
$this
->
assertIdentical
(
$key_exists
,
FALSE
,
'Non-existing key not found.'
);
}
/**
* Tests setting nested array values.
*/
function
testSet
()
{
$new_value
=
array
(
'#value'
=>
'New value'
,
'#required'
=>
TRUE
,
);
// Verify setting the value of a nested element.
drupal_array_set_nested_value
(
$this
->
form
,
$this
->
parents
,
$new_value
);
$this
->
assertEqual
(
$this
->
form
[
'fieldset'
][
'element'
][
'#value'
],
'New value'
,
'Changed nested element value found.'
);
$this
->
assertIdentical
(
$this
->
form
[
'fieldset'
][
'element'
][
'#required'
],
TRUE
,
'New nested element value found.'
);
}
/**
* Tests unsetting nested array values.
*/
function
testUnset
()
{
// Verify unsetting a non-existing nested element throws no errors and the
// non-existing key is properly reported.
$key_existed
=
NULL
;
$parents
=
$this
->
parents
;
$parents
[]
=
'foo'
;
drupal_array_unset_nested_value
(
$this
->
form
,
$parents
,
$key_existed
);
$this
->
assertTrue
(
isset
(
$this
->
form
[
'fieldset'
][
'element'
][
'#value'
]),
'Outermost nested element key still exists.'
);
$this
->
assertIdentical
(
$key_existed
,
FALSE
,
'Non-existing key not found.'
);
// Verify unsetting a nested element.
$key_existed
=
NULL
;
drupal_array_unset_nested_value
(
$this
->
form
,
$this
->
parents
,
$key_existed
);
$this
->
assertFalse
(
isset
(
$this
->
form
[
'fieldset'
][
'element'
]),
'Removed nested element not found.'
);
$this
->
assertIdentical
(
$key_existed
,
TRUE
,
'Existing key was found.'
);
}
/**
* Tests existence of array key.
*/
function
testKeyExists
()
{
// Verify that existing key is found.
$this
->
assertIdentical
(
drupal_array_nested_key_exists
(
$this
->
form
,
$this
->
parents
),
TRUE
,
'Nested key found.'
);
// Verify that non-existing keys are not found.
$parents
=
$this
->
parents
;
$parents
[]
=
'foo'
;
$this
->
assertIdentical
(
drupal_array_nested_key_exists
(
$this
->
form
,
$parents
),
FALSE
,
'Non-existing nested key not found.'
);
}
}
core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php
0 → 100644
View file @
fbe34afe
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\AttributesUnitTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\UnitTestBase
;
/**
* Tests the drupal_attributes() functionality.
*/
class
AttributesUnitTest
extends
UnitTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'HTML Attributes'
,
'description'
=>
'Tests the drupal_attributes() functionality.'
,
'group'
=>
'Common'
,
);
}
/**
* Tests that drupal_html_class() cleans the class name properly.
*/
function
testDrupalAttributes
()
{
// Verify that special characters are HTML encoded.
$this
->
assertIdentical
(
drupal_attributes
(
array
(
'title'
=>
'&"\'<>'
)),
' title="&"'<>"'
,
t
(
'HTML encode attribute values.'
));
// Verify multi-value attributes are concatenated with spaces.
$attributes
=
array
(
'class'
=>
array
(
'first'
,
'last'
));
$this
->
assertIdentical
(
drupal_attributes
(
array
(
'class'
=>
array
(
'first'
,
'last'
))),
' class="first last"'
,
t
(
'Concatenate multi-value attributes.'
));
// Verify empty attribute values are rendered.
$this
->
assertIdentical
(
drupal_attributes
(
array
(
'alt'
=>
''
)),
' alt=""'
,
t
(
'Empty attribute value #1.'
));
$this
->
assertIdentical
(
drupal_attributes
(
array
(
'alt'
=>
NULL
)),
' alt=""'
,
t
(
'Empty attribute value #2.'
));
// Verify multiple attributes are rendered.
$attributes
=
array
(
'id'
=>
'id-test'
,
'class'
=>
array
(
'first'
,
'last'
),
'alt'
=>
'Alternate'
,
);
$this
->
assertIdentical
(
drupal_attributes
(
$attributes
),
' id="id-test" class="first last" alt="Alternate"'
,
t
(
'Multiple attributes.'
));
// Verify empty attributes array is rendered.
$this
->
assertIdentical
(
drupal_attributes
(
array
()),
''
,
t
(
'Empty attributes array.'
));
}
}
core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php
0 → 100644
View file @
fbe34afe
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\AutocompleteTagsUnitTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\UnitTestBase
;
/**
* Tests drupal_explode_tags() and drupal_implode_tags().
*/
class
AutocompleteTagsUnitTest
extends
UnitTestBase
{
var
$validTags
=
array
(
'Drupal'
=>
'Drupal'
,
'Drupal with some spaces'
=>
'Drupal with some spaces'
,
'"Legendary Drupal mascot of doom: ""Druplicon"""'
=>
'Legendary Drupal mascot of doom: "Druplicon"'
,
'"Drupal, although it rhymes with sloopal, is as awesome as a troopal!"'
=>
'Drupal, although it rhymes with sloopal, is as awesome as a troopal!'
,
);
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Autocomplete tags'
,
'description'
=>
'Tests explosion and implosion of autocomplete tags.'
,
'group'
=>
'Common'
,
);
}
/**
* Explode a series of tags.
*/
function
testDrupalExplodeTags
()
{
$string
=
implode
(
', '
,
array_keys
(
$this
->
validTags
));
$tags
=
drupal_explode_tags
(
$string
);
$this
->
assertTags
(
$tags
);
}
/**
* Implode a series of tags.
*/
function
testDrupalImplodeTags
()
{
$tags
=
array_values
(
$this
->
validTags
);
// Let's explode and implode to our heart's content.
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$string
=
drupal_implode_tags
(
$tags
);
$tags
=
drupal_explode_tags
(
$string
);
}
$this
->
assertTags
(
$tags
);
}
/**
* Helper function: asserts that the ending array of tags is what we wanted.
*/
function
assertTags
(
$tags
)
{
$original
=
$this
->
validTags
;
foreach
(
$tags
as
$tag
)
{
$key
=
array_search
(
$tag
,
$original
);
$this
->
assertTrue
(
$key
,
t
(
'Make sure tag %tag shows up in the final tags array (originally %original)'
,
array
(
'%tag'
=>
$tag
,
'%original'
=>
$key
)));
unset
(
$original
[
$key
]);
}
foreach
(
$original
as
$leftover
)
{
$this
->
fail
(
t
(
'Leftover tag %leftover was left over.'
,
array
(
'%leftover'
=>
$leftover
)));
}
}
}
core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php
0 → 100644
View file @
fbe34afe
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\CascadingStylesheetsTest.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\WebTestBase
;
/**
* Tests the Drupal CSS system.
*/
class
CascadingStylesheetsTest
extends
WebTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Cascading stylesheets'
,
'description'
=>
'Tests adding various cascading stylesheets to the page.'
,
'group'
=>
'Common'
,
);
}
function
setUp
()
{
parent
::
setUp
(
array
(
'language'
,
'common_test'
));
// Reset drupal_add_css() before each test.
drupal_static_reset
(
'drupal_add_css'
);
}
/**
* Check default stylesheets as empty.
*/
function
testDefault
()
{
$this
->
assertEqual
(
array
(),
drupal_add_css
(),
t
(
'Default CSS is empty.'
));
}
/**
* Test that stylesheets in module .info files are loaded.
*/
function
testModuleInfo
()
{
$this
->
drupalGet
(
''
);
// Verify common_test.css in a STYLE media="all" tag.
$elements
=
$this
->
xpath
(
'//style[@media=:media and contains(text(), :filename)]'
,
array
(
':media'
=>
'all'
,
':filename'
=>
'tests/modules/common_test/common_test.css'
,
));
$this
->
assertTrue
(
count
(
$elements
),
"Stylesheet with media 'all' in module .info file found."
);
// Verify common_test.print.css in a STYLE media="print" tag.
$elements
=
$this
->
xpath
(
'//style[@media=:media and contains(text(), :filename)]'
,
array
(
':media'
=>
'print'
,
':filename'
=>
'tests/modules/common_test/common_test.print.css'
,
));
$this
->
assertTrue
(
count
(
$elements
),
"Stylesheet with media 'print' in module .info file found."
);
}
/**
* Tests adding a file stylesheet.
*/
function
testAddFile
()
{
$path
=
drupal_get_path
(
'module'
,
'simpletest'
)
.
'/simpletest.css'
;
$css
=
drupal_add_css
(
$path
);
$this
->
assertEqual
(
$css
[
$path
][
'data'
],
$path
,
t
(
'Adding a CSS file caches it properly.'
));
}
/**
* Tests adding an external stylesheet.
*/
function
testAddExternal
()
{
$path
=
'http://example.com/style.css'
;
$css
=
drupal_add_css
(
$path
,
'external'
);
$this
->
assertEqual
(
$css
[
$path
][
'type'
],
'external'
,
t
(
'Adding an external CSS file caches it properly.'
));
}
/**
* Makes sure that reseting the CSS empties the cache.
*/
function
testReset
()
{
drupal_static_reset
(
'drupal_add_css'
);
$this
->
assertEqual
(
array
(),
drupal_add_css
(),
t
(
'Resetting the CSS empties the cache.'
));
}
/**
* Tests rendering the stylesheets.
*/
function
testRenderFile
()
{
$css
=
drupal_get_path
(
'module'
,
'simpletest'
)
.
'/simpletest.css'
;
drupal_add_css
(
$css
);
$styles
=
drupal_get_css
();
$this
->
assertTrue
(
strpos
(
$styles
,
$css
)
>
0
,
t
(
'Rendered CSS includes the added stylesheet.'
));
}
/**
* Tests rendering an external stylesheet.
*/
function
testRenderExternal
()
{
$css
=
'http://example.com/style.css'
;
drupal_add_css
(
$css
,
'external'
);
$styles
=
drupal_get_css
();
// Stylesheet URL may be the href of a LINK tag or in an @import statement
// of a STYLE tag.
$this
->
assertTrue
(
strpos
(
$styles
,
'href="'
.
$css
)
>
0
||
strpos
(
$styles
,
'@import url("'
.
$css
.
'")'
)
>
0
,
t
(
'Rendering an external CSS file.'
));
}
/**
* Tests rendering inline stylesheets with preprocessing on.
*/
function
testRenderInlinePreprocess
()
{
$css
=
'body { padding: 0px; }'
;
$css_preprocessed
=
'<style media="all">'
.
"
\n
<!--/*--><![CDATA[/*><!--*/
\n
"
.
drupal_load_stylesheet_content
(
$css
,
TRUE
)
.
"
\n
/*]]>*/-->
\n
"
.
'</style>'
;
drupal_add_css
(
$css
,
array
(
'type'
=>
'inline'
));
$styles
=
drupal_get_css
();
$this
->
assertEqual
(
trim
(
$styles
),
$css_preprocessed
,
t
(
'Rendering preprocessed inline CSS adds it to the page.'
));
}
/**
* Tests rendering inline stylesheets with preprocessing off.
*/
function
testRenderInlineNoPreprocess
()
{
$css
=
'body { padding: 0px; }'
;
drupal_add_css
(
$css
,
array
(
'type'
=>
'inline'
,
'preprocess'
=>
FALSE
));
$styles
=
drupal_get_css
();
$this
->
assertTrue
(
strpos
(
$styles
,
$css
)
>
0
,
t
(
'Rendering non-preprocessed inline CSS adds it to the page.'
));
}
/**
* Tests rendering inline stylesheets through a full page request.
*/
function
testRenderInlineFullPage
()
{
module_enable
(
array
(
'php'
));
$css
=
'body { font-size: 254px; }'
;
// Inline CSS is minified unless 'preprocess' => FALSE is passed as a
// drupal_add_css() option.
$expected
=
'body{font-size:254px;}'
;
// Create Basic page node type.
$this
->
drupalCreateContentType
(
array
(
'type'
=>
'page'
,
'name'
=>
'Basic page'
));
// Create a node, using the PHP filter that tests drupal_add_css().
$php_format_id
=
'php_code'
;
$settings
=
array
(
'type'
=>
'page'
,
'body'
=>
array
(
LANGUAGE_NOT_SPECIFIED
=>
array
(
array
(
'value'
=>
t
(
'This tests the inline CSS!'
)
.
"<?php drupal_add_css('
$css
', 'inline'); ?>"
,
'format'
=>
$php_format_id
,
),
),
),
'promote'
=>
1
,
);
$node
=
$this
->
drupalCreateNode
(
$settings
);
// Fetch the page.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertRaw
(
$expected
,
t
(
'Inline stylesheets appear in the full page rendering.'
));
}
/**
* Test CSS ordering.
*/
function
testRenderOrder
()
{
// A module CSS file.
drupal_add_css
(
drupal_get_path
(
'module'
,
'simpletest'
)
.
'/simpletest.css'
);