summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_glossary.test
blob: 0fe0fbae6f5021be7d21ce47262bae4a7e1aa0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

/**
 * @file
 * Definition of ViewsGlossaryTestCase.
 */

/**
 * Tests glossary view ( summary of arguments ).
 */
class ViewsGlossaryTestCase extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Glossary Test',
      'description' => 'Tests glossary functionality of views.',
      'group' => 'Views',
    );
  }

  public function setUp() {
    parent::setUp('views');
  }

  /**
   * Tests the default glossary view.
   */
  public function testGlossaryView() {
    // create a contentype and add some nodes, with a non random title.
    $type = $this->drupalCreateContentType();
    $nodes_per_char = array(
      'd' => 1,
      'r' => 4,
      'u' => 10,
      'p' => 2,
      'a' => 3,
      'l' => 6,
    );
    foreach ($nodes_per_char as $char => $count) {
      $setting = array(
        'type' => $type->type
      );
      for ($i = 0; $i < $count; $i++) {
        $node = $setting;
        $node['title'] = $char . $this->randomString(3);
        $this->drupalCreateNode($node);
      }
    }

    // Execute glossary view
    $view = views_get_view('glossary');
    $view->set_display('attachment');
    $view->execute_display('attachment');

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