BasicTest.php 6.98 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Tests\Wizard\BasicTest.
6
7
 */

8
namespace Drupal\views\Tests\Wizard;
9
10
11
12

/**
 * Tests creating views with the wizard and viewing them on the listing page.
 */
13
14
class BasicTest extends WizardTestBase {

15
16
  public static function getInfo() {
    return array(
17
      'name' => 'Basic functionality',
18
      'description' => 'Test creating basic views with the wizard and viewing them on the listing page.',
19
      'group' => 'Views Wizard',
20
21
22
23
    );
  }

  function testViewsWizardAndListing() {
24
25
26
    $this->drupalCreateContentType(array('type' => 'article'));
    $this->drupalCreateContentType(array('type' => 'page'));

27
28
29
30
31
32
    // Check if we can access the main views admin page.
    $this->drupalGet('admin/structure/views');
    $this->assertText(t('Add new view'));

    // Create a simple and not at all useful view.
    $view1 = array();
33
    $view1['label'] = $this->randomName(16);
34
    $view1['id'] = strtolower($this->randomName(16));
35
36
    $view1['description'] = $this->randomName(16);
    $view1['page[create]'] = FALSE;
37
    $this->drupalPostForm('admin/structure/views/add', $view1, t('Save and edit'));
38
    $this->assertResponse(200);
39
    $this->drupalGet('admin/structure/views');
40
    $this->assertText($view1['label']);
41
    $this->assertText($view1['description']);
42
43
44
    $this->assertLinkByHref(url('admin/structure/views/view/' . $view1['id']));
    $this->assertLinkByHref(url('admin/structure/views/view/' . $view1['id'] . '/delete'));
    $this->assertLinkByHref(url('admin/structure/views/view/' . $view1['id'] . '/clone'));
45
46
47

    // This view should not have a block.
    $this->drupalGet('admin/structure/block');
48
    $this->assertNoText($view1['label']);
49
50
51
52
53
54
55

    // Create two nodes.
    $node1 = $this->drupalCreateNode(array('type' => 'page'));
    $node2 = $this->drupalCreateNode(array('type' => 'article'));

    // Now create a page with simple node listing and an attached feed.
    $view2 = array();
56
    $view2['label'] = $this->randomName(16);
57
    $view2['id'] = strtolower($this->randomName(16));
58
59
60
61
62
63
    $view2['description'] = $this->randomName(16);
    $view2['page[create]'] = 1;
    $view2['page[title]'] = $this->randomName(16);
    $view2['page[path]'] = $this->randomName(16);
    $view2['page[feed]'] = 1;
    $view2['page[feed_properties][path]'] = $this->randomName(16);
64
    $this->drupalPostForm('admin/structure/views/add', $view2, t('Save and edit'));
65
    $this->drupalGet($view2['page[path]']);
66
    $this->assertResponse(200);
67
68
69
70
71

    // Since the view has a page, we expect to be automatically redirected to
    // it.
    $this->assertUrl($view2['page[path]']);
    $this->assertText($view2['page[title]']);
72
73
    $this->assertText($node1->label());
    $this->assertText($node2->label());
74
75
76
77
78
79
80

    // Check if we have the feed.
    $this->assertLinkByHref(url($view2['page[feed_properties][path]']));
    $this->drupalGet($view2['page[feed_properties][path]']);
    $this->assertRaw('<rss version="2.0"');
    // The feed should have the same title and nodes as the page.
    $this->assertText($view2['page[title]']);
81
    $this->assertRaw(url('node/' . $node1->id(), array('absolute' => TRUE)));
82
    $this->assertText($node1->label());
83
    $this->assertRaw(url('node/' . $node2->id(), array('absolute' => TRUE)));
84
    $this->assertText($node2->label());
85
86
87

    // Go back to the views page and check if this view is there.
    $this->drupalGet('admin/structure/views');
88
    $this->assertText($view2['label']);
89
90
91
92
93
    $this->assertText($view2['description']);
    $this->assertLinkByHref(url($view2['page[path]']));

    // This view should not have a block.
    $this->drupalGet('admin/structure/block');
94
    $this->assertNoText('View: ' . $view2['label']);
95
96
97

    // Create a view with a page and a block, and filter the listing.
    $view3 = array();
98
    $view3['label'] = $this->randomName(16);
99
    $view3['id'] = strtolower($this->randomName(16));
100
101
102
103
104
105
106
107
    $view3['description'] = $this->randomName(16);
    $view3['show[wizard_key]'] = 'node';
    $view3['show[type]'] = 'page';
    $view3['page[create]'] = 1;
    $view3['page[title]'] = $this->randomName(16);
    $view3['page[path]'] = $this->randomName(16);
    $view3['block[create]'] = 1;
    $view3['block[title]'] = $this->randomName(16);
108
    $this->drupalPostForm('admin/structure/views/add', $view3, t('Save and edit'));
109
    $this->drupalGet($view3['page[path]']);
110
    $this->assertResponse(200);
111
112
113
114

    // Make sure the view only displays the node we expect.
    $this->assertUrl($view3['page[path]']);
    $this->assertText($view3['page[title]']);
115
116
    $this->assertText($node1->label());
    $this->assertNoText($node2->label());
117
118
119

    // Go back to the views page and check if this view is there.
    $this->drupalGet('admin/structure/views');
120
    $this->assertText($view3['label']);
121
122
123
    $this->assertText($view3['description']);
    $this->assertLinkByHref(url($view3['page[path]']));

124
    // Confirm that the block is available in the block administration UI.
125
    $this->drupalGet('admin/structure/block/list/' . \Drupal::config('system.theme')->get('default'));
126
    $this->assertText($view3['label']);
127
128

    // Place the block.
129
    $this->drupalPlaceBlock("views_block:{$view3['id']}-block_1");
130
131
132
133

    // Visit a random page (not the one that displays the view itself) and look
    // for the expected node title in the block.
    $this->drupalGet('user');
134
135
    $this->assertText($node1->label());
    $this->assertNoText($node2->label());
136
137

    // Make sure the listing page doesn't show disabled default views.
138
    $this->assertNoText('tracker', 'Default tracker view does not show on the listing page.');
139
  }
140

141
142
143
144
145
146
147
148
  /**
   * Tests the actual wizard form.
   *
   * @see \Drupal\views_ui\ViewAddFormController::form()
   */
  protected function testWizardForm() {
    $this->drupalGet('admin/structure/views/add');

149
    $result = $this->xpath('//small[@id = "edit-label-machine-name-suffix"]');
150
151
    $this->assertTrue(count($result), 'Ensure that the machine name is applied to the name field.');
  }
152
153
154
155
156
157
158
159
160
161
162
163
164
165

  /**
   * Tests default plugin values are populated from the wizard form.
   *
   * @see \Drupal\views\Plugin\views\display\DisplayPluginBase::mergeDefaults().
   */
  public function testWizardDefaultValues() {
    $random_id = strtolower($this->randomName(16));
    // Create a basic view.
    $view = array();
    $view['label'] = $this->randomName(16);
    $view['id'] = $random_id;
    $view['description'] = $this->randomName(16);
    $view['page[create]'] = FALSE;
166
    $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
167
168
169
170
171
172
173
174
175
176
177
178
179

    // Make sure the plugin types that should not have empty options don't have.
    // Test against all values is unit tested.
    // @see \Drupal\views\Tests\Plugin\DisplayUnitTest
    $view = views_get_view($random_id);
    $displays = $view->storage->get('display');
    foreach (array('query', 'exposed_form', 'pager', 'style', 'row') as $type) {
      foreach ($displays as $display) {
        $this->assertFalse(empty($display['display_options'][$type]['options']), format_string('Default options found for @plugin.', array('@plugin' => $type)));
      }
    }

  }
180
}