public function PathautoPatternTest::testMediaPattern in Lightning Media 8.4
Same name and namespace in other branches
- 8.2 tests/src/Functional/PathautoPatternTest.php \Drupal\Tests\lightning_media\Functional\PathautoPatternTest::testMediaPattern()
- 8.3 tests/src/Functional/PathautoPatternTest.php \Drupal\Tests\lightning_media\Functional\PathautoPatternTest::testMediaPattern()
Tests media types that ship with Lightning.
File
- tests/
src/ Functional/ PathautoPatternTest.php, line 48
Class
- PathautoPatternTest
- Tests that all media items have a /media/BUNDLE/ID Pathauto pattern.
Namespace
Drupal\Tests\lightning_media\FunctionalCode
public function testMediaPattern() {
$assert_session = $this
->assertSession();
// This could be done with the data provider pattern, but there's no real
// benefit to that in this case, and this is significantly faster.
$media = [
'document' => NULL,
'image' => NULL,
'video' => 'https://www.youtube.com/watch?v=Nf_aD3dTloY',
'tweet' => 'https://twitter.com/50NerdsofGrey/status/757319527151636480',
'instagram' => 'https://www.instagram.com/p/BmIh_AFDBzX',
];
foreach ($media as $type => $source_value) {
/** @var \Drupal\media\MediaInterface $media */
$media_item = Media::create([
'bundle' => $type,
'name' => $this
->randomString(),
]);
if ($source_value) {
$source_field = $media_item
->getSource()
->getSourceFieldDefinition($media_item->bundle->entity)
->getName();
$media_item
->set($source_field, $source_value);
}
$media_item
->setPublished()
->save();
$this
->drupalGet($media_item
->toUrl());
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains($media_item
->label());
$assert_session
->addressEquals('/media/' . strtolower($media_item
->bundle()) . '/' . $media_item
->id());
}
}