comparison core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
41 public function testMediaWithOnlyOneMediaType() { 41 public function testMediaWithOnlyOneMediaType() {
42 $session = $this->getSession(); 42 $session = $this->getSession();
43 $page = $session->getPage(); 43 $page = $session->getPage();
44 $assert_session = $this->assertSession(); 44 $assert_session = $this->assertSession();
45 45
46 $media_type = $this->createMediaType([ 46 $media_type = $this->createMediaType('test', [
47 'new_revision' => FALSE,
48 'queue_thumbnail_downloads' => FALSE, 47 'queue_thumbnail_downloads' => FALSE,
49 ]); 48 ]);
50 49
51 $this->drupalGet('media/add'); 50 $this->drupalGet('media/add');
52 $assert_session->statusCodeEquals(200); 51 $assert_session->statusCodeEquals(200);
59 $revision_log_message = $this->randomString(); 58 $revision_log_message = $this->randomString();
60 $page->fillField('revision_log_message[0][value]', $revision_log_message); 59 $page->fillField('revision_log_message[0][value]', $revision_log_message);
61 $source_field = $this->randomString(); 60 $source_field = $this->randomString();
62 $page->fillField('field_media_test[0][value]', $source_field); 61 $page->fillField('field_media_test[0][value]', $source_field);
63 $page->pressButton('Save'); 62 $page->pressButton('Save');
64 $media_id = $this->container->get('entity.query')->get('media')->execute(); 63 $media_id = $this->container->get('entity_type.manager')
64 ->getStorage('media')
65 ->getQuery()
66 ->execute();
65 $media_id = reset($media_id); 67 $media_id = reset($media_id);
66 /** @var \Drupal\media\MediaInterface $media */ 68 /** @var \Drupal\media\MediaInterface $media */
67 $media = $this->container->get('entity_type.manager') 69 $media = $this->container->get('entity_type.manager')
68 ->getStorage('media') 70 ->getStorage('media')
69 ->loadUnchanged($media_id); 71 ->loadUnchanged($media_id);
70 $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message); 72 $this->assertSame($media->getRevisionLogMessage(), $revision_log_message);
71 $this->assertEquals($media->getName(), $media_name); 73 $this->assertSame($media->getName(), $media_name);
74 $this->drupalGet('media/' . $media_id);
72 $assert_session->titleEquals($media_name . ' | Drupal'); 75 $assert_session->titleEquals($media_name . ' | Drupal');
73 76
74 // Tests media edit form. 77 // Tests media edit form.
75 $media_type->setNewRevision(FALSE); 78 $media_type->setNewRevision(FALSE);
76 $media_type->save(); 79 $media_type->save();
82 $page->pressButton('Save'); 85 $page->pressButton('Save');
83 /** @var \Drupal\media\MediaInterface $media */ 86 /** @var \Drupal\media\MediaInterface $media */
84 $media = $this->container->get('entity_type.manager') 87 $media = $this->container->get('entity_type.manager')
85 ->getStorage('media') 88 ->getStorage('media')
86 ->loadUnchanged($media_id); 89 ->loadUnchanged($media_id);
87 $this->assertEquals($media->getName(), $media_name2); 90 $this->assertSame($media->getName(), $media_name2);
91 $this->drupalGet('media/' . $media_id);
88 $assert_session->titleEquals($media_name2 . ' | Drupal'); 92 $assert_session->titleEquals($media_name2 . ' | Drupal');
89 93
90 // Test that there is no empty vertical tabs element, if the container is 94 // Test that there is no empty vertical tabs element, if the container is
91 // empty (see #2750697). 95 // empty (see #2750697).
92 // Make the "Publisher ID" and "Created" fields hidden. 96 // Make the "Publisher ID" and "Created" fields hidden.
109 $this->drupalGet('media/' . $media_id . '/edit'); 113 $this->drupalGet('media/' . $media_id . '/edit');
110 $assert_session->checkboxChecked('edit-revision'); 114 $assert_session->checkboxChecked('edit-revision');
111 $page->fillField('name[0][value]', $media_name); 115 $page->fillField('name[0][value]', $media_name);
112 $page->fillField('revision_log_message[0][value]', $revision_log_message); 116 $page->fillField('revision_log_message[0][value]', $revision_log_message);
113 $page->pressButton('Save'); 117 $page->pressButton('Save');
118 $this->drupalGet('media/' . $media_id);
114 $assert_session->titleEquals($media_name . ' | Drupal'); 119 $assert_session->titleEquals($media_name . ' | Drupal');
115 /** @var \Drupal\media\MediaInterface $media */ 120 /** @var \Drupal\media\MediaInterface $media */
116 $media = $this->container->get('entity_type.manager') 121 $media = $this->container->get('entity_type.manager')
117 ->getStorage('media') 122 ->getStorage('media')
118 ->loadUnchanged($media_id); 123 ->loadUnchanged($media_id);
119 $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message); 124 $this->assertSame($media->getRevisionLogMessage(), $revision_log_message);
120 $this->assertNotEquals($previous_revision_id, $media->getRevisionId()); 125 $this->assertNotEquals($previous_revision_id, $media->getRevisionId());
121 126
122 // Test the status checkbox. 127 // Test the status checkbox.
123 $this->drupalGet('media/' . $media_id . '/edit'); 128 $this->drupalGet('media/' . $media_id . '/edit');
124 $page->uncheckField('status[value]'); 129 $page->uncheckField('status[value]');
146 */ 151 */
147 public function testMediaWithMultipleMediaTypes() { 152 public function testMediaWithMultipleMediaTypes() {
148 $assert_session = $this->assertSession(); 153 $assert_session = $this->assertSession();
149 154
150 // Tests and creates the first media type. 155 // Tests and creates the first media type.
151 $first_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]); 156 $first_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]);
152 157
153 // Test and create a second media type. 158 // Test and create a second media type.
154 $second_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]); 159 $second_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]);
155 160
156 // Test if media/add displays two media type options. 161 // Test if media/add displays two media type options.
157 $this->drupalGet('media/add'); 162 $this->drupalGet('media/add');
158 163
159 // Checks for the first media type. 164 // Checks for the first media type.
241 'multi-value:single_type:create_list:tags' => [3, [TRUE], TRUE, 'entity_reference_autocomplete_tags'], 246 'multi-value:single_type:create_list:tags' => [3, [TRUE], TRUE, 'entity_reference_autocomplete_tags'],
242 247
243 // Unlimited value field. 248 // Unlimited value field.
244 'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE], 249 'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE],
245 // Unlimited value field with the tags widget. 250 // Unlimited value field with the tags widget.
246 'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE, 'entity_reference_autocomplete_tags'], 251 'unlimited_value:single_type:create_list:tags' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE, 'entity_reference_autocomplete_tags'],
247 ]; 252 ];
248 } 253 }
249 254
250 /** 255 /**
251 * Tests the default autocomplete widgets for media reference fields. 256 * Tests the default autocomplete widgets for media reference fields.
279 foreach ($media_type_create_access as $id => $access) { 284 foreach ($media_type_create_access as $id => $access) {
280 if ($access) { 285 if ($access) {
281 $create_media_types[] = "media_type_$id"; 286 $create_media_types[] = "media_type_$id";
282 $permissions[] = "create media_type_$id media"; 287 $permissions[] = "create media_type_$id media";
283 } 288 }
284 $this->createMediaType(['bundle' => "media_type_$id"]); 289 $this->createMediaType('test', [
290 'id' => "media_type_$id",
291 'label' => "media_type_$id",
292 ]);
285 $media_types["media_type_$id"] = "media_type_$id"; 293 $media_types["media_type_$id"] = "media_type_$id";
286 } 294 }
287 295
288 // Create a user that can create content of the type, with other 296 // Create a user that can create content of the type, with other
289 // permissions as given by the data provider. 297 // permissions as given by the data provider.
427 $this->assertNoHelpLink($fieldset, 'media list'); 435 $this->assertNoHelpLink($fieldset, 'media list');
428 } 436 }
429 } 437 }
430 438
431 /** 439 /**
440 * Tests the redirect URL after creating a media item.
441 */
442 public function testMediaCreateRedirect() {
443 $session = $this->getSession();
444 $page = $session->getPage();
445 $assert_session = $this->assertSession();
446
447 $this->createMediaType('test', [
448 'queue_thumbnail_downloads' => FALSE,
449 ]);
450
451 // Test a redirect to the media canonical URL for a user without the 'access
452 // media overview' permission.
453 $this->drupalLogin($this->drupalCreateUser([
454 'view media',
455 'create media',
456 ]));
457 $this->drupalGet('media/add');
458 $page->fillField('name[0][value]', $this->randomMachineName());
459 $page->fillField('field_media_test[0][value]', $this->randomString());
460 $page->pressButton('Save');
461 $media_id = $this->container->get('entity_type.manager')
462 ->getStorage('media')
463 ->getQuery()
464 ->execute();
465 $media_id = reset($media_id);
466 $assert_session->addressEquals('media/' . $media_id);
467
468 // Test a redirect to the media overview for a user with the 'access media
469 // overview' permission.
470 $this->drupalLogin($this->drupalCreateUser([
471 'view media',
472 'create media',
473 'access media overview',
474 ]));
475 $this->drupalGet('media/add');
476 $page->fillField('name[0][value]', $this->randomMachineName());
477 $page->fillField('field_media_test[0][value]', $this->randomString());
478 $page->pressButton('Save');
479 $assert_session->addressEquals('admin/content/media');
480 }
481
482 /**
432 * Asserts that the given texts are present exactly once. 483 * Asserts that the given texts are present exactly once.
433 * 484 *
434 * @param string[] $texts 485 * @param string[] $texts
435 * A list of the help texts to check. 486 * A list of the help texts to check.
436 * @param string $selector 487 * @param string $selector
479 // Find all the links inside the element. 530 // Find all the links inside the element.
480 $link = $element->findLink($text); 531 $link = $element->findLink($text);
481 532
482 $this->assertNotEmpty($link); 533 $this->assertNotEmpty($link);
483 foreach ($attributes as $attribute => $value) { 534 foreach ($attributes as $attribute => $value) {
484 $this->assertEquals($link->getAttribute($attribute), $value); 535 $this->assertSame($link->getAttribute($attribute), $value);
485 } 536 }
486 } 537 }
487 538
488 /** 539 /**
489 * Asserts that a given link is not present. 540 * Asserts that a given link is not present.
508 $media_storage = $this->container->get('entity_type.manager')->getStorage('media'); 559 $media_storage = $this->container->get('entity_type.manager')->getStorage('media');
509 560
510 $this->container->get('module_installer')->uninstall(['views']); 561 $this->container->get('module_installer')->uninstall(['views']);
511 562
512 // Create a media type and media item. 563 // Create a media type and media item.
513 $media_type = $this->createMediaType(); 564 $media_type = $this->createMediaType('test');
514 $media = $media_storage->create([ 565 $media = $media_storage->create([
515 'bundle' => $media_type->id(), 566 'bundle' => $media_type->id(),
516 'name' => 'Unnamed', 567 'name' => 'Unnamed',
517 ]); 568 ]);
518 $media->save(); 569 $media->save();