Projet

Général

Profil

Paste
Télécharger (25,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / theme.test @ 76597ebf

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for the theme API.
6
 */
7

    
8
/**
9
 * Unit tests for the Theme API.
10
 */
11
class ThemeTestCase extends DrupalWebTestCase {
12
  protected $profile = 'testing';
13

    
14
  public static function getInfo() {
15
    return array(
16
      'name' => 'Theme API',
17
      'description' => 'Test low-level theme functions.',
18
      'group' => 'Theme',
19
    );
20
  }
21

    
22
  function setUp() {
23
    parent::setUp('theme_test');
24
    theme_enable(array('test_theme'));
25
  }
26

    
27
  /**
28
   * Test function theme_get_suggestions() for SA-CORE-2009-003.
29
   */
30
  function testThemeSuggestions() {
31
    // Set the front page as something random otherwise the CLI
32
    // test runner fails.
33
    variable_set('site_frontpage', 'nobody-home');
34
    $args = array('node', '1', 'edit');
35
    $suggestions = theme_get_suggestions($args, 'page');
36
    $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1', 'page__node__edit'), 'Found expected node edit page suggestions');
37
    // Check attack vectors.
38
    $args = array('node', '\\1');
39
    $suggestions = theme_get_suggestions($args, 'page');
40
    $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid \\ from suggestions');
41
    $args = array('node', '1/');
42
    $suggestions = theme_get_suggestions($args, 'page');
43
    $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid / from suggestions');
44
    $args = array('node', "1\0");
45
    $suggestions = theme_get_suggestions($args, 'page');
46
    $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid \\0 from suggestions');
47
    // Define path with hyphens to be used to generate suggestions.
48
    $args = array('node', '1', 'hyphen-path');
49
    $result = array('page__node', 'page__node__%', 'page__node__1', 'page__node__hyphen_path');
50
    $suggestions = theme_get_suggestions($args, 'page');
51
    $this->assertEqual($suggestions, $result, 'Found expected page suggestions for paths containing hyphens.');
52
  }
53

    
54
  /**
55
   * Ensures preprocess functions run even for suggestion implementations.
56
   *
57
   * The theme hook used by this test has its base preprocess function in a
58
   * separate file, so this test also ensures that that file is correctly loaded
59
   * when needed.
60
   */
61
  function testPreprocessForSuggestions() {
62
    // Test with both an unprimed and primed theme registry.
63
    drupal_theme_rebuild();
64
    for ($i = 0; $i < 2; $i++) {
65
      $this->drupalGet('theme-test/suggestion');
66
      $this->assertText('Theme hook implementor=test_theme_theme_test__suggestion(). Foo=template_preprocess_theme_test', 'Theme hook suggestion ran with data available from a preprocess function for the base hook.');
67
    }
68
  }
69

    
70
  /**
71
   * Ensure page-front template suggestion is added when on front page.
72
   */
73
  function testFrontPageThemeSuggestion() {
74
    $q = $_GET['q'];
75
    // Set $_GET['q'] to node because theme_get_suggestions() will query it to
76
    // see if we are on the front page.
77
    $_GET['q'] = variable_get('site_frontpage', 'node');
78
    $suggestions = theme_get_suggestions(explode('/', $_GET['q']), 'page');
79
    // Set it back to not annoy the batch runner.
80
    $_GET['q'] = $q;
81
    $this->assertTrue(in_array('page__front', $suggestions), 'Front page template was suggested.');
82
  }
83

    
84
  /**
85
   * Ensures theme hook_*_alter() implementations can run before anything is rendered.
86
   */
87
  function testAlter() {
88
    $this->drupalGet('theme-test/alter');
89
    $this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', 'The theme was able to implement an alter hook during page building before anything was rendered.');
90
  }
91

    
92
  /**
93
   * Ensures a theme's .info file is able to override a module CSS file from being added to the page.
94
   *
95
   * @see test_theme.info
96
   */
97
  function testCSSOverride() {
98
    // Reuse the same page as in testPreprocessForSuggestions(). We're testing
99
    // what is output to the HTML HEAD based on what is in a theme's .info file,
100
    // so it doesn't matter what page we get, as long as it is themed with the
101
    // test theme. First we test with CSS aggregation disabled.
102
    variable_set('preprocess_css', 0);
103
    $this->drupalGet('theme-test/suggestion');
104
    $this->assertNoText('system.base.css', 'The theme\'s .info file is able to override a module CSS file from being added to the page.');
105

    
106
    // Also test with aggregation enabled, simply ensuring no PHP errors are
107
    // triggered during drupal_build_css_cache() when a source file doesn't
108
    // exist. Then allow remaining tests to continue with aggregation disabled
109
    // by default.
110
    variable_set('preprocess_css', 1);
111
    $this->drupalGet('theme-test/suggestion');
112
    variable_set('preprocess_css', 0);
113
  }
114

    
115
  /**
116
   * Ensures the theme registry is rebuilt when modules are disabled/enabled.
117
   */
118
  function testRegistryRebuild() {
119
    $this->assertIdentical(theme('theme_test_foo', array('foo' => 'a')), 'a', 'The theme registry contains theme_test_foo.');
120

    
121
    module_disable(array('theme_test'), FALSE);
122
    $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), '', 'The theme registry does not contain theme_test_foo, because the module is disabled.');
123

    
124
    module_enable(array('theme_test'), FALSE);
125
    $this->assertIdentical(theme('theme_test_foo', array('foo' => 'c')), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.');
126
  }
127

    
128
  /**
129
   * Test the list_themes() function.
130
   */
131
  function testListThemes() {
132
    $themes = list_themes();
133
    // Check if drupal_theme_access() retrieves enabled themes properly from list_themes().
134
    $this->assertTrue(drupal_theme_access('test_theme'), 'Enabled theme detected');
135
    // Check if list_themes() returns disabled themes.
136
    $this->assertTrue(array_key_exists('test_basetheme', $themes), 'Disabled theme detected');
137
    // Check for base theme and subtheme lists.
138
    $base_theme_list = array('test_basetheme' => 'Theme test base theme');
139
    $sub_theme_list = array('test_subtheme' => 'Theme test subtheme');
140
    $this->assertIdentical($themes['test_basetheme']->sub_themes, $sub_theme_list, 'Base theme\'s object includes list of subthemes.');
141
    $this->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, 'Subtheme\'s object includes list of base themes.');
142
    // Check for theme engine in subtheme.
143
    $this->assertIdentical($themes['test_subtheme']->engine, 'phptemplate', 'Subtheme\'s object includes the theme engine.');
144
    // Check for theme engine prefix.
145
    $this->assertIdentical($themes['test_basetheme']->prefix, 'phptemplate', 'Base theme\'s object includes the theme engine prefix.');
146
    $this->assertIdentical($themes['test_subtheme']->prefix, 'phptemplate', 'Subtheme\'s object includes the theme engine prefix.');
147
  }
