Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php Tue Jul 10 15:07:59 2018 +0100 +++ b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php Thu Feb 28 13:21:36 2019 +0000 @@ -43,8 +43,7 @@ $page = $session->getPage(); $assert_session = $this->assertSession(); - $media_type = $this->createMediaType([ - 'new_revision' => FALSE, + $media_type = $this->createMediaType('test', [ 'queue_thumbnail_downloads' => FALSE, ]); @@ -61,14 +60,18 @@ $source_field = $this->randomString(); $page->fillField('field_media_test[0][value]', $source_field); $page->pressButton('Save'); - $media_id = $this->container->get('entity.query')->get('media')->execute(); + $media_id = $this->container->get('entity_type.manager') + ->getStorage('media') + ->getQuery() + ->execute(); $media_id = reset($media_id); /** @var \Drupal\media\MediaInterface $media */ $media = $this->container->get('entity_type.manager') ->getStorage('media') ->loadUnchanged($media_id); - $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message); - $this->assertEquals($media->getName(), $media_name); + $this->assertSame($media->getRevisionLogMessage(), $revision_log_message); + $this->assertSame($media->getName(), $media_name); + $this->drupalGet('media/' . $media_id); $assert_session->titleEquals($media_name . ' | Drupal'); // Tests media edit form. @@ -84,7 +87,8 @@ $media = $this->container->get('entity_type.manager') ->getStorage('media') ->loadUnchanged($media_id); - $this->assertEquals($media->getName(), $media_name2); + $this->assertSame($media->getName(), $media_name2); + $this->drupalGet('media/' . $media_id); $assert_session->titleEquals($media_name2 . ' | Drupal'); // Test that there is no empty vertical tabs element, if the container is @@ -111,12 +115,13 @@ $page->fillField('name[0][value]', $media_name); $page->fillField('revision_log_message[0][value]', $revision_log_message); $page->pressButton('Save'); + $this->drupalGet('media/' . $media_id); $assert_session->titleEquals($media_name . ' | Drupal'); /** @var \Drupal\media\MediaInterface $media */ $media = $this->container->get('entity_type.manager') ->getStorage('media') ->loadUnchanged($media_id); - $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message); + $this->assertSame($media->getRevisionLogMessage(), $revision_log_message); $this->assertNotEquals($previous_revision_id, $media->getRevisionId()); // Test the status checkbox. @@ -148,10 +153,10 @@ $assert_session = $this->assertSession(); // Tests and creates the first media type. - $first_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]); + $first_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]); // Test and create a second media type. - $second_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]); + $second_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]); // Test if media/add displays two media type options. $this->drupalGet('media/add'); @@ -243,7 +248,7 @@ // Unlimited value field. 'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE], // Unlimited value field with the tags widget. - 'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE, 'entity_reference_autocomplete_tags'], + 'unlimited_value:single_type:create_list:tags' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE, 'entity_reference_autocomplete_tags'], ]; } @@ -281,7 +286,10 @@ $create_media_types[] = "media_type_$id"; $permissions[] = "create media_type_$id media"; } - $this->createMediaType(['bundle' => "media_type_$id"]); + $this->createMediaType('test', [ + 'id' => "media_type_$id", + 'label' => "media_type_$id", + ]); $media_types["media_type_$id"] = "media_type_$id"; } @@ -429,6 +437,49 @@ } /** + * Tests the redirect URL after creating a media item. + */ + public function testMediaCreateRedirect() { + $session = $this->getSession(); + $page = $session->getPage(); + $assert_session = $this->assertSession(); + + $this->createMediaType('test', [ + 'queue_thumbnail_downloads' => FALSE, + ]); + + // Test a redirect to the media canonical URL for a user without the 'access + // media overview' permission. + $this->drupalLogin($this->drupalCreateUser([ + 'view media', + 'create media', + ])); + $this->drupalGet('media/add'); + $page->fillField('name[0][value]', $this->randomMachineName()); + $page->fillField('field_media_test[0][value]', $this->randomString()); + $page->pressButton('Save'); + $media_id = $this->container->get('entity_type.manager') + ->getStorage('media') + ->getQuery() + ->execute(); + $media_id = reset($media_id); + $assert_session->addressEquals('media/' . $media_id); + + // Test a redirect to the media overview for a user with the 'access media + // overview' permission. + $this->drupalLogin($this->drupalCreateUser([ + 'view media', + 'create media', + 'access media overview', + ])); + $this->drupalGet('media/add'); + $page->fillField('name[0][value]', $this->randomMachineName()); + $page->fillField('field_media_test[0][value]', $this->randomString()); + $page->pressButton('Save'); + $assert_session->addressEquals('admin/content/media'); + } + + /** * Asserts that the given texts are present exactly once. * * @param string[] $texts @@ -481,7 +532,7 @@ $this->assertNotEmpty($link); foreach ($attributes as $attribute => $value) { - $this->assertEquals($link->getAttribute($attribute), $value); + $this->assertSame($link->getAttribute($attribute), $value); } } @@ -510,7 +561,7 @@ $this->container->get('module_installer')->uninstall(['views']); // Create a media type and media item. - $media_type = $this->createMediaType(); + $media_type = $this->createMediaType('test'); $media = $media_storage->create([ 'bundle' => $media_type->id(), 'name' => 'Unnamed',