Projet

Général

Profil

Paste
Télécharger (11,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / sweaver / tests / sweaver.editor.test @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 * Basic tests for sweaver frontend editor.
6
 */
7

    
8
class sweaverEditor extends DrupalWebTestCase {
9
  /**
10
   * Implementation of getInfo().
11
   */
12
  public static function getInfo() {
13
    return array(
14
      'name' => t('Sweaver editor'),
15
      'description' => t('Tests for the frontend editor.'),
16
      'group' => t('Sweaver'),
17
    );
18
  }
19

    
20
  /**
21
   * Implementation of setUp().
22
   */
23
  function setUp() {
24
    parent::setUp('ctools', 'sweaver');
25
    $this->admin_user = $this->drupalCreateUser(array('use editor', 'configure sweaver'));
26
    $this->drupalLogin($this->admin_user);
27
  }
28

    
29
  /**
30
   * Debug helper function. Writes values away to a text file in the files directory.
31
   */
32
  function _debugHelper($value, $writetype = 'a+') {
33
    $debug = fopen($this->originalFileDirectory .'/simpletestdebug.txt', 'a+');
34
    fwrite($debug, print_r($value, TRUE) ."\n");
35
    fclose($debug);
36
  }
37

    
38
  /**
39
   * Return public path helper function.
40
   */
41
  function sweaver_public_path() {
42
    return variable_get('file_public_path', conf_path() . '/files');
43
  }
44

    
45
  /**
46
   * Test frontend editor.
47
   */
48
  function testFrontendEditor() {
49
    variable_set('sweaver_styles_delete_tab', TRUE);
50
    variable_set('sweaver_plugin_status_sweaver_plugin_themeswitch', TRUE);
51
    drupal_flush_all_caches();
52

    
53
    $editor_tests = t('Editor testing');
54

    
55
    // Enable minelli.
56
    db_query("UPDATE {system} set status = 1 where type = 'theme' AND name = 'garland'");
57

    
58
    // Assert custom css plugin is disabled.
59
    $this->drupalGet('user');
60
    $this->assertNoRaw('Custom css', t('Custom css tab not found'), $editor_tests);
61

    
62
    // Enable custom css plugin.
63
    $edit = array(
64
      'sweaver_plugin_customcss[status]' => 1,
65
    );
66
    $this->drupalPost('admin/config/user-interface/sweaver/plugins', $edit, t('Save configuration'));
67
    $this->assertRaw('The configuration options have been saved.', t('Plugins have been saved'), $editor_tests);
68
    $this->drupalGet('user');
69
    $this->assertRaw('Custom css', t('Custom css tab found'), $editor_tests);
70

    
71
    // Switch to minnelli.
72
    $this->assertNoRaw('sweaver_themeswitch/bartik', t('Can not switch to bartik'), $editor_tests);
73
    $this->drupalGet('sweaver_themeswitch/garland');
74
    $this->assertRaw(t('You have switched to Garland.'), t('Switch to garland success.'), $editor_tests);
75

    
76
    // Switch back to bartik.
77
    $this->assertNoRaw('sweaver_themeswitch/garland', t('Can not switch to garland'), $editor_tests);
78
    $this->drupalGet('sweaver_themeswitch/bartik');
79
    $this->assertRaw(t('You have switched to Bartik.'), t('Switch to bartik success.'), $editor_tests);
80

    
81
    // Set some styling for bartik.
82
    $edit = array(
83
      'sweaver-css' => '{"#center ":{"font-size":30}}',
84
      'css-rendered' => '<style type="text/css">#center { font-size: 30px; } </style>',
85
      'sweaver_plugin_custom_css' => '#header { background-color: blue; }',
86
      'save_style' => 'Bartik 1',
87
    );
88

    
89
    // Save style and assert it's saved and we can keep working on it. The draft file should be saved, the live file not.
90
    $this->drupalPost('node', $edit, t('Save and continue'));
91
    $this->assertRaw(t('The style Bartik 1 has been saved. You can keep working on your style.'), t('Style has been saved'), $editor_tests);
92
    $css = db_query("SELECT * FROM {sweaver_style_draft} where style_id = 1 AND theme = 'bartik'")->fetchObject();
93
    $this->assertEqual($edit['sweaver-css'], $css->css, t('Css has been saved'), $editor_tests);
94
    $this->assertEqual($edit['sweaver_plugin_custom_css'], $css->customcss, t('Custom css saved'), $editor_tests);
95
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_draft.css'), 'Draft filename written', $editor_tests);
96
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_live.css'), 'Live filename not written', $editor_tests);
97
    $this->assertNoRaw('sweaver/sweaver_bartik_'. $css->style_id .'_draft.css', t('The style Bartik 1 has not been loaded in the HTML.'), $editor_tests);
98

    
99
    // Set styling for bartik 2.
100
    $edit = array(
101
      'sweaver-css' => '{"#center ":{"font-size":40}}',
102
      'css-rendered' => '<style type="text/css">#center { font-size: 40px; } </style>',
103
      'sweaver_plugin_custom_css' => '#header { background-color: red; }',
104
      'save_style' => 'Bartik 2',
105
      'save_type' => '0',
106
    );
107

    
108
    // Save style and assert it's saved. We'll look for the message, the entry
109
    // into the database and the css file in the sweaver directory.
110
    $this->drupalPost('node', $edit, t('Save and continue'));
111
    $this->assertRaw(t('The style Bartik 2 has been saved. You can keep working on your style.'), t('Style has been saved'), $editor_tests);
112
    $css = db_query("SELECT * FROM {sweaver_style_draft} where style_id = 2 AND theme = 'bartik'")->fetchObject();
113
    $this->assertEqual($edit['sweaver-css'], $css->css, t('Css has been saved'), $editor_tests);
114
    $this->assertEqual($edit['sweaver_plugin_custom_css'], $css->customcss, t('Custom css saved'), $editor_tests);
115
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_draft.css'), 'Draft filename written', $editor_tests);
116
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_live.css'), 'Live filename not written', $editor_tests);
117
    $this->assertNoRaw('sweaver/sweaver_bartik_'. $css->style_id .'_draft.css', t('The style Bartik 2 has not been loaded in the HTML.'), $editor_tests);
118
    $this->assertEqual($css->style_id, 2, t('New style saved in database with id 2'), $editor_tests);
119

    
120
    // Load style.
121
    $edit = array(
122
      'load_style' => 1,
123
    );
124
    $this->drupalPost('user', $edit, t('Load style'));
125
    $this->assertRaw(t('The style Bartik 1 has been loaded. It is only visible for you.'), t('Style loaded'), $editor_tests);
126
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_1_live.css'), 'Live filename not written', $editor_tests);
127

    
128
    // Publish style.
129
    $this->drupalPost('user', $edit, t('Publish style'));
130
    $this->assertRaw(t('The style Bartik 1 has been published.'), t('Style published'), $editor_tests);
131
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_1_live.css'), 'Live filename written', $editor_tests);
132

    
133
    // Delete styles
134
    $edit = array(
135
      'delete_style' => 1,
136
    );
137
    $this->drupalPost('user', $edit, t('Delete style'));
138
    $this->assertRaw(t('The style Bartik 1 has been deleted.'), t('Style deleted'), $editor_tests);
139
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_1_draft.css'), 'Draft filename gone', $editor_tests);
140
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_1_live.css'), 'Live filename gone', $editor_tests);
141

    
142
    // Assert we don't see the publish button.
143
    $this->assertNoRaw('<h2>Publish style</h2>', t('Publish button not found.'));
144

    
145
    $edit = array(
146
      'delete_style' => 2,
147
    );
148
    $this->drupalPost('user', $edit, t('Delete style'));
149
    $this->assertRaw(t('The style Bartik 2 has been deleted.'), t('Delete style'), $editor_tests);
150
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_2_draft.css'), 'Draft filename gone', $editor_tests);
151
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_2_live.css'), 'Live filename gone', $editor_tests);
152

    
153
    // Set styling for bartik 3.
154
    $edit = array(
155
      'sweaver-css' => '{"#center ":{"font-size":40}}',
156
      'css-rendered' => '<style type="text/css">#center { font-size: 40px; } </style>',
157
      'sweaver_plugin_custom_css' => '#header { background-color: red; }',
158
      'save_style' => 'Bartik 3',
159
    );
160

    
161
    // Save style and assert it's saved. We'll look for the message, the entry
162
    // into the database and the css file in the sweaver directory.
163
    $this->drupalPost('node', $edit, t('Save and continue'));
164
    $this->assertRaw(t('The style Bartik 3 has been saved. You can keep working on your style.'), t('Style has been saved'), $editor_tests);
165
    $css = db_query("SELECT * FROM {sweaver_style_draft} where style_id = 3 AND theme = 'bartik'")->fetchObject();
166
    $this->assertEqual($edit['sweaver-css'], $css->css, t('Css has been saved'), $editor_tests);
167
    $this->assertEqual($edit['sweaver_plugin_custom_css'], $css->customcss, t('Custom css saved'), $editor_tests);
168
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_draft.css'), 'Draft filename written', $editor_tests);
169
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_live.css'), 'Live filename not written', $editor_tests);
170
    $this->assertNoRaw('sweaver/sweaver_bartik_'. $css->style_id .'_draft.css', t('The style Bartik 3 has not been loaded in the HTML.'), $editor_tests);
171
    $this->assertEqual($css->style_id, 3, t('New style saved in database with id 3'), $editor_tests);
172

    
173
    // Load style.
174
    $edit = array(
175
      'load_style' => 3,
176
    );
177
    $this->drupalPost('user', $edit, t('Load style'));
178
    $this->assertRaw(t('The style Bartik 3 has been loaded. It is only visible for you.'), t('Style loaded'), $editor_tests);
179
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_3_live.css'), 'Live filename not written', $editor_tests);
180

    
181
    // Assert we see the publish button.
182
    $this->assertRaw('<h2>Publish style</h2>', t('Publish button found.'));
183

    
184
    // Resave this style as Bartik 4.
185
    $edit = array(
186
      'sweaver-css' => '{"#center ":{"font-size":30}}',
187
      'css-rendered' => '<style type="text/css">#center { font-size: 30px; } </style>',
188
      'sweaver_plugin_custom_css' => '#header { background-color: blue; }',
189
      'save_style' => 'Bartik 4',
190
      'save_type' => '0',
191
    );
192
    $this->drupalPost('node', $edit, t('Save and continue'));
193
    $this->assertRaw(t('The style Bartik 4 has been saved. You can keep working on your style.'), t('New styles saved and working in draft.'), $editor_tests);
194
    $css = db_query("SELECT * FROM {sweaver_style_draft} where style_id = 4 AND theme = 'bartik'")->fetchObject();
195
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_draft.css'), 'Draft filename written', $editor_tests);
196
    $this->assertFalse(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_live.css'), 'Live filename written', $editor_tests);
197
    $this->assertEqual($css->style_id, 4, t('New style saved in database with id 4'), $editor_tests);
198

    
199
    // Save and publish button style.
200
    $edit = array(
201
      'sweaver-css' => '{"#center ":{"font-size":30}}',
202
      'css-rendered' => '<style type="text/css">#center { font-size: 30px; } </style>',
203
      'sweaver_plugin_custom_css' => '#header { background-color: blue; }',
204
      'save_style' => 'Bartik 5',
205
      'save_type' => '0',
206
    );
207
    $this->drupalPost('node', $edit, t('Save and publish'));
208
    $this->assertRaw(t('The style Bartik 5 has been saved and published. You can keep working on your style.'), t('New styles saved and published.'), $editor_tests);
209
    $css = db_query("SELECT * FROM {sweaver_style_draft} where style_id = 5 AND theme = 'bartik'")->fetchObject();
210
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_draft.css'), 'Draft filename written', $editor_tests);
211
    $this->assertTrue(file_exists($this->sweaver_public_path() .'/sweaver/sweaver_bartik_'. $css->style_id .'_live.css'), 'Live filename written', $editor_tests);
212
    $this->assertEqual($css->style_id, 5, t('New style saved and published in database with id 5'), $editor_tests);
213
  }
214
}