3 namespace Drupal\media_entity\Tests\Views;
5 use Drupal\views\Views;
6 use Drupal\views\Tests\Wizard\WizardTestBase;
9 * Tests the media entity type integration into the wizard.
12 * @see \Drupal\media_entity\Plugin\views\wizard\Media
13 * @see \Drupal\media_entity\Plugin\views\wizard\MediaRevision
15 class WizardTest extends WizardTestBase {
22 public static $modules = ['media_entity'];
25 * Tests adding a view of media.
27 public function testMediaWizard() {
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);
35 // Just triggering the saving should automatically choose a proper row
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.');
40 $user = $this->drupalCreateUser(['access content']);
41 $this->drupalLogin($user);
43 $view = Views::getView($view['id']);
44 $view->initHandlers();
45 $row = $view->display_handler->getOption('row');
46 $this->assertEqual($row['type'], 'fields');
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);
53 // Check for the default fields.
54 $this->assertEqual($view->field['name']->table, 'media_field_data');
55 $this->assertEqual($view->field['name']->field, 'name');
59 * Tests adding a view of media revisions.
61 public function testMediaRevisionWizard() {
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);
69 // Just triggering the saving should automatically choose a proper row
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.');
74 $user = $this->drupalCreateUser(['view all revisions']);
75 $this->drupalLogin($user);
77 $view = Views::getView($view['id']);
78 $view->initHandlers();
79 $row = $view->display_handler->getOption('row');
80 $this->assertEqual($row['type'], 'fields');
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);
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');