rootClass = new \core_kernel_classes_Class('http://myFancyDomaine.com/myGreatCLassUriForBrowserTest'); } public function tearDown(): void { (MediaService::singleton())->deleteClass($this->rootClass); } public function testGetDirectory() { $this->rootClass->setLabel('myRootClass'); $acceptableMime = []; $depth = 1; $mediaSource = $this->initializeMediaSource(); $directory = $mediaSource->getDirectory(\tao_helpers_Uri::encode($this->rootClass->getUri()), $acceptableMime, $depth); $this->assertIsArray($directory, 'The result should be an array'); $this->assertArrayHasKey('label', $directory, 'The result should contain "label"'); $this->assertArrayHasKey('path', $directory, 'The result should contain "path"'); $this->assertArrayHasKey('children', $directory, 'The result should contain "children"'); $this->assertIsArray($directory['children'], 'Children should be an array'); $this->assertEquals('myRootClass', $directory['label'], 'The label is not correct'); $this->assertEquals('taomedia://mediamanager/' . \tao_helpers_Uri::encode($this->rootClass->getUri()), $directory['path'], 'The path is not correct'); $this->rootClass->createSubClass('mySubClass1'); $this->rootClass->createSubClass('mySubClass0'); $newDirectory = $mediaSource->getDirectory(\tao_helpers_Uri::encode($this->rootClass->getUri()), $acceptableMime, $depth); $this->assertIsArray($newDirectory['children'], 'Children should be an array'); $this->assertNotEmpty($newDirectory['children'], 'Children should not be empty'); $labels = []; foreach ($newDirectory['children'] as $i => $child) { $this->assertIsArray($child, 'The result should be an array'); if (isset($child['parent'])) { $this->assertArrayHasKey('label', $child, 'The result should contain "label"'); $this->assertArrayHasKey('path', $child, 'The result should contain "path"'); $labels[$child['label']] = $child['label']; } else { $this->assertArrayHasKey('name', $child, 'The result should contain "name"'); $this->assertArrayHasKey('uri', $child, 'The result should contain "uri"'); $this->assertArrayHasKey('link', $child, 'The result should contain "link"'); } } $this->assertEquals(2, count($labels)); $this->assertContains('mySubClass0', $labels); $this->assertContains('mySubClass1', $labels); } public function testGetFileInfo() { $instance = $this->rootClass->createInstance('Brazil.png'); $instance->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK), 'myGreatLink'); $instance->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE), 'image/png'); $uri = $instance->getUri(); $fileInfo = $this->initializeMediaSource()->getFileInfo(\tao_helpers_Uri::decode($uri)); $this->assertIsArray($fileInfo, 'The result should be an array'); $this->assertArrayHasKey('name', $fileInfo, 'The result should contain "name"'); $this->assertArrayHasKey('mime', $fileInfo, 'The result should contain "mime"'); $this->assertArrayHasKey('size', $fileInfo, 'The result should contain "size"'); $this->assertArrayHasKey('uri', $fileInfo, 'The result should contain "size"'); $this->assertEquals($instance->getLabel(), $fileInfo['name'], 'The file name is not correct'); $this->assertEquals('image/png', $fileInfo['mime'], 'The mime type is not correct'); $this->assertEquals('taomedia://mediamanager/' . \tao_helpers_Uri::encode($uri), $fileInfo['uri'], 'The uri is not correct'); } public function testGetFileInfoFail() { $this->expectException(tao_models_classes_FileNotFoundException::class); $this->expectExceptionMessage('File A Fake link not found'); $link = 'A Fake link'; $this->initializeMediaSource()->getFileInfo($link); } private function initializeMediaSource() { $fileManagerMock = $this->getMockBuilder(FlySystemManagement::class) ->setMethods(['getFileSize', 'deleteFile']) ->getMock(); $fileManagerMock->expects($this->any()) ->method('getFileSize') ->willReturn(100); $mediaSource = new MediaSource(['lang' => 'EN_en', 'rootClass' => $this->rootClass]); $ref = new \ReflectionProperty(MediaSource::class, 'fileManagementService'); $ref->setAccessible(true); $ref->setValue($mediaSource, $fileManagerMock); return $mediaSource; } }