Projet

Général

Profil

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

root / drupal7 / modules / simpletest / tests / theme.test @ 27e02aed

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
   * Test the drupal_add_region_content() function.
161
   */
162
  function testDrupalAddRegionContent() {
163
    $this->drupalGet('theme-test/drupal-add-region-content');
164
    $this->assertText('Hello');
165
    $this->assertText('World');
166
  }
167
}
168

    
169
/**
170
 * Unit tests for theme_table().
171
 */
172
class ThemeTableTestCase extends DrupalWebTestCase {
173
  public static function getInfo() {
174
    return array(
175
      'name' => 'Theme Table',
176
      'description' => 'Tests built-in theme functions.',
177
      'group' => 'Theme',
178
    );
179
  }
180

    
181
  /**
182
   * Tableheader.js provides 'sticky' table headers, and is included by default.
183
   */
184
  function testThemeTableStickyHeaders() {
185
    $header = array('one', 'two', 'three');
186
    $rows = array(array(1,2,3), array(4,5,6), array(7,8,9));
187
    $this->content = theme('table', array('header' => $header, 'rows' => $rows));
188
    $js = drupal_add_js();
189
    $this->assertTrue(isset($js['misc/tableheader.js']), 'tableheader.js was included when $sticky = TRUE.');
190
    $this->assertRaw('sticky-enabled', 'Table has a class of sticky-enabled when $sticky = TRUE.');
191
    drupal_static_reset('drupal_add_js');
192
  }
193

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

    
210
  /**
211
   * Tests that the table header is printed correctly even if there are no rows,
212
   * and that the empty text is displayed correctly.
213
   */
214
  function testThemeTableWithEmptyMessage() {
215
    $header = array(
216
      t('Header 1'),
217
      array(
218
        'data' => t('Header 2'),
219
        'colspan' => 2,
220
      ),
221
    );
222
    $this->content = theme('table', array('header' => $header, 'rows' => array(), 'empty' => t('No strings available.')));
223
    $this->assertRaw('<tr class="odd"><td colspan="3" class="empty message">No strings available.</td>', 'Correct colspan was set on empty message.');
224
    $this->assertRaw('<thead><tr><th>Header 1</th>', 'Table header was printed.');
225
  }
226

    
227
  /**
228
   * Tests that the 'no_striping' option works correctly.
229
   */
230
  function testThemeTableWithNoStriping() {
231
    $rows = array(
232
      array(
233
        'data' => array(1),
234
        'no_striping' => TRUE,
235
      ),
236
    );
237
    $this->content = theme('table', array('rows' => $rows));
238
    $this->assertNoRaw('class="odd"', 'Odd/even classes were not added because $no_striping = TRUE.');
239
    $this->assertNoRaw('no_striping', 'No invalid no_striping HTML attribute was printed.');
240
  }
241

    
242
  /**
243
   * Test that the 'footer' option works correctly.
244
   */
245
  function testThemeTableFooter() {
246
    $footer = array(
247
      array(
248
        'data' => array(1),
249
      ),
250
      array('Foo'),
251
    );
252

    
253
    $table = array(
254
      'rows' => array(),
255
      'footer' => $footer,
256
    );
257

    
258
    $this->content = theme('table', $table);
259
    $this->content = preg_replace('@>\s+<@', '><', $this->content);
260
    $this->assertRaw('<tfoot><tr><td>1</td></tr><tr><td>Foo</td></tr></tfoot>', 'Table footer found.');
261
  }
262
}
263

    
264
/**
265
 * Unit tests for theme_item_list().
266
 */
267
class ThemeItemListUnitTest extends DrupalWebTestCase {
268
  public static function getInfo() {
269
    return array(
270
      'name' => 'Theme item list',
271
      'description' => 'Test the theme_item_list() function.',
272
      'group' => 'Theme',
273
    );
274
  }
275

    
276
  /**
277
   * Test item list rendering.
278
   */
279
  function testItemList() {
280
    $items = array('a', array('data' => 'b', 'children' => array('c' => 'c', 'd' => 'd', 'e' => 'e')), 'f');
281
    $expected = '<div class="item-list"><ul><li class="first">a</li>
282
<li>b<div class="item-list"><ul><li class="first">c</li>
283
<li>d</li>
284
<li class="last">e</li>
285
</ul></div></li>
286
<li class="last">f</li>
287
</ul></div>';
288
    $output = theme('item_list', array('items' => $items));
289
    $this->assertIdentical($expected, $output, 'Item list is rendered correctly.');
290
  }
291
}
292

    
293
/**
294
 * Unit tests for theme_links().
295
 */