148

    
149
  /**
150
   * Test the theme_get_setting() function.
151
   */
152
  function testThemeGetSetting() {
153
    $GLOBALS['theme_key'] = 'test_theme';
154
    $this->assertIdentical(theme_get_setting('theme_test_setting'), 'default value', 'theme_get_setting() uses the default theme automatically.');
155
    $this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), 'Base theme\'s default settings values can be overridden by subtheme.');
156
    $this->assertIdentical(theme_get_setting('basetheme_only', 'test_subtheme'), 'base theme value', 'Base theme\'s default settings values are inherited by subtheme.');
157
  }
158
}
159

    
160
/**
161
 * Unit tests for theme_table().
162
 */
163
class ThemeTableTestCase extends DrupalWebTestCase {
164
  public static function getInfo() {
165
    return array(
166
      'name' => 'Theme Table',
167
      'description' => 'Tests built-in theme functions.',
168
      'group' => 'Theme',
169
    );
170
  }
171

    
172
  /**
173
   * Tableheader.js provides 'sticky' table headers, and is included by default.
174
   */
175
  function testThemeTableStickyHeaders() {
176
    $header = array('one', 'two', 'three');
177
    $rows = array(array(1,2,3), array(4,5,6), array(7,8,9));
178
    $this->content = theme('table', array('header' => $header, 'rows' => $rows));
179
    $js = drupal_add_js();
180
    $this->assertTrue(isset($js['misc/tableheader.js']), 'tableheader.js was included when $sticky = TRUE.');
181
    $this->assertRaw('sticky-enabled', 'Table has a class of sticky-enabled when $sticky = TRUE.');
182
    drupal_static_reset('drupal_add_js');
183
  }
184

    
185
  /**
186
   * If $sticky is FALSE, no tableheader.js should be included.
187
   */
188
  function testThemeTableNoStickyHeaders() {
189
    $header = array('one', 'two', 'three');
190
    $rows = array(array(1,2,3), array(4,5,6), array(7,8,9));
191
    $attributes = array();
192
    $caption = NULL;
193
    $colgroups = array();
194
    $this->content = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes, 'caption' => $caption, 'colgroups' => $colgroups, 'sticky' => FALSE));
