Project

General

Profile

Paste
Download (6.45 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views / tests / views_handler_filter.test @ 6de61b86

1
<?php
2

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

    
8
/**
9
 * Tests filter handler.
10
 */
11
class ViewsHandlerFilterTest extends ViewsSqlTest {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Handler filter test',
19
      'description' => 'test filter handler definitions',
20
      'group' => 'Views',
21
    );
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  protected function setUp() {
28
    // The Views and Views UI modules will be enabled with this.
29
    parent::setUp();
30

    
31
    // Assign vocabulary 'tag' to user entity.
32
    $field_definition = field_read_field('field_tags');
33
    $instance_definition = array(
34
      'field_name' => $field_definition['field_name'],
35
      'entity_type' => 'user',
36
      'bundle' => 'user',
37
      'widget' => array(
38
        'type' => 'taxonomy_autocomplete',
39
      ),
40
      'display' => array(
41
        'default' => array(
42
          'type' => 'taxonomy_term_reference_link',
43
          'weight' => 10,
44
        ),
45
        'teaser' => array(
46
          'type' => 'taxonomy_term_reference_link',
47
          'weight' => 10,
48
        ),
49
      ),
50
    );
51
    field_create_instance($instance_definition);
52
  }
53

    
54
  /**
55
   * Tests "is all of" of filter operation.
56
   */
57
  function testFilterInOperatorUi() {
58
    $term = $this->drupalCreateTerm(1);
59

    
60
    $node1 = $this->drupalCreateNode(array('type' => 'article','field_tags_tid' => $term->tid, 'created' => REQUEST_TIME));
61
    $node2 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME + 1));
62
    $user2 = $this->drupalCreateUser(array('access content'));
63
    // $this->drupalLogin($this->drupalCreateUser(array('administer users'));
64
    $this->drupalLogin($this->drupalCreateUser(array('administer users', 'access administration pages', 'administer site configuration', 'administer nodes', 'bypass node access')));
65

    
66
    $this->drupalGet('node/1/edit');
67
    $edit['field_tags' . '[' . LANGUAGE_NONE . ']'] = $term->name;
68
    $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
69

    
70
    $edit['field_tags' . '[' . LANGUAGE_NONE . ']'] = $term->name;
71
    $this->drupalPost('user/' . $user2->uid . '/edit', $edit, t('Save'));
72

    
73
    $result[] = array('nid' => $node1->nid);
74
    $view = $this->get_sample_view();
75
    $this->executeView($view);
76
    $this->assertIdenticalResultset($view, $result);
77
  }
78

    
79
  /**
80
   * Sample view.
81
   *
82
   * @return \view
83
   */
84
  protected function get_sample_view() {
85
    $view = new view();
86
    $view->name = 'article';
87
    $view->description = '';
88
    $view->tag = 'default';
89
    $view->base_table = 'node';
90
    $view->human_name = 'Article';
91
    $view->core = 7;
92
    $view->api_version = '3.0';
93
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
94

    
95
    /* Display: Master */
96
    $handler = $view->new_display('default', 'Master', 'default');
97
    $handler->display->display_options['title'] = 'Article';
98
    $handler->display->display_options['use_more_always'] = FALSE;
99
    $handler->display->display_options['access']['type'] = 'perm';
100
    $handler->display->display_options['cache']['type'] = 'none';
101
    $handler->display->display_options['query']['type'] = 'views_query';
102
    $handler->display->display_options['exposed_form']['type'] = 'basic';
103
    $handler->display->display_options['pager']['type'] = 'full';
104
    $handler->display->display_options['pager']['options']['items_per_page'] = '10';
105
    $handler->display->display_options['style_plugin'] = 'table';
106
    $handler->display->display_options['style_options']['columns'] = array(
107
      'title' => 'title',
108
    );
109
    $handler->display->display_options['style_options']['default'] = '-1';
110
    $handler->display->display_options['style_options']['info'] = array(
111
      'title' => array(
112
        'sortable' => 0,
113
        'default_sort_order' => 'asc',
114
        'align' => '',
115
        'separator' => '',
116
        'empty_column' => 0,
117
      ),
118
    );
119
    /* Field: Content: Nid */
120
    $handler->display->display_options['fields']['nid']['id'] = 'nid';
121
    $handler->display->display_options['fields']['nid']['table'] = 'node';
122
    $handler->display->display_options['fields']['nid']['field'] = 'nid';
123
    $handler->display->display_options['fields']['nid']['label'] = '';
124
    $handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
125
    /* Sort criterion: Content: Post date */
126
    $handler->display->display_options['sorts']['created']['id'] = 'created';
127
    $handler->display->display_options['sorts']['created']['table'] = 'node';
128
    $handler->display->display_options['sorts']['created']['field'] = 'created';
129
    $handler->display->display_options['sorts']['created']['order'] = 'DESC';
130
    /* Filter criterion: Content: Published */
131
    $handler->display->display_options['filters']['status']['id'] = 'status';
132
    $handler->display->display_options['filters']['status']['table'] = 'node';
133
    $handler->display->display_options['filters']['status']['field'] = 'status';
134
    $handler->display->display_options['filters']['status']['value'] = 1;
135
    $handler->display->display_options['filters']['status']['group'] = 1;
136
    $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
137
    /* Filter criterion: Field: Tags (field_tags) */
138
    $handler->display->display_options['filters']['field_tags_tid']['id'] = 'field_tags_tid';
139
    $handler->display->display_options['filters']['field_tags_tid']['table'] = 'field_data_field_tags';
140
    $handler->display->display_options['filters']['field_tags_tid']['field'] = 'field_tags_tid';
141
    $handler->display->display_options['filters']['field_tags_tid']['operator'] = 'and';
142
    $handler->display->display_options['filters']['field_tags_tid']['value'] = array(
143
      0 => '1',
144
    );
145
    $handler->display->display_options['filters']['field_tags_tid']['expose']['operator_id'] = 'field_tags_tid_op';
146
    $handler->display->display_options['filters']['field_tags_tid']['expose']['label'] = 'Tags (field_tags)';
147
    $handler->display->display_options['filters']['field_tags_tid']['expose']['operator'] = 'field_tags_tid_op';
148
    $handler->display->display_options['filters']['field_tags_tid']['expose']['identifier'] = 'field_tags_tid';
149
    $handler->display->display_options['filters']['field_tags_tid']['expose']['remember_roles'] = array(
150
      2 => '2',
151
    );
152
    $handler->display->display_options['filters']['field_tags_tid']['vocabulary'] = 'tags';
153

    
154
    /* Display: Page */
155
    $handler = $view->new_display('page', 'Page', 'page');
156
    $handler->display->display_options['path'] = 'article';
157

    
158
    return $view;
159
  }
160

    
161
}