296
class ThemeLinksTest extends DrupalWebTestCase {
297
  public static function getInfo() {
298
    return array(
299
      'name' => 'Links',
300
      'description' => 'Test the theme_links() function and rendering groups of links.',
301
      'group' => 'Theme',
302
    );
303
  }
304

    
305
  /**
306
   * Test the use of drupal_pre_render_links() on a nested array of links.
307
   */
308
  function testDrupalPreRenderLinks() {
309
    // Define the base array to be rendered, containing a variety of different
310
    // kinds of links.
311
    $base_array = array(
312
      '#theme' => 'links',
313
      '#pre_render' => array('drupal_pre_render_links'),
314
      '#links' => array(
315
        'parent_link' => array(
316
          'title' => 'Parent link original',
317
          'href' => 'parent-link-original',
318
        ),
319
      ),
320
      'first_child' => array(
321
        '#theme' => 'links',
322
        '#links' => array(
323
          // This should be rendered if 'first_child' is rendered separately,
324
          // but ignored if the parent is being rendered (since it duplicates
325
          // one of the parent's links).
326
          'parent_link' => array(
327
            'title' => 'Parent link copy',
328
            'href' => 'parent-link-copy',
329
          ),
330
          // This should always be rendered.
331
          'first_child_link' => array(
332
            'title' => 'First child link',
333
            'href' => 'first-child-link',
334
          ),
335
        ),
336
      ),
337
      // This should always be rendered as part of the parent.
338
      'second_child' => array(
339
        '#theme' => 'links',
340
        '#links' => array(
341
          'second_child_link' => array(
342
            'title' => 'Second child link',
343
            'href' => 'second-child-link',
344
          ),
345
        ),
346
      ),
347
      // This should never be rendered, since the user does not have access to
348
      // it.
349
      'third_child' => array(
350
        '#theme' => 'links',
351
        '#links' => array(
352
          'third_child_link' => array(
353
            'title' => 'Third child link',
354
            'href' => 'third-child-link',
355
          ),
356
        ),
357
        '#access' => FALSE,
358
      ),
359
    );
360

    
361
    // Start with a fresh copy of the base array, and try rendering the entire
362
    // thing. We expect a single <ul> with appropriate links contained within
363
    // it.
364
    $render_array = $base_array;
365
    $html = drupal_render($render_array);
366
    $dom = new DOMDocument();
367
    $dom->loadHTML($html);
368
    $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered HTML.');
369
    $list_elements = $dom->getElementsByTagName('li');
370
    $this->assertEqual($list_elements->length, 3, 'Three "li" tags found in the rendered HTML.');
371
    $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
372
    $this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
373
    $this->assertEqual($list_elements->item(2)->nodeValue, 'Second child link', 'Third expected link found.');
374
    $this->assertIdentical(strpos($html, 'Parent link copy'), FALSE, '"Parent link copy" link not found.');
375
    $this->assertIdentical(strpos($html, 'Third child link'), FALSE, '"Third child link" link not found.');
376

    
377
    // Now render 'first_child', followed by the rest of the links, and make
378
    // sure we get two separate <ul>'s with the appropriate links contained
379
    // within each.
380
    $render_array = $base_array;
381
    $child_html = drupal_render($render_array['first_child']);
382
    $parent_html = drupal_render($render_array);
383
    // First check the child HTML.
384
    $dom = new DOMDocument();
385
    $dom->loadHTML($child_html);
386
    $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered child HTML.');
387
    $list_elements = $dom->getElementsByTagName('li');
388
    $this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered child HTML.');
389
    $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link copy', 'First expected link found.');
390
    $this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
391
    // Then check the parent HTML.
392
    $dom = new DOMDocument();
393
    $dom->loadHTML($parent_html);
394
    $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered parent HTML.');
395
    $list_elements = $dom->getElementsByTagName('li');
396
    $this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered parent HTML.');
397
    $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
398
    $this->assertEqual($list_elements->item(1)->nodeValue, 'Second child link', 'Second expected link found.');
399
    $this->assertIdentical(strpos($parent_html, 'First child link'), FALSE, '"First child link" link not found.');
400
    $this->assertIdentical(strpos($parent_html, 'Third child link'), FALSE, '"Third child link" link not found.');
401
  }
402
}
403

    
404
/**
405
 * Functional test for initialization of the theme system in hook_init().
406
 */