195
    $js = drupal_add_js();
196
    $this->assertFalse(isset($js['misc/tableheader.js']), 'tableheader.js was not included because $sticky = FALSE.');
197
    $this->assertNoRaw('sticky-enabled', 'Table does not have a class of sticky-enabled because $sticky = FALSE.');
198
    drupal_static_reset('drupal_add_js');
199
  }
200

    
201
  /**
202
   * Tests that the table header is printed correctly even if there are no rows,
203
   * and that the empty text is displayed correctly.
204
   */
205
  function testThemeTableWithEmptyMessage() {
206
    $header = array(
207
      t('Header 1'),
208
      array(
209
        'data' => t('Header 2'),
210
        'colspan' => 2,
211
      ),
212
    );
213
    $this->content = theme('table', array('header' => $header, 'rows' => array(), 'empty' => t('No strings available.')));
214
    $this->assertRaw('<tr class="odd"><td colspan="3" class="empty message">No strings available.</td>', 'Correct colspan was set on empty message.');
215
    $this->assertRaw('<thead><tr><th>Header 1</th>', 'Table header was printed.');
216
  }
217

    
218
  /**
219
   * Tests that the 'no_striping' option works correctly.
220
   */
221
  function testThemeTableWithNoStriping() {
222
    $rows = array(
223
      array(
224
        'data' => array(1),
225
        'no_striping' => TRUE,
226
      ),
227
    );
228
    $this->content = theme('table', array('rows' => $rows));
229
    $this->assertNoRaw('class="odd"', 'Odd/even classes were not added because $no_striping = TRUE.');
230
    $this->assertNoRaw('no_striping', 'No invalid no_striping HTML attribute was printed.');
231
  }
232
}
233

    
234
/**
235
 * Unit tests for theme_item_list().
236
 */
237
class ThemeItemListUnitTest extends DrupalWebTestCase {
238
  public static function getInfo() {
239
    return array(
240
      'name' => 'Theme item list',
241
      'description' => 'Test the theme_item_list() function.',
242
      'group' => 'Theme',
243
    );
244
  }
245

    
246
  /**
247
   * Test item list rendering.
248
   */
249
  function testItemList() {
250
    $items = array('a', array('data' => 'b', 'children' => array('c' => 'c', 'd' => 'd', 'e' => 'e')), 'f');
251
    $expected = '<div class="item-list"><ul><li class="first">a</li>
252
<li>b<div class="item-list"><ul><li class="first">c</li>
253
<li>d</li>
254
<li class="last">e</li>
255
</ul></div></li>
256
<li class="last">f</li>
257
</ul></div>';
258
    $output = theme('item_list', array('items' => $items));
259
    $this->assertIdentical($expected, $output, 'Item list is rendered correctly.');
260
  }
261
}
262

    
263
/**
264
 * Unit tests for theme_links().
265
 */
