Mercurial > hg > isophonics-drupal-site
comparison core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\media\Functional; | |
4 | |
5 use Drupal\media\Entity\Media; | |
6 use Drupal\media\Entity\MediaType; | |
7 | |
8 /** | |
9 * Ensures that media UI works correctly. | |
10 * | |
11 * @group media | |
12 */ | |
13 class MediaUiFunctionalTest extends MediaFunctionalTestBase { | |
14 | |
15 /** | |
16 * Modules to enable. | |
17 * | |
18 * @var array | |
19 */ | |
20 public static $modules = [ | |
21 'block', | |
22 'media_test_source', | |
23 ]; | |
24 | |
25 /** | |
26 * {@inheritdoc} | |
27 */ | |
28 protected function setUp() { | |
29 parent::setUp(); | |
30 $this->drupalPlaceBlock('local_actions_block'); | |
31 $this->drupalPlaceBlock('local_tasks_block'); | |
32 | |
33 // We need to test without any default configuration in place. | |
34 // @TODO: Remove this when https://www.drupal.org/node/2883813 lands. | |
35 MediaType::load('file')->delete(); | |
36 MediaType::load('image')->delete(); | |
37 } | |
38 | |
39 /** | |
40 * Tests the media actions (add/edit/delete). | |
41 */ | |
42 public function testMediaWithOnlyOneMediaType() { | |
43 $session = $this->getSession(); | |
44 $page = $session->getPage(); | |
45 $assert_session = $this->assertSession(); | |
46 | |
47 $media_type = $this->createMediaType([ | |
48 'new_revision' => FALSE, | |
49 'queue_thumbnail_downloads' => FALSE, | |
50 ]); | |
51 | |
52 $this->drupalGet('media/add'); | |
53 $assert_session->statusCodeEquals(200); | |
54 $assert_session->addressEquals('media/add/' . $media_type->id()); | |
55 $assert_session->elementNotExists('css', '#edit-revision'); | |
56 | |
57 // Tests media add form. | |
58 $media_name = $this->randomMachineName(); | |
59 $page->fillField('name[0][value]', $media_name); | |
60 $revision_log_message = $this->randomString(); | |
61 $page->fillField('revision_log_message[0][value]', $revision_log_message); | |
62 $page->pressButton('Save'); | |
63 $media_id = $this->container->get('entity.query')->get('media')->execute(); | |
64 $media_id = reset($media_id); | |
65 /** @var \Drupal\media\MediaInterface $media */ | |
66 $media = $this->container->get('entity_type.manager') | |
67 ->getStorage('media') | |
68 ->loadUnchanged($media_id); | |
69 $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message); | |
70 $this->assertEquals($media->getName(), $media_name); | |
71 $assert_session->titleEquals($media_name . ' | Drupal'); | |
72 | |
73 // Tests media edit form. | |
74 $media_type->setNewRevision(FALSE); | |
75 $media_type->save(); | |
76 $media_name2 = $this->randomMachineName(); | |
77 $this->drupalGet('media/' . $media_id . '/edit'); | |
78 $assert_session->checkboxNotChecked('edit-revision'); | |
79 $media_name = $this->randomMachineName(); | |
80 $page->fillField('name[0][value]', $media_name2); | |
81 $page->pressButton('Save'); | |
82 /** @var \Drupal\media\MediaInterface $media */ | |
83 $media = $this->container->get('entity_type.manager') | |
84 ->getStorage('media') | |
85 ->loadUnchanged($media_id); | |
86 $this->assertEquals($media->getName(), $media_name2); | |
87 $assert_session->titleEquals($media_name2 . ' | Drupal'); | |
88 | |
89 // Test that there is no empty vertical tabs element, if the container is | |
90 // empty (see #2750697). | |
91 // Make the "Publisher ID" and "Created" fields hidden. | |
92 $this->drupalGet('/admin/structure/media/manage/' . $media_type->id() . '/form-display'); | |
93 $page->selectFieldOption('fields[created][parent]', 'hidden'); | |
94 $page->selectFieldOption('fields[uid][parent]', 'hidden'); | |
95 $page->pressButton('Save'); | |
96 // Assure we are testing with a user without permission to manage revisions. | |
97 $this->drupalLogin($this->nonAdminUser); | |
98 // Check the container is not present. | |
99 $this->drupalGet('media/' . $media_id . '/edit'); | |
100 $assert_session->elementNotExists('css', 'input.vertical-tabs__active-tab'); | |
101 // Continue testing as admin. | |
102 $this->drupalLogin($this->adminUser); | |
103 | |
104 // Enable revisions by default. | |
105 $previous_revision_id = $media->getRevisionId(); | |
106 $media_type->setNewRevision(TRUE); | |
107 $media_type->save(); | |
108 $this->drupalGet('media/' . $media_id . '/edit'); | |
109 $assert_session->checkboxChecked('edit-revision'); | |
110 $page->fillField('name[0][value]', $media_name); | |
111 $page->fillField('revision_log_message[0][value]', $revision_log_message); | |
112 $page->pressButton('Save'); | |
113 $assert_session->titleEquals($media_name . ' | Drupal'); | |
114 /** @var \Drupal\media\MediaInterface $media */ | |
115 $media = $this->container->get('entity_type.manager') | |
116 ->getStorage('media') | |
117 ->loadUnchanged($media_id); | |
118 $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message); | |
119 $this->assertNotEquals($previous_revision_id, $media->getRevisionId()); | |
120 | |
121 // Test the status checkbox. | |
122 $this->drupalGet('media/' . $media_id . '/edit'); | |
123 $page->uncheckField('status[value]'); | |
124 $page->pressButton('Save'); | |
125 /** @var \Drupal\media\MediaInterface $media */ | |
126 $media = $this->container->get('entity_type.manager') | |
127 ->getStorage('media') | |
128 ->loadUnchanged($media_id); | |
129 $this->assertFalse($media->isPublished()); | |
130 | |
131 // Tests media delete form. | |
132 $this->drupalGet('media/' . $media_id . '/edit'); | |
133 $page->clickLink('Delete'); | |
134 $assert_session->pageTextContains('This action cannot be undone'); | |
135 $page->pressButton('Delete'); | |
136 $media_id = \Drupal::entityQuery('media')->execute(); | |
137 $this->assertFalse($media_id); | |
138 } | |
139 | |
140 /** | |
141 * Tests the "media/add" and "media/mid" pages. | |
142 * | |
143 * Tests if the "media/add" page gives you a selecting option if there are | |
144 * multiple media types available. | |
145 */ | |
146 public function testMediaWithMultipleMediaTypes() { | |
147 $assert_session = $this->assertSession(); | |
148 | |
149 // Tests and creates the first media type. | |
150 $first_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]); | |
151 | |
152 // Test and create a second media type. | |
153 $second_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]); | |
154 | |
155 // Test if media/add displays two media type options. | |
156 $this->drupalGet('media/add'); | |
157 | |
158 // Checks for the first media type. | |
159 $assert_session->pageTextContains($first_media_type->label()); | |
160 $assert_session->pageTextContains($first_media_type->getDescription()); | |
161 // Checks for the second media type. | |
162 $assert_session->pageTextContains($second_media_type->label()); | |
163 $assert_session->pageTextContains($second_media_type->getDescription()); | |
164 | |
165 // Continue testing media type filter. | |
166 $first_media_item = Media::create(['bundle' => $first_media_type->id()]); | |
167 $first_media_item->save(); | |
168 $second_media_item = Media::create(['bundle' => $second_media_type->id()]); | |
169 $second_media_item->save(); | |
170 | |
171 // Go to first media item. | |
172 $this->drupalGet('media/' . $first_media_item->id()); | |
173 $assert_session->statusCodeEquals(200); | |
174 $assert_session->pageTextContains($first_media_item->getName()); | |
175 | |
176 // Go to second media item. | |
177 $this->drupalGet('media/' . $second_media_item->id()); | |
178 $assert_session->statusCodeEquals(200); | |
179 $assert_session->pageTextContains($second_media_item->getName()); | |
180 } | |
181 | |
182 } |