407
class ThemeHookInitTestCase extends DrupalWebTestCase {
408
  public static function getInfo() {
409
    return array(
410
      'name' => 'Theme initialization in hook_init()',
411
      'description' => 'Tests that the theme system can be correctly initialized in hook_init().',
412
      'group' => 'Theme',
413
    );
414
  }
415

    
416
  function setUp() {
417
    parent::setUp('theme_test');
418
  }
419

    
420
  /**
421
   * Test that the theme system can generate output when called by hook_init().
422
   */
423
  function testThemeInitializationHookInit() {
424
    $this->drupalGet('theme-test/hook-init');
425
    $this->assertRaw('Themed output generated in hook_init()', 'Themed output generated in hook_init() correctly appears on the page.');
426
    $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page when the theme system is initialized in hook_init().");
427
  }
428
}
429

    
430
/**
431
 * Tests autocompletion not loading registry.
432
 */
433
class ThemeFastTestCase extends DrupalWebTestCase {
434
  public static function getInfo() {
435
    return array(
436
      'name' => 'Theme fast initialization',
437
      'description' => 'Test that autocompletion does not load the registry.',
438
      'group' => 'Theme'
439
    );
440
  }
441

    
442
  function setUp() {
443
    parent::setUp('theme_test');
444
    $this->account = $this->drupalCreateUser(array('access user profiles'));
445
  }
446

    
447
  /**
448
   * Tests access to user autocompletion and verify the correct results.
449
   */
450
  function testUserAutocomplete() {
451
    $this->drupalLogin($this->account);
452
    $this->drupalGet('user/autocomplete/' . $this->account->name);
453
    $this->assertText('registry not initialized', 'The registry was not initialized');
454
  }
455
}
456

    
457
/**
458
 * Tests the markup of core render element types passed to drupal_render().
459
 */
