summaryrefslogtreecommitdiffstats
path: root/core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php
blob: 7b91c6ea3c7a4839ab704fe70c4d9335563e8e73 (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
<?php

namespace Drupal\Tests\media\FunctionalJavascript;

use Drupal\views\Views;

/**
 * Tests the media entity type integration into the wizard.
 *
 * @group media
 *
 * @see \Drupal\media\Plugin\views\wizard\Media
 * @see \Drupal\media\Plugin\views\wizard\MediaRevision
 */
class MediaViewsWizardTest extends MediaJavascriptTestBase {

  /**
   * Tests adding a view of media.
   */
  public function testMediaWizard() {
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $view_id = strtolower($this->randomMachineName(16));
    $this->drupalGet('admin/structure/views/add');
    $page->fillField('label', $view_id);
    $this->waitUntilVisible('.machine-name-value');
    $page->selectFieldOption('show[wizard_key]', 'media');
    $assert_session->assertWaitOnAjaxRequest();
    $page->checkField('page[create]');
    $page->fillField('page[path]', $this->randomMachineName(16));
    $page->pressButton('Save and edit');
    $this->assertEquals($session->getCurrentUrl(), $this->baseUrl . '/admin/structure/views/view/' . $view_id);

    $view = Views::getView($view_id);
    $view->initHandlers();
    $row = $view->display_handler->getOption('row');
    $this->assertEquals($row['type'], 'fields');
    // Check for the default filters.
    $this->assertEquals($view->filter['status']->table, 'media_field_data');
    $this->assertEquals($view->filter['status']->field, 'status');
    $this->assertTrue($view->filter['status']->value);
    // Check for the default fields.
    $this->assertEquals($view->field['name']->table, 'media_field_data');
    $this->assertEquals($view->field['name']->field, 'name');

  }

  /**
   * Tests adding a view of media revisions.
   */
  public function testMediaRevisionWizard() {
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $view_id = strtolower($this->randomMachineName(16));
    $this->drupalGet('admin/structure/views/add');
    $page->fillField('label', $view_id);
    $this->waitUntilVisible('.machine-name-value');
    $page->selectFieldOption('show[wizard_key]', 'media_revision');
    $assert_session->assertWaitOnAjaxRequest();
    $page->checkField('page[create]');
    $page->fillField('page[path]', $this->randomMachineName(16));
    $page->pressButton('Save and edit');
    $this->assertEquals($session->getCurrentUrl(), $this->baseUrl . '/admin/structure/views/view/' . $view_id);

    $view = Views::getView($view_id);
    $view->initHandlers();
    $row = $view->display_handler->getOption('row');
    $this->assertEquals($row['type'], 'fields');

    // Check for the default filters.
    $this->assertEquals($view->filter['status']->table, 'media_field_revision');
    $this->assertEquals($view->filter['status']->field, 'status');
    $this->assertTrue($view->filter['status']->value);

    // Check for the default fields.
    $this->assertEquals($view->field['name']->table, 'media_field_revision');
    $this->assertEquals($view->field['name']->field, 'name');
    $this->assertEquals($view->field['changed']->table, 'media_field_revision');
    $this->assertEquals($view->field['changed']->field, 'changed');
  }

}