resolver = $this->createMock(TaoMediaResolver::class);
$this->subject = new SharedStimulusMediaParser();
$this->subject->withMediaResolver($this->resolver);
}
public function testExtractMedia()
{
$imagePath = 'taomedia://taomediamanager/image-path.png';
$imageDataUri = 'data:image/png;base64' . base64_encode('base64-image');
$imageDataUri = 'data:video/mp4;base64' . base64_encode('base64-video');
$objectPath = 'taomedia://taomediamanager/video-path.mp4';
$objectHttp = 'http://video.tao';
$xml = '';
$xml .= '
';
$xml .= '
';
$xml .= '
';
$xml .= '
';
$xml .= '
';
$xml .= '
';
$processor = function(MediaAsset $mediaAsset) {
return 'processed::' . $mediaAsset->getMediaIdentifier();
};
$this->resolver
->expects($this->exactly(3))
->method('resolve')
->withConsecutive(
[$this->equalTo($imagePath)],
[$this->equalTo($objectPath)],
[$this->equalTo($objectHttp)]
)
->willReturnOnConsecutiveCalls(
$this->createMediaAsset($imagePath, MediaSource::class),
$this->createMediaAsset($objectPath, MediaSource::class),
$this->createMediaAsset($objectHttp, HttpSource::class)
);
$expected = [
'processed::' . $imagePath,
'processed::' . $objectPath,
];
$this->assertSame(
$expected,
$this->subject->extractMedia($xml, $processor)
);
}
public function testExtractMediaWithInvalidQtiXml()
{
// missing closing div element ()
$invalidXml = '';
$this->expectException(TaoMediaException::class);
$this->subject->extractMedia($invalidXml, function () {});
}
private function createMediaAsset(string $path, string $sourceClass): MediaAsset
{
$mediaAsset = $this->createMock(MediaAsset::class);
$mediaAsset
->expects($this->once())
->method('getMediaSource')
->willReturn(
$this->createMock($sourceClass)
);
$mediaAsset
->expects($this->any())
->method('getMediaIdentifier')
->willReturn(
$path
);
return $mediaAsset;
}
}