summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/node/views_node_revision_relations.test
blob: 6b38396f89dd062f544115813bda809dd8cded94 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php

/**
 * @file
 * Definition of ViewsNodeRevisionRelationsTestCase.
 */

/**
 * Tests basic node_revision table integration into views.
 */
class ViewsNodeRevisionRelationsTestCase extends ViewsSqlTest {

  public static function getInfo() {
    return array(
      'name' => 'Tests basic node_revision integration',
      'description' => 'Tests the integration of node_revision table of node module',
      'group' => 'Views Modules',
    );
  }

  /**
   * Create a node with revision and rest result count for both views.
   */
  public function testNodeRevisionRelationship() {
    $node = $this->drupalCreateNode();
    // Create revision of the node.
    $node_revision = clone $node;
    $node_revision->revision = 1;
    node_save($node_revision);
    $column_map = array(
      'vid' => 'vid',
      'node_revision_nid' => 'node_revision_nid',
      'node_node_revision_nid' => 'node_node_revision_nid',
    );

    // Here should be two rows.
    $view_nid = $this->test_view_node_revision_nid();
    $this->executeView($view_nid, array($node->nid));
    $resultset_nid = array(
      array(
        'vid' => '1',
        'node_revision_nid' => '1',
        'node_node_revision_nid' => '1',
      ),
      array(
        'vid' => '2',
        'node_revision_nid' => '1',
        'node_node_revision_nid' => '1',
      ),
    );
    $this->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);

    // There should be only one row with active revision 2.
    $view_vid = $this->test_view_node_revision_vid();
    $this->executeView($view_vid, array($node->nid));
    $resultset_vid = array(
      array(
        'vid' => '2',
        'node_revision_nid' => '1',
        'node_node_revision_nid' => '1',
      ),
    );
    $this->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);
  }

  /**
   * Test view with default join on node.nid.
   */
  function test_view_node_revision_nid() {
    $view = new view();
    $view->name = 'test_node_revision_nid';
    $view->description = '';
    $view->tag = '';
    $view->base_table = 'node_revision';
    $view->human_name = 'Test node revision nid';
    $view->core = 7;
    $view->api_version = '3.0';
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view->new_display('default', 'Master', 'default');
    $handler->display->display_options['use_more_always'] = FALSE;
    $handler->display->display_options['access']['type'] = 'perm';
    $handler->display->display_options['access']['perm'] = 'view revisions';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';
    /* Relationship: Content revision: Content */
    $handler->display->display_options['relationships']['nid']['id'] = 'nid';
    $handler->display->display_options['relationships']['nid']['table'] = 'node_revision';
    $handler->display->display_options['relationships']['nid']['field'] = 'nid';
    $handler->display->display_options['relationships']['nid']['label'] = 'NID';
    $handler->display->display_options['relationships']['nid']['required'] = TRUE;
    /* Field: Content revision: Vid */
    $handler->display->display_options['fields']['vid']['id'] = 'vid';
    $handler->display->display_options['fields']['vid']['table'] = 'node_revision';
    $handler->display->display_options['fields']['vid']['field'] = 'vid';
    /* Field: Content revision: Nid */
    $handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
    $handler->display->display_options['fields']['nid_1']['table'] = 'node_revision';
    $handler->display->display_options['fields']['nid_1']['field'] = 'nid';
    /* Field: Content: Nid */
    $handler->display->display_options['fields']['nid']['id'] = 'nid';
    $handler->display->display_options['fields']['nid']['table'] = 'node';
    $handler->display->display_options['fields']['nid']['field'] = 'nid';
    $handler->display->display_options['fields']['nid']['relationship'] = 'nid';
    /* Contextual filter: Content revision: Nid */
    $handler->display->display_options['arguments']['nid']['id'] = 'nid';
    $handler->display->display_options['arguments']['nid']['table'] = 'node_revision';
    $handler->display->display_options['arguments']['nid']['field'] = 'nid';
    $handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
    $handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
    $handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';

    return $view;
  }

  /**
   * Test view with default join on node.vid.
   */
  function test_view_node_revision_vid() {
    $view = new view();
    $view->name = 'test_node_revision_vid';
    $view->description = '';
    $view->tag = '';
    $view->base_table = 'node_revision';
    $view->human_name = 'Test node revision vid';
    $view->core = 7;
    $view->api_version = '3.0';
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view->new_display('default', 'Master', 'default');
    $handler->display->display_options['use_more_always'] = FALSE;
    $handler->display->display_options['access']['type'] = 'perm';
    $handler->display->display_options['access']['perm'] = 'view revisions';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';
    /* Relationship: Content revision: Content */
    $handler->display->display_options['relationships']['vid']['id'] = 'vid';
    $handler->display->display_options['relationships']['vid']['table'] = 'node_revision';
    $handler->display->display_options['relationships']['vid']['field'] = 'vid';
    $handler->display->display_options['relationships']['vid']['label'] = 'VID';
    $handler->display->display_options['relationships']['vid']['required'] = TRUE;
    /* Field: Content revision: Vid */
    $handler->display->display_options['fields']['vid']['id'] = 'vid';
    $handler->display->display_options['fields']['vid']['table'] = 'node_revision';
    $handler->display->display_options['fields']['vid']['field'] = 'vid';
    /* Field: Content revision: Nid */
    $handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
    $handler->display->display_options['fields']['nid_1']['table'] = 'node_revision';
    $handler->display->display_options['fields']['nid_1']['field'] = 'nid';
    /* Field: Content: Nid */
    $handler->display->display_options['fields']['nid']['id'] = 'nid';
    $handler->display->display_options['fields']['nid']['table'] = 'node';
    $handler->display->display_options['fields']['nid']['field'] = 'nid';
    $handler->display->display_options['fields']['nid']['relationship'] = 'vid';
    /* Contextual filter: Content revision: Nid */
    $handler->display->display_options['arguments']['nid']['id'] = 'nid';
    $handler->display->display_options['arguments']['nid']['table'] = 'node_revision';
    $handler->display->display_options['arguments']['nid']['field'] = 'nid';
    $handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
    $handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
    $handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';

    return $view;
  }
}