Projet

Général

Profil

Paste
Télécharger (5,51 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / views_handlers.test @ 4003efde

1
<?php
2

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

    
8
/**
9
 * Tests abstract handlers of views.
10
 */
11
class ViewsHandlersTest extends ViewsSqlTest {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Handlers test',
15
      'description' => 'test abstract handler definitions',
16
      'group' => 'Views',
17
    );
18
  }
19

    
20
  function testFilterInOperatorUi() {
21
    $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
22
    $this->drupalLogin($admin_user);
23
    menu_rebuild();
24

    
25
    $path = 'admin/structure/views/nojs/config-item/test_filter_in_operator_ui/default/filter/type';
26
    $this->drupalGet($path);
27
    $this->assertFieldByName('options[expose][reduce]', FALSE);
28

    
29
    $edit = array(
30
      'options[expose][reduce]' => TRUE,
31
    );
32
    $this->drupalPost($path, $edit, t('Apply'));
33
    $this->drupalGet($path);
34
    $this->assertFieldByName('options[expose][reduce]', TRUE);
35
  }
36

    
37
  /**
38
   * Tests views_break_phrase_string function.
39
   */
40
  function test_views_break_phrase_string() {
41
    $empty_stdclass = new stdClass();
42
    $empty_stdclass->operator = 'or';
43
    $empty_stdclass->value = array();
44

    
45
    $null = NULL;
46
    // check defaults.
47
    $this->assertEqual($empty_stdclass, views_break_phrase_string('', $null));
48

    
49
    $handler = views_get_handler('node', 'title', 'argument');
50
    $this->assertEqual($handler, views_break_phrase_string('', $handler));
51

    
52
    // test ors.
53
    $handler = views_break_phrase_string('word1 word2+word');
54
    $this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
55
    $this->assertEqual('or', $handler->operator);
56
    $handler = views_break_phrase_string('word1+word2+word');
57
    $this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
58
    $this->assertEqual('or', $handler->operator);
59
    $handler = views_break_phrase_string('word1 word2 word');
60
    $this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
61
    $this->assertEqual('or', $handler->operator);
62
    $handler = views_break_phrase_string('word-1+word-2+word');
63
    $this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
64
    $this->assertEqual('or', $handler->operator);
65
    $handler = views_break_phrase_string('wõrd1+wõrd2+wõrd');
66
    $this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
67
    $this->assertEqual('or', $handler->operator);
68

    
69
    // test ands.
70
    $handler = views_break_phrase_string('word1,word2,word');
71
    $this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
72
    $this->assertEqual('and', $handler->operator);
73
    $handler = views_break_phrase_string('word1 word2,word');
74
    $this->assertEqualValue(array('word1 word2', 'word'), $handler);
75
    $this->assertEqual('and', $handler->operator);
76
    $handler = views_break_phrase_string('word1,word2 word');
77
    $this->assertEqualValue(array('word1', 'word2 word'), $handler);
78
    $this->assertEqual('and', $handler->operator);
79
    $handler = views_break_phrase_string('word-1,word-2,word');
80
    $this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
81
    $this->assertEqual('and', $handler->operator);
82
    $handler = views_break_phrase_string('wõrd1,wõrd2,wõrd');
83
    $this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
84
    $this->assertEqual('and', $handler->operator);
85

    
86
    // test a single word.
87
    $handler = views_break_phrase_string('word');
88
    $this->assertEqualValue(array('word'), $handler);
89
    $this->assertEqual('and', $handler->operator);
90
  }
91

    
92
  /**
93
   * Tests views_break_phrase function.
94
   */
95
  function test_views_break_phrase() {
96
    $empty_stdclass = new stdClass();
97
    $empty_stdclass->operator = 'or';
98
    $empty_stdclass->value = array();
99

    
100
    $null = NULL;
101
    // check defaults.
102
    $this->assertEqual($empty_stdclass, views_break_phrase('', $null));
103

    
104
    $handler = views_get_handler('node', 'title', 'argument');
105
    $this->assertEqual($handler, views_break_phrase('', $handler));
106

    
107
    // Generate three random numbers which can be used below;
108
    $n1 = rand(0, 100);
109
    $n2 = rand(0, 100);
110
    $n3 = rand(0, 100);
111
    // test ors.
112
    $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2+$n3", $handler));
113
    $this->assertEqual('or', $handler->operator);
114
    $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1+$n2+$n3", $handler));
115
    $this->assertEqual('or', $handler->operator);
116
    $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2 $n3", $handler));
117
    $this->assertEqual('or', $handler->operator);
118
    $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2++$n3", $handler));
119
    $this->assertEqual('or', $handler->operator);
120

    
121
    // test ands.
122
    $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,$n2,$n3", $handler));
123
    $this->assertEqual('and', $handler->operator);
124
    $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,,$n2,$n3", $handler));
125
    $this->assertEqual('and', $handler->operator);
126
  }
127

    
128
  /**
129
   * Check to see if two values are equal.
130
   *
131
   * @param string $first
132
   *   The first value to check.
133
   * @param views_handler $handler
134
   * @param string $message
135
   *   The message to display along with the assertion.
136
   * @param string $group
137
   *   The type of assertion - examples are "Browser", "PHP".
138
   *
139
   * @return bool
140
   *   TRUE if the assertion succeeded, FALSE otherwise.
141
   */
142
  protected function assertEqualValue($first, $handler, $message = '', $group = 'Other') {
143
    return $this->assert($first == $handler->value, $message ? $message : t('First value is equal to second value'), $group);
144
  }
145

    
146
}