getExtensionById('taoItems'); } public function tearDown(): void { if ($this->item) { $this->item->delete(); } parent::tearDown(); } public function testAdd() { $source = $this->getLocalItemSource(); $info = $source->add($this->getSampleFile(), 'example.txt', '/'); $this->assertEquals('example.txt', $info['name']); $this->assertEquals('example.txt', $info['uri']); $this->assertEquals('example.txt', $info['filePath']); } public function testGetFileInfo() { $asset = $this->getMediaAsset(); $source = $asset->getMediaSource(); $info = $source->getFileInfo($asset->getMediaIdentifier()); $this->assertEquals('example.txt', $info['uri']); } public function testDelete() { $asset = $this->getMediaAsset(); $source = $asset->getMediaSource(); $success = $source->delete($asset->getMediaIdentifier()); $this->assertTrue($success); try { $source->getFileInfo($asset->getMediaIdentifier()); $this->fail('GetFileInfo on a deleted file should throw error'); } catch (\tao_models_classes_FileNotFoundException $e) { // should not be found } } protected function getMediaAsset() { $source = $this->getLocalItemSource(); $info = $source->add($this->getSampleFile(), 'example.txt', '/'); $link = $info['uri']; return new MediaAsset($source, $link); } protected function getSampleFile() { return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . 'asset' . DIRECTORY_SEPARATOR . 'sample.css'; } protected function getLocalItemSource() { $itemService = \taoItems_models_classes_ItemsService::singleton(); $this->item = $itemService->createInstance($itemService->getRootClass(), 'testItem'); $source = new LocalItemSource([ 'item' => $this->item, 'lang' => DEFAULT_LANG ]); $this->setInaccessibleProperty($source, 'itemService', $this->getItemServiceMock()); return $source; } protected function getItemServiceMock() { $itemServiceMock = $this->getMockBuilder(\taoItems_models_classes_ItemsService::class) ->disableOriginalConstructor() ->getMock(); $itemServiceMock->expects($this->any()) ->method('getItemDirectory') ->will($this->returnValue($this->getTempDirectory())); return $itemServiceMock; } }