ontology = $this->createMock(Ontology::class); $this->resolver = $this->createMock(TaoMediaResolver::class); $this->subject = new SharedStimulusMediaExtractor(); $this->subject->setServiceLocator($this->getServiceLocatorMock([ Ontology::SERVICE_ID => $this->ontology ])); $this->subject->withMediaResolver($this->resolver); } public function testExtractMediaIdentifiers(): void { $imagePath = 'taomedia://taomediamanager/image-path.png'; $videoPath = 'taomedia://taomediamanager/video-path.png'; $xml = ''; $xml .= '
'; $xml .= ''; $xml .= ''; $xml .= ''; $this->loadResolver($imagePath, $videoPath); $resource = $this->createConfiguredMock(RdfResource::class, ['exists' => true]); $this->ontology ->expects($this->exactly(2)) ->method('getResource') ->withConsecutive( [$this->equalTo($imagePath)], [$this->equalTo($videoPath)] ) ->willReturn( $resource, $resource ); $expected = [ $imagePath, $videoPath, ]; $this->assertSame( $expected, $this->subject->extractMediaIdentifiers($xml) ); } public function testExtractNonExistingMediaIdentifiers(): void { $imagePath = 'http://image-path.png'; $videoPath = 'taomedia://mediamanager/video-path.png'; $xml = ''; $xml .= '
'; $xml .= ''; $xml .= ''; $xml .= ''; $this->loadResolver($imagePath, $videoPath); $resource = $this->createConfiguredMock(RdfResource::class, ['exists' => false]); $this->ontology ->expects($this->once()) ->method('getResource') ->with($this->equalTo($imagePath)) ->willReturn($resource); $this->expectException(InvalidMediaReferenceException::class); $this->subject->extractMediaIdentifiers($xml); } public function testAssertMediaFileNotExists() { $imagePath = 'http://image-path.png'; $videoPath = 'taomedia://mediamanager/video-path.png'; $xml = ''; $xml .= '
'; $xml .= ''; $xml .= ''; $xml .= ''; $mediaSource = $this->createMock(MediaSource::class); $mediaSource ->expects($this->once()) ->method('getFileInfo') ->with($imagePath) ->willThrowException(new InvalidMediaReferenceException($imagePath)); $imageAsset = $this->createConfiguredMock(MediaAsset::class, [ 'getMediaSource' => $mediaSource, 'getMediaIdentifier' => $imagePath ]); $this->resolver ->method('resolve') ->with($imagePath) ->willReturn($imageAsset); $this->expectException(InvalidMediaReferenceException::class); $this->subject->assertMediaFileExists($xml); } public function testAssertMediaFileExists() { $imagePath = 'image-path.png'; $videoPath = 'video-path.png'; $xml = ''; $xml .= '
'; $xml .= ''; $xml .= ''; $xml .= ''; $this->loadResolver($imagePath, $videoPath); try { $this->subject->assertMediaFileExists($xml); $this->assertTrue(true); } catch (Throwable $e) { $this->fail('An exception has been thrown and should not if files are existing. '); } } private function loadResolver(string $imagePath, string $videoPath): void { $mediaSource = $this->createConfiguredMock(MediaSource::class, ['getFileInfo' => 'info']); ; $imageAsset = $this->createConfiguredMock(MediaAsset::class, [ 'getMediaSource' => $mediaSource, 'getMediaIdentifier' => $imagePath ]); $videoAsset = $this->createConfiguredMock(MediaAsset::class, [ 'getMediaSource' => $mediaSource, 'getMediaIdentifier' => $videoPath ]); $this->resolver ->method('resolve') ->withConsecutive([$this->equalTo($imagePath)], [$this->equalTo($videoPath)]) ->willReturnOnConsecutiveCalls($imageAsset, $videoAsset); } }