266
class ThemeLinksTest extends DrupalWebTestCase {
267
  public static function getInfo() {
268
    return array(
269
      'name' => 'Links',
270
      'description' => 'Test the theme_links() function and rendering groups of links.',
271
      'group' => 'Theme',
272
    );
273
  }
274

    
275
  /**
276
   * Test the use of drupal_pre_render_links() on a nested array of links.
277
   */
278
  function testDrupalPreRenderLinks() {
279
    // Define the base array to be rendered, containing a variety of different
280
    // kinds of links.
281
    $base_array = array(
282
      '#theme' => 'links',
283
      '#pre_render' => array('drupal_pre_render_links'),
284
      '#links' => array(
285
        'parent_link' => array(
286
          'title' => 'Parent link original',
287
          'href' => 'parent-link-original',
288
        ),
289
      ),
290
      'first_child' => array(
291
        '#theme' => 'links',
292
        '#links' => array(
293
          // This should be rendered if 'first_child' is rendered separately,
294
          // but ignored if the parent is being rendered (since it duplicates
295
          // one of the parent's links).
296
          'parent_link' => array(
297
            'title' => 'Parent link copy',
298
            'href' => 'parent-link-copy',
299
          ),
300
          // This should always be rendered.
301
          'first_child_link' => array(
302
            'title' => 'First child link',
303
            'href' => 'first-child-link',
304
          ),
305
        ),
306
      ),
307
      // This should always be rendered as part of the parent.
308
      'second_child' => array(
309
        '#theme' => 'links',
310
        '#links' => array(
311
          'second_child_link' => array(
312
            'title' => 'Second child link',
313
            'href' => 'second-child-link',
314
          ),
315
        ),
316
      ),
317
      // This should never be rendered, since the user does not have access to
318
      // it.
319
      'third_child' => array(
320
        '#theme' => 'links',
321
        '#links' => array(
322
          'third_child_link' => array(
323
            'title' => 'Third child link',
324
            'href' => 'third-child-link',
325
          ),
326
        ),
327
        '#access' => FALSE,
328
      ),
329
    );
330

    
331
    // Start with a fresh copy of the base array, and try rendering the entire
332
    // thing. We expect a single <ul> with appropriate links contained within
333
    // it.
334
    $render_array = $base_array;
335
    $html = drupal_render($render_array);
336
    $dom = new DOMDocument();
337
    $dom->loadHTML($html);
338
    $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered HTML.');
339
    $list_elements = $dom->getElementsByTagName('li');
340
    $this->assertEqual($list_elements->length, 3, 'Three "li" tags found in the rendered HTML.');
341
    $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
342
    $this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
343
    $this->assertEqual($list_elements->item(2)->nodeValue, 'Second child link', 'Third expected link found.');
344
    $this->assertIdentical(strpos($html, 'Parent link copy'), FALSE, '"Parent link copy" link not found.');
345
    $this->assertIdentical(strpos($html, 'Third child link'), FALSE, '"Third child link" link not found.');
346

    
347
    // Now render 'first_child', followed by the rest of the links, and make
348
    // sure we get two separate <ul>'s with the appropriate links contained
349
    // within each.
350
    $render_array = $base_array;
351
    $child_html = drupal_render($render_array['first_child']);
352
    $parent_html = drupal_render($render_array);
353
    // First check the child HTML.
354
    $dom = new DOMDocument();
355
    $dom->loadHTML($child_html);
356
    $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered child HTML.');
357
    $list_elements = $dom->getElementsByTagName('li');
358
    $this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered child HTML.');
359
    $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link copy', 'First expected link found.');
360
    $this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
361
    // Then check the parent HTML.
362
    $dom = new DOMDocument();
363
    $dom->loadHTML($parent_html);
364
    $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered parent HTML.');
365
    $list_elements = $dom->getElementsByTagName('li');
366
    $this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered parent HTML.');
367
    $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
368
    $this->assertEqual($list_elements->item(1)->nodeValue, 'Second child link', 'Second expected link found.');
369
    $this->assertIdentical(strpos($parent_html, 'First child link'), FALSE, '"First child link" link not found.');
370
    $this->assertIdentical(strpos($parent_html, 'Third child link'), FALSE, '"Third child link" link not found.');
371
  }
372
}
373

    
374
/**
375
 * Functional test for initialization of the theme system in hook_init().
376
 */
377
class ThemeHookInitTestCase extends DrupalWebTestCase {
378
  public static function getInfo() {
379
    return array(
380
      'name' => 'Theme initialization in hook_init()',
381
      'description' => 'Tests that the theme system can be correctly initialized in hook_init().',
382
      'group' => 'Theme',
383
    );
384
  }
385

    
386
  function setUp() {
387
    parent::setUp('theme_test');
388
  }
389

    
390
  /**
391
   * Test that the theme system can generate output when called by hook_init().
392
   */
393
  function testThemeInitializationHookInit() {
394
    $this->drupalGet('theme-test/hook-init');
395
    $this->assertRaw('Themed output generated in hook_init()', 'Themed output generated in hook_init() correctly appears on the page.');
396
    $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page when the theme system is initialized in hook_init().");
397
  }
398
}
399

    
400
/**
401
 * Tests autocompletion not loading registry.
402
 */