460
class RenderElementTypesTestCase extends DrupalWebTestCase {
461
  public static function getInfo() {
462
    return array(
463
      'name' => 'Render element types',
464
      'description' => 'Tests the markup of core render element types passed to drupal_render().',
465
      'group' => 'Theme',
466
    );
467
  }
468

    
469
  /**
470
   * Asserts that an array of elements is rendered properly.
471
   *
472
   * @param array $elements
473
   *   An array of associative arrays describing render elements and their
474
   *   expected markup. Each item in $elements must contain the following:
475
   *   - 'name': This human readable description will be displayed on the test
476
   *     results page.
477
   *   - 'value': This is the render element to test.
478
   *   - 'expected': This is the expected markup for the element in 'value'.
479
   */
480
  function assertElements($elements) {
481
    foreach($elements as $element) {
482
      $this->assertIdentical(drupal_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by drupal_render().');
483
    }
484
  }
485

    
486
  /**
487
   * Tests system #type 'container'.
488
   */
489
  function testContainer() {
490
    $elements = array(
491
      // Basic container with no attributes.
492
      array(
493
        'name' => "#type 'container' with no HTML attributes",
494
        'value' => array(
495
          '#type' => 'container',
496
          'child' => array(
497
            '#markup' => 'foo',
498
          ),
499
        ),
500
        'expected' => '<div>foo</div>',
501
      ),
502
      // Container with a class.
503
      array(
504
        'name' => "#type 'container' with a class HTML attribute",
505
        'value' => array(
506
          '#type' => 'container',
507
          'child' => array(
508
            '#markup' => 'foo',
509
          ),
510
          '#attributes' => array(
511
            'class' => 'bar',
512
          ),
513
        ),
514
        'expected' => '<div class="bar">foo</div>',
515
      ),
516
    );
517

    
518
    $this->assertElements($elements);
519
  }
520

    
521
  /**
522
   * Tests system #type 'html_tag'.
523
   */
524
  function testHtmlTag() {
525
    $elements = array(
526
      // Test auto-closure meta tag generation.
527
      array(
528
        'name' => "#type 'html_tag' auto-closure meta tag generation",
529
        'value' => array(
530
          '#type' => 'html_tag',
531
          '#tag' => 'meta',
532
          '#attributes' => array(
533
            'name' => 'description',
534
            'content' => 'Drupal test',
535
          ),
536
        ),
537
        'expected' => '<meta name="description" content="Drupal test" />' . "\n",
538
      ),
539
      // Test title tag generation.
540
      array(
541
        'name' => "#type 'html_tag' title tag generation",
542
        'value' => array(
543
          '#type' => 'html_tag',
544
          '#tag' => 'title',
545
          '#value' => 'title test',
546
        ),
547
        'expected' => '<title>title test</title>' . "\n",
548
      ),
549
    );
550

    
551
    $this->assertElements($elements);
552
  }
553
}
554

    
555
/**
556
 * Tests for the ThemeRegistry class.
557
 */
558
class ThemeRegistryTestCase extends DrupalWebTestCase {
559
  public static function getInfo() {
560
    return array(
561
      'name' => 'ThemeRegistry',
562
      'description' => 'Tests the behavior of the ThemeRegistry class',
563
      'group' => 'Theme',
564
    );
565
  }
566
  function setUp() {
567
    parent::setUp('theme_test');
568
  }
569

    
570
  /**
571
   * Tests the behavior of the theme registry class.
572
   */
573
  function testRaceCondition() {
574
    $_SERVER['REQUEST_METHOD'] = 'GET';
575
    $cid = 'test_theme_registry';
576

    
577
    // Directly instantiate the theme registry, this will cause a base cache
578
    // entry to be written in __construct().
579
    $registry = new ThemeRegistry($cid, 'cache');
580

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

    
583
    // Trigger a cache miss for an offset.
584
    $this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry.');
585
    // This will cause the ThemeRegistry class to write an updated version of
586
    // the cache entry when it is destroyed, usually at the end of the request.
587
    // Before that happens, manually delete the cache entry we created earlier
588
    // so that the new entry is written from scratch.
589
    cache_clear_all($cid, 'cache');
590

    
591
    // Destroy the class so that it triggers a cache write for the offset.
592
    unset($registry);
593

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

    
596
    // Create a new instance of the class. Confirm that both the offset
597
    // requested previously, and one that has not yet been requested are both
598
    // available.
599
    $registry = new ThemeRegistry($cid, 'cache');
600

    
601
    $this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry');
602
    $this->assertTrue($registry['theme_test_template_test_2'], 'Offset was returned correctly from the theme registry');
603
  }
604
}
605

    
606
/**
607
 * Tests for theme debug markup.
608
 */
609
class ThemeDebugMarkupTestCase extends DrupalWebTestCase {
610

    
611
  public static function getInfo() {
612
    return array(
613
      'name' => 'Theme debug markup',
614
      'description' => 'Tests theme debug markup output.',
615
      'group' => 'Theme',
616
    );
617
  }
618

    
619
  function setUp() {
620
    parent::setUp('theme_test', 'node');
621
    theme_enable(array('test_theme'));
622
  }
623

    
624
  /**
625
   * Tests debug markup added to template output.
626
   */
627
  function testDebugOutput() {
628
    variable_set('theme_default', 'test_theme');
629
    // Enable the debug output.
630
    variable_set('theme_debug', TRUE);
631

    
632
    $registry = theme_get_registry();
633
    $extension = '.tpl.php';
634
    // Populate array of templates.
635
    $templates = drupal_find_theme_templates($registry, $extension, drupal_get_path('theme', 'test_theme'));
636
    $templates += drupal_find_theme_templates($registry, $extension, drupal_get_path('module', 'node'));
637

    
638
    // Create a node and test different features of the debug markup.
639
    $node = $this->drupalCreateNode();
640
    $this->drupalGet('node/' . $node->nid);
641
    $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
642
    $this->assertRaw("CALL: theme('node')", 'Theme call information found.');
643
    $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.');
644
    $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension;
645
    $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
646

    
647
    // Create another node and make sure the template suggestions shown in the
648
    // debug markup are correct.
649
    $node2 = $this->drupalCreateNode();
650
    $this->drupalGet('node/' . $node2->nid);
651
    $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.');
652

    
653
    // Create another node and make sure the template suggestions shown in the
654
    // debug markup are correct.
655
    $node3 = $this->drupalCreateNode();
656
    $build = array('#theme' => 'node__foo__bar');
657
    $build += node_view($node3);
658
    $output = drupal_render($build);
659
    $this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.');
660
    $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.');
661

    
662
    // Disable theme debug.
663
    variable_set('theme_debug', FALSE);
664

    
665
    $this->drupalGet('node/' . $node->nid);
666
    $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
667
  }
668

    
669
}
670

    
671
/**
672
 * Tests module-provided theme engines.
673
 */
674
class ModuleProvidedThemeEngineTestCase extends DrupalWebTestCase {
675

    
676
  public static function getInfo() {
677
    return array(
678
      'name' => 'Theme engine test',
679
      'description' => 'Tests module-provided theme engines.',
680
      'group' => 'Theme',
681
    );
682
  }
683

    
684
  function setUp() {
685
    parent::setUp('theme_test');
686
    theme_enable(array('test_theme', 'test_theme_nyan_cat'));
687
  }
688

    
689
  /**
690
   * Ensures that the module provided theme engine is found and used by core.
691
   */
692
  function testEngineIsFoundAndWorking() {
693
    variable_set('theme_default', 'test_theme_nyan_cat');
694
    variable_set('admin_theme', 'test_theme_nyan_cat');
695

    
696
    $this->drupalGet('theme-test/engine-info-test');
697
    $this->assertText('Miaou');
698
  }
699

    
700
}