1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for css_injector.
|
6
|
*/
|
7
|
|
8
|
class CSSInjectorTest extends DrupalWebTestCase {
|
9
|
|
10
|
protected $privileged_user;
|
11
|
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => t('CSS Injector Functionality'),
|
15
|
'description' => t('CSS Injector Functionality.'),
|
16
|
'group' => 'CSS Injector',
|
17
|
);
|
18
|
}
|
19
|
function setUp() {
|
20
|
parent::setUp(array('css_injector', 'php'));
|
21
|
$privileged_user = $this->drupalCreateUser(array('administer css injection', 'use PHP for settings'));
|
22
|
$this->drupalLogin($privileged_user);
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* Test the Administrative UI, making sure it does what it ought to do.
|
27
|
*
|
28
|
* - Create 3 rules:
|
29
|
* - A basic rule that will appear on every page.
|
30
|
* - A basic rule that will appear on only one page.
|
31
|
*/
|
32
|
function testCSSInjectionUI() {
|
33
|
|
34
|
$base_url = 'admin/config/development/css-injector';
|
35
|
$add_url = $base_url . '/add';
|
36
|
|
37
|
// To add to these rules, just copy and paste.
|
38
|
$rules = array(
|
39
|
1 => array(
|
40
|
'crid' => 1,
|
41
|
'title' => t('Rule 1: pink background on all pages'),
|
42
|
'css_text' => '.content { background-color: pink; }',
|
43
|
'rule_type' => CSS_INJECTOR_PAGES_NOTLISTED, // add on every page except
|
44
|
'rule_conditions' => '', // no conditions
|
45
|
'pages_with' => array('user'), // Test page where it should show up.
|
46
|
'pages_without' => array(),
|
47
|
),
|
48
|
2 => array(
|
49
|
'crid' => 2,
|
50
|
'title' => t('Rule 2: blue background on admin page'),
|
51
|
'css_text' => '.content { background-color: blue; }',
|
52
|
'rule_type' => CSS_INJECTOR_PAGES_LISTED, // add on listed pages.
|
53
|
'rule_conditions' => 'user', // show only on /user
|
54
|
'pages_with' => array('user'), // Test page where it should show up.
|
55
|
'pages_without' => array(''), // front page
|
56
|
),
|
57
|
3 => array(
|
58
|
'crid' => 3,
|
59
|
'title' => t('Rule 3: blue background on admin page'),
|
60
|
'css_text' => '.content { background-color: green; }',
|
61
|
'rule_type' => CSS_INJECTOR_PHP, // add on listed pages.
|
62
|
'rule_conditions' => '<?php print (arg(0) == "admin"); ?>', // show only on /admin
|
63
|
'pages_with' => array('admin/config/development/css-injector'), // Test page where it should show up.
|
64
|
'pages_without' => array('user'), // front page should not have this one.
|
65
|
),
|
66
|
|
67
|
);
|
68
|
|
69
|
foreach ($rules as $index => $rule) {
|
70
|
// Create the rule.
|
71
|
$edit = array(
|
72
|
'title' => $rule['title'],
|
73
|
'css_text' => $rule['css_text'],
|
74
|
'rule_type' => $rule['rule_type'],
|
75
|
'rule_conditions' => $rule['rule_conditions'],
|
76
|
);
|
77
|
$this->drupalPost($add_url, $edit, t('Save'));
|
78
|
$this->assertRaw(t('Your CSS injection rule %rule was saved', array('%rule' => $rule['title'])));
|
79
|
$file = 'css_injector_' . $index . '.css';
|
80
|
|
81
|
// visit 'pages_with' to see if it's there.
|
82
|
foreach ($rule['pages_with'] as $page) {
|
83
|
$this->drupalGet($page);
|
84
|
$this->assertRaw($file, t('Rule %rule file %file was found on page %page', array('%rule' => $rule['crid'], '%file' => $file, '%page' => $page )));
|
85
|
}
|
86
|
// visit 'pages_without' and assert that the CSS is not there.
|
87
|
foreach ($rule['pages_without'] as $page) {
|
88
|
$this->drupalGet($page);
|
89
|
$this->assertNoRaw($file, t('Rule %rule file %file not found on page %page', array('%rule' => $rule['crid'], '%file' => $file, '%page' => $page )));
|
90
|
}
|
91
|
|
92
|
$buffer = file_get_contents(_css_injector_rule_uri($rule['crid']));
|
93
|
$this->assertIdentical($rule['css_text'], $buffer, t('The file being used has the contents expected'));
|
94
|
}
|
95
|
|
96
|
// Now delete each one and make sure that things work correctly.
|
97
|
foreach ($rules as $index => $rule) {
|
98
|
$delete_url = $base_url . '/delete/' . $index;
|
99
|
$this->drupalPost($delete_url, array(), t('Delete'));
|
100
|
$this->assertRaw(t('The CSS rule %rule has been deleted', array('%rule' => $rule['title'])));
|
101
|
|
102
|
// visit 'pages_with' to verify it's no longer there.
|
103
|
foreach ($rule['pages_with'] as $page) {
|
104
|
$this->drupalGet($page);
|
105
|
$this->assertNoRaw($file, t('Rule %rule file %file no longer found on page %page', array('%rule' => $rule['crid'], '%file' => $file, '%page' => $page )));
|
106
|
}
|
107
|
// visit 'pages_without' and assert that the CSS is not there either.
|
108
|
foreach ($rule['pages_without'] as $page) {
|
109
|
$this->drupalGet($page);
|
110
|
$this->assertNoRaw($file, t('Rule %rule file %file not found on page %page', array('%rule' => $rule['crid'], '%file' => $file, '%page' => $page )));
|
111
|
}
|
112
|
|
113
|
}
|
114
|
}
|
115
|
}
|