ee91ccdda3f8d53c2b2dbae409f8040369758757
[yaffs-website] / web / modules / contrib / media_entity / src / Tests / Views / WizardTest.php
1 <?php
2
3 namespace Drupal\media_entity\Tests\Views;
4
5 use Drupal\views\Views;
6 use Drupal\views\Tests\Wizard\WizardTestBase;
7
8 /**
9  * Tests the media entity type integration into the wizard.
10  *
11  * @group media_entity
12  * @see \Drupal\media_entity\Plugin\views\wizard\Media
13  * @see \Drupal\media_entity\Plugin\views\wizard\MediaRevision
14  */
15 class WizardTest extends WizardTestBase {
16
17   /**
18    * Modules to install.
19    *
20    * @var array
21    */
22   public static $modules = ['media_entity'];
23
24   /**
25    * Tests adding a view of media.
26    */
27   public function testMediaWizard() {
28     $view = [];
29     $view['label'] = $this->randomMachineName(16);
30     $view['id'] = strtolower($this->randomMachineName(16));
31     $view['show[wizard_key]'] = 'media';
32     $view['page[create]'] = TRUE;
33     $view['page[path]'] = $this->randomMachineName(16);
34
35     // Just triggering the saving should automatically choose a proper row
36     // plugin.
37     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
38     $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
39
40     $user = $this->drupalCreateUser(['access content']);
41     $this->drupalLogin($user);
42
43     $view = Views::getView($view['id']);
44     $view->initHandlers();
45     $row = $view->display_handler->getOption('row');
46     $this->assertEqual($row['type'], 'fields');
47
48     // Check for the default filters.
49     $this->assertEqual($view->filter['status']->table, 'media_field_data');
50     $this->assertEqual($view->filter['status']->field, 'status');
51     $this->assertTrue($view->filter['status']->value);
52
53     // Check for the default fields.
54     $this->assertEqual($view->field['name']->table, 'media_field_data');
55     $this->assertEqual($view->field['name']->field, 'name');
56   }
57
58   /**
59    * Tests adding a view of media revisions.
60    */
61   public function testMediaRevisionWizard() {
62     $view = [];
63     $view['label'] = $this->randomMachineName(16);
64     $view['id'] = strtolower($this->randomMachineName(16));
65     $view['show[wizard_key]'] = 'media_revision';
66     $view['page[create]'] = TRUE;
67     $view['page[path]'] = $this->randomMachineName(16);
68
69     // Just triggering the saving should automatically choose a proper row
70     // plugin.
71     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
72     $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
73
74     $user = $this->drupalCreateUser(['view all revisions']);
75     $this->drupalLogin($user);
76
77     $view = Views::getView($view['id']);
78     $view->initHandlers();
79     $row = $view->display_handler->getOption('row');
80     $this->assertEqual($row['type'], 'fields');
81
82     // Check for the default filters.
83     $this->assertEqual($view->filter['status']->table, 'media_field_revision');
84     $this->assertEqual($view->filter['status']->field, 'status');
85     $this->assertTrue($view->filter['status']->value);
86
87     // Check for the default fields.
88     $this->assertEqual($view->field['name']->table, 'media_field_revision');
89     $this->assertEqual($view->field['name']->field, 'name');
90     $this->assertEqual($view->field['changed']->table, 'media_field_revision');
91     $this->assertEqual($view->field['changed']->field, 'changed');
92   }
93
94 }