public function AssetImageHelperTest::testGetGenericMediaIcon in Media: Acquia DAM 8
Validate we get a generic media icon when no image can be loaded.
File
- tests/
src/ Unit/ AssetImageHelperTest.php, line 98
Class
- AssetImageHelperTest
- Tests integration of the AssetImageHelper service.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
public function testGetGenericMediaIcon() {
$mimetype = [
'discrete' => 'image',
'sub' => 'jpg',
];
// @todo Any way to reset the mock method so we can change willReturn?
// We have to get a new mock class each test because it is (seemingly) not
// possible to change the willReturn for a mocked method after it has been
// set.
$helper = $this
->getMockedAssetImageHelper();
$helper
->method('phpFileExists')
->willReturn(TRUE);
$this
->assertEquals('public://media-icons/image-jpg.png', $helper
->getGenericMediaIcon($mimetype));
$helper = $this
->getMockedAssetImageHelper();
$helper
->method('phpFileExists')
->willReturnOnConsecutiveCalls(FALSE, TRUE);
$this
->assertEquals('public://media-icons/jpg.png', $helper
->getGenericMediaIcon($mimetype));
$helper = $this
->getMockedAssetImageHelper();
$helper
->method('phpFileExists')
->willReturnOnConsecutiveCalls(FALSE, FALSE, TRUE);
$this
->assertEquals('public://media-icons/generic.png', $helper
->getGenericMediaIcon($mimetype));
$helper = $this
->getMockedAssetImageHelper();
$helper
->method('phpFileExists')
->willReturn(FALSE);
$this
->assertFalse($helper
->getGenericMediaIcon($mimetype));
}