Projet

Général

Profil

Révision b4adf10d

Ajouté par Assos Assos il y a plus de 9 ans

Udpate to 7.33

Voir les différences:

drupal7/modules/simpletest/tests/theme.test
425 425
}
426 426

  
427 427
/**
428
 * Unit tests for theme_html_tag().
428
 * Tests the markup of core render element types passed to drupal_render().
429 429
 */
430
class ThemeHtmlTag extends DrupalUnitTestCase {
430
class RenderElementTypesTestCase extends DrupalWebTestCase {
431 431
  public static function getInfo() {
432 432
    return array(
433
      'name' => 'Theme HTML Tag',
434
      'description' => 'Tests theme_html_tag() built-in theme functions.',
433
      'name' => 'Render element types',
434
      'description' => 'Tests the markup of core render element types passed to drupal_render().',
435 435
      'group' => 'Theme',
436 436
    );
437 437
  }
438 438

  
439 439
  /**
440
   * Test function theme_html_tag()
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'.
441 493
   */
442
  function testThemeHtmlTag() {
443
    // Test auto-closure meta tag generation
444
    $tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test'));
445
    $this->assertEqual('<meta name="description" content="Drupal test" />'."\n", theme_html_tag($tag), 'Test auto-closure meta tag generation.');
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
    );
446 520

  
447
    // Test title tag generation
448
    $tag['element'] = array('#tag' => 'title', '#value' => 'title test');
449
    $this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), 'Test title tag generation.');
521
    $this->assertElements($elements);
450 522
  }
451 523
}
452 524

  
......
500 572
    $this->assertTrue($registry['theme_test_template_test_2'], 'Offset was returned correctly from the theme registry');
501 573
  }
502 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
}

Formats disponibles : Unified diff