403
class ThemeFastTestCase extends DrupalWebTestCase {
404
  public static function getInfo() {
405
    return array(
406
      'name' => 'Theme fast initialization',
407
      'description' => 'Test that autocompletion does not load the registry.',
408
      'group' => 'Theme'
409
    );
410
  }
411

    
412
  function setUp() {
413
    parent::setUp('theme_test');
414
    $this->account = $this->drupalCreateUser(array('access user profiles'));
415
  }
416

    
417
  /**
418
   * Tests access to user autocompletion and verify the correct results.
419
   */
420
  function testUserAutocomplete() {
421
    $this->drupalLogin($this->account);
422
    $this->drupalGet('user/autocomplete/' . $this->account->name);
423
    $this->assertText('registry not initialized', 'The registry was not initialized');
424
  }
425
}
426

    
427
/**
428
 * Tests the markup of core render element types passed to drupal_render().
429
 */
430
class RenderElementTypesTestCase extends DrupalWebTestCase {
431
  public static function getInfo() {
432
    return array(
433
      'name' => 'Render element types',
434
      'description' => 'Tests the markup of core render element types passed to drupal_render().',
435
      'group' => 'Theme',
436
    );
437
  }
438

    
439
  /**
440
   * Asserts that an array of elements is rendered properly.
441
   *
442
   * @param array $elements
443
   *   An array of associative arrays describing render elements and their
444
   *   expected markup. Each item in $elements must contain the following:
445
   *   - 'name': This human readable description will be displayed on the test
446
   *     results page.
447
   *   - 'value': This is the render element to test.
448
   *   - 'expected': This is the expected markup for the element in 'value'.
449
   */
450
  function assertElements($elements) {
451
    foreach($elements as $element) {
452
      $this->assertIdentical(drupal_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by drupal_render().');
453
    }
454
  }
455

    
456
  /**
457
   * Tests system #type 'container'.
458
   */
459
  function testContainer() {
460
    $elements = array(
461
      // Basic container with no attributes.
462
      array(
463
        'name' => "#type 'container' with no HTML attributes",
464
        'value' => array(
465
          '#type' => 'container',
466
          'child' => array(
467
            '#markup' => 'foo',
468
          ),
469
        ),
470
        'expected' => '<div>foo</div>',
471
      ),
472
      // Container with a class.
473
      array(
474
        'name' => "#type 'container' with a class HTML attribute",
475
        'value' => array(
476
          '#type' => 'container',
477
          'child' => array(
478
            '#markup' => 'foo',
479
          ),
480
          '#attributes' => array(
481
            'class' => 'bar',
482
          ),
483
        ),
484
        'expected' => '<div class="bar">foo</div>',
485
      ),
486
    );
487

    
488
    $this->assertElements($elements);
489
  }
490

    
491
  /**
492
   * Tests system #type 'html_tag'.
493
   */
494
  function testHtmlTag() {
495
    $elements = array(
496
      // Test auto-closure meta tag generation.
497
      array(
498
        'name' => "#type 'html_tag' auto-closure meta tag generation",
499
        'value' => array(
500
          '#type' => 'html_tag',
501
          '#tag' => 'meta',
502
          '#attributes' => array(
503
            'name' => 'description',
504
            'content' => 'Drupal test',
505
          ),
506
        ),
507
        'expected' => '<meta name="description" content="Drupal test" />' . "\n",
508
      ),
509
      // Test title tag generation.
510
      array(
511
        'name' => "#type 'html_tag' title tag generation",
512
        'value' => array(
513
          '#type' => 'html_tag',
514
          '#tag' => 'title',
515
          '#value' => 'title test',
516
        ),
517
        'expected' => '<title>title test</title>' . "\n",
518
      ),
519
    );
520

    
521
    $this->assertElements($elements);
522
  }
523
}
524

    
525
/**
526
 * Tests for the ThemeRegistry class.
527
 */
528
class ThemeRegistryTestCase extends DrupalWebTestCase {
529
  public static function getInfo() {
530
    return array(
531
      'name' => 'ThemeRegistry',
532
      'description' => 'Tests the behavior of the ThemeRegistry class',
533
      'group' => 'Theme',
534
    );
535
  }
536
  function setUp() {
537
    parent::setUp('theme_test');
538
  }
539

    
540
  /**
541
   * Tests the behavior of the theme registry class.
542
   */
543
  function testRaceCondition() {
544
    $_SERVER['REQUEST_METHOD'] = 'GET';
545
    $cid = 'test_theme_registry';
546

    
547
    // Directly instantiate the theme registry, this will cause a base cache
548
    // entry to be written in __construct().
549
    $registry = new ThemeRegistry($cid, 'cache');
550

    
551
    $this->assertTrue(cache_get($cid), 'Cache entry was created.');
552

    
553
    // Trigger a cache miss for an offset.
554
    $this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry.');
555
    // This will cause the ThemeRegistry class to write an updated version of
556
    // the cache entry when it is destroyed, usually at the end of the request.
557
    // Before that happens, manually delete the cache entry we created earlier
558
    // so that the new entry is written from scratch.
559
    cache_clear_all($cid, 'cache');
560

    
561
    // Destroy the class so that it triggers a cache write for the offset.
562
    unset($registry);
563

    
564
    $this->assertTrue(cache_get($cid), 'Cache entry was created.');
565

    
566
    // Create a new instance of the class. Confirm that both the offset
567
    // requested previously, and one that has not yet been requested are both
568
    // available.
569
    $registry = new ThemeRegistry($cid, 'cache');
570

    
571
    $this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry');
572
    $this->assertTrue($registry['theme_test_template_test_2'], 'Offset was returned correctly from the theme registry');
573
  }
574
}
575

    
576
/**
577
 * Tests for theme debug markup.
578
 */
579
class ThemeDebugMarkupTestCase extends DrupalWebTestCase {
580

    
581
  public static function getInfo() {
582
    return array(
583
      'name' => 'Theme debug markup',
584
      'description' => 'Tests theme debug markup output.',
585
      'group' => 'Theme',
586
    );
587
  }
588

    
589
  function setUp() {
590
    parent::setUp('theme_test', 'node');
591
    theme_enable(array('test_theme'));
592
  }
593

    
594
  /**
595
   * Tests debug markup added to template output.
596
   */
597
  function testDebugOutput() {
598
    variable_set('theme_default', 'test_theme');
599
    // Enable the debug output.
600
    variable_set('theme_debug', TRUE);
601

    
602
    $registry = theme_get_registry();
603
    $extension = '.tpl.php';
604
    // Populate array of templates.
605
    $templates = drupal_find_theme_templates($registry, $extension, drupal_get_path('theme', 'test_theme'));
606
    $templates += drupal_find_theme_templates($registry, $extension, drupal_get_path('module', 'node'));
607

    
608
    // Create a node and test different features of the debug markup.
609
    $node = $this->drupalCreateNode();
610
    $this->drupalGet('node/' . $node->nid);
611
    $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
612
    $this->assertRaw("CALL: theme('node')", 'Theme call information found.');
613
    $this->assertRaw('x node--1' . $extension . PHP_EOL . '   * node--page' . $extension . PHP_EOL . '   * node' . $extension, 'Suggested template files found in order and node ID specific template shown as current template.');
614
    $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension;
615
    $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
616

    
617
    // Create another node and make sure the template suggestions shown in the
618
    // debug markup are correct.
619
    $node2 = $this->drupalCreateNode();
620
    $this->drupalGet('node/' . $node2->nid);
621
    $this->assertRaw('* node--2' . $extension . PHP_EOL . '   * node--page' . $extension . PHP_EOL . '   x node' . $extension, 'Suggested template files found in order and base template shown as current template.');
622

    
623
    // Create another node and make sure the template suggestions shown in the
624
    // debug markup are correct.
625
    $node3 = $this->drupalCreateNode();
626
    $build = array('#theme' => 'node__foo__bar');
627
    $build += node_view($node3);
628
    $output = drupal_render($build);
629
    $this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.');
630
    $this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . '   * node--foo' . $extension . PHP_EOL . '   * node--3' . $extension . PHP_EOL . '   * node--page' . $extension . PHP_EOL . '   x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
631

    
632
    // Disable theme debug.
633
    variable_set('theme_debug', FALSE);
634

    
635
    $this->drupalGet('node/' . $node->nid);
636
    $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
637
  }
638

    
639
}