public function MediaEntitySlideshowTest::testMediaEntitySlideshow in Media entity slideshow 8
Tests media entity slideshow.
File
- src/
Tests/ MediaEntitySlideshowTest.php, line 75
Class
- MediaEntitySlideshowTest
- Tests for media entity slideshow.
Namespace
Drupal\media_entity_slideshow\TestsCode
public function testMediaEntitySlideshow() {
// If we have a bundle already the schema is correct.
$this
->assertTrue((bool) $this->slideshowMediaBundle, 'The media bundle from default configuration has been created in the database.');
// Test the creation of a media entity of the slidehsow bundle.
$this
->drupalGet('media/add/' . $this->slideshowMediaBundle
->id());
$edit = [
'name[0][value]' => 'My first slideshow',
'field_slides[0][target_id]' => $this->mediaImageCollection[0]
->label() . ' (' . $this->mediaImageCollection[0]
->id() . ')',
];
$this
->drupalPostForm(NULL, $edit, t('Save and publish'));
$this
->assertText('Slideshow bundle My first slideshow has been created', 'Slideshow media entity was correctly created.');
$slideshow_id = $this->container
->get('entity.query')
->get('media')
->condition('bundle', 'slideshow_bundle')
->sort('created', 'DESC')
->execute();
$slideshow = $this
->loadMedia(reset($slideshow_id));
// Add one more slide to it.
$this
->drupalGet('media/' . $slideshow
->id() . '/edit');
$edit = [
'field_slides[0][target_id]' => $this->mediaImageCollection[0]
->label() . ' (' . $this->mediaImageCollection[0]
->id() . ')',
'field_slides[1][target_id]' => $this->mediaImageCollection[1]
->label() . ' (' . $this->mediaImageCollection[1]
->id() . ')',
];
$this
->drupalPostForm(NULL, $edit, t('Save and keep published'));
$this
->assertResponse(200, 'Form submitted correctly');
$slideshow = $this
->loadMedia($slideshow
->id());
$this
->assertEqual($slideshow->field_slides
->count(), 2, 'A new slide was correctly added to the slideshow.');
// Test removing one of the slides.
$this
->drupalGet('media/' . $slideshow
->id() . '/edit');
$edit = [
'field_slides[0][target_id]' => $this->mediaImageCollection[0]
->label() . ' (' . $this->mediaImageCollection[0]
->id() . ')',
'field_slides[1][target_id]' => '',
];
$this
->drupalPostForm(NULL, $edit, t('Save and keep published'));
$this
->assertResponse(200, 'Form submitted correctly');
$slideshow = $this
->loadMedia($slideshow
->id());
$this
->assertEqual($slideshow->field_slides
->count(), 1, 'The deletion of one slide worked properly.');
// Delete the slideshow entirely.
$this
->drupalGet('/media/' . $slideshow
->id() . '/delete');
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertResponse(200, 'Form submitted correctly');
$this
->assertText('The media My first slideshow has been deleted', 'The slideshow was correctly deleted.');
}