Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / tests / views_glossary.test @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of ViewsGlossaryTestCase.
6
 */
7

    
8
/**
9
 * Tests glossary view ( summary of arguments ).
10
 */
11
class ViewsGlossaryTestCase extends ViewsSqlTest {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Glossary Test',
15
      'description' => 'Tests glossary functionality of views.',
16
      'group' => 'Views',
17
    );
18
  }
19

    
20
  public function setUp() {
21
    parent::setUp('views');
22
  }
23

    
24
  /**
25
   * Tests the default glossary view.
26
   */
27
  public function testGlossaryView() {
28
    // create a contentype and add some nodes, with a non random title.
29
    $type = $this->drupalCreateContentType();
30
    $nodes_per_char = array(
31
      'd' => 1,
32
      'r' => 4,
33
      'u' => 10,
34
      'p' => 2,
35
      'a' => 3,
36
      'l' => 6,
37
    );
38
    foreach ($nodes_per_char as $char => $count) {
39
      $setting = array(
40
        'type' => $type->type
41
      );
42
      for ($i = 0; $i < $count; $i++) {
43
        $node = $setting;
44
        $node['title'] = $char . $this->randomString(3);
45
        $this->drupalCreateNode($node);
46
      }
47
    }
48

    
49
    // Execute glossary view
50
    $view = views_get_view('glossary');
51
    $view->set_display('attachment');
52
    $view->execute_display('attachment');
53

    
54
    // Check that the amount of nodes per char.
55
    $result_nodes_per_char = array();
56
    foreach ($view->result as $item) {
57
      $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
58
    }
59
  }
60
}