comparison core/modules/media/tests/src/Kernel/MediaCreationTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
26 26
27 // Test a media type created from default configuration. 27 // Test a media type created from default configuration.
28 $this->container->get('module_installer')->install(['media_test_type']); 28 $this->container->get('module_installer')->install(['media_test_type']);
29 $test_media_type = $media_type_storage->load('test'); 29 $test_media_type = $media_type_storage->load('test');
30 $this->assertInstanceOf(MediaTypeInterface::class, $test_media_type, 'The media type from default configuration has not been created in the database.'); 30 $this->assertInstanceOf(MediaTypeInterface::class, $test_media_type, 'The media type from default configuration has not been created in the database.');
31 $this->assertEquals('Test type', $test_media_type->get('label'), 'Could not assure the correct type name.'); 31 $this->assertSame('Test type', $test_media_type->get('label'), 'Could not assure the correct type name.');
32 $this->assertEquals('Test type.', $test_media_type->get('description'), 'Could not assure the correct type description.'); 32 $this->assertSame('Test type.', $test_media_type->get('description'), 'Could not assure the correct type description.');
33 $this->assertEquals('test', $test_media_type->get('source'), 'Could not assure the correct media source.'); 33 $this->assertSame('test', $test_media_type->get('source'), 'Could not assure the correct media source.');
34 // Source field is not set on the media source, but it should never 34 // Source field is not set on the media source, but it should never
35 // be created automatically when a config is being imported. 35 // be created automatically when a config is being imported.
36 $this->assertEquals(['source_field' => '', 'test_config_value' => 'Kakec'], $test_media_type->get('source_configuration'), 'Could not assure the correct media source configuration.'); 36 $this->assertSame(['source_field' => '', 'test_config_value' => 'Kakec'], $test_media_type->get('source_configuration'), 'Could not assure the correct media source configuration.');
37 $this->assertEquals(['metadata_attribute' => 'field_attribute_config_test'], $test_media_type->get('field_map'), 'Could not assure the correct field map.'); 37 $this->assertSame(['metadata_attribute' => 'field_attribute_config_test'], $test_media_type->get('field_map'), 'Could not assure the correct field map.');
38 // Check the Media Type access handler behavior. 38 // Check the Media Type access handler behavior.
39 // We grant access to the 'view label' operation to all users having 39 // We grant access to the 'view label' operation to all users having
40 // permission to 'view media'. 40 // permission to 'view media'.
41 $user1 = User::create([ 41 $user1 = User::create([
42 'name' => 'username1', 42 'name' => 'username1',
70 $media->save(); 70 $media->save();
71 71
72 $this->assertNotInstanceOf(MediaInterface::class, Media::load(rand(1000, 9999)), 'Failed asserting a non-existent media.'); 72 $this->assertNotInstanceOf(MediaInterface::class, Media::load(rand(1000, 9999)), 'Failed asserting a non-existent media.');
73 73
74 $this->assertInstanceOf(MediaInterface::class, Media::load($media->id()), 'The new media item has not been created in the database.'); 74 $this->assertInstanceOf(MediaInterface::class, Media::load($media->id()), 'The new media item has not been created in the database.');
75 $this->assertEquals($this->testMediaType->id(), $media->bundle(), 'The media item was not created with the correct type.'); 75 $this->assertSame($this->testMediaType->id(), $media->bundle(), 'The media item was not created with the correct type.');
76 $this->assertEquals('Unnamed', $media->getName(), 'The media item was not created with the correct name.'); 76 $this->assertSame('Unnamed', $media->getName(), 'The media item was not created with the correct name.');
77 $source_field_name = $media->bundle->entity->getSource()->getSourceFieldDefinition($media->bundle->entity)->getName(); 77 $source_field_name = $media->bundle->entity->getSource()->getSourceFieldDefinition($media->bundle->entity)->getName();
78 $this->assertEquals('Nation of sheep, ruled by wolves, owned by pigs.', $media->get($source_field_name)->value, 'Source returns incorrect source field value.'); 78 $this->assertSame('Nation of sheep, ruled by wolves, owned by pigs.', $media->get($source_field_name)->value, 'Source returns incorrect source field value.');
79 } 79 }
80 80
81 } 81 }