['folder' => self::$SUB_FOLDER_FULL_PATH]] ); self::createTestFolder(self::$SUB_FOLDER_DELETE_FULL_PATH); self::createTestFolder(self::$SUB_FOLDER_SINGLE_FULL_PATH); self::createTestFolder(self::$FOLDER2_NAME); } public static function tearDownAfterClass() { self::cleanupTestAssets(); self::cleanupFolder(self::$FOLDER_NAME); self::cleanupFolder(self::$FOLDER2_NAME); parent::tearDownAfterClass(); } /** * Get a list of all root folders. */ public function testListRootFolders() { $result = self::$adminApi->rootFolders(); self::assertObjectStructure($result, ['total_count' => IsType::TYPE_INT]); self::assertNotEmpty($result['folders']); self::assertValidFolder($result['folders'][0]); $result = self::$adminApi->rootFolders(['max_results' => 1]); self::assertCount(1, $result['folders']); self::assertObjectStructure( $result, ['total_count' => IsType::TYPE_INT, 'next_cursor' => IsType::TYPE_STRING] ); self::assertValidFolder($result['folders'][0]); } /** * Get sub folders for a given folder. * * @throws ApiError */ public function testListSubFolders() { $result = self::$adminApi->subfolders(self::$SUB_FOLDER_FULL_PATH); self::assertObjectStructure($result, ['total_count' => IsType::TYPE_INT]); self::assertNotEmpty($result['folders']); self::assertValidFolder( $result['folders'][0], [ 'name' => self::$SUB_FOLDER_NAME, 'path' => self::$SUB_FOLDER_SINGLE_FULL_PATH, ] ); $result = self::$adminApi->subfolders(self::$FOLDER_NAME, ['max_results' => 1]); self::assertCount(1, $result['folders']); self::assertObjectStructure( $result, ['total_count' => IsType::TYPE_INT, 'next_cursor' => IsType::TYPE_STRING] ); self::assertValidFolder($result['folders'][0]); } /** * Create folder. * * @throws ApiError */ public function testCreateFolder() { self::createTestFolder(self::$SUB_FOLDER_CREATE_FULL_PATH); } /** * Delete folder * * @throws ApiError */ public function testDeleteFolder() { $result = self::$adminApi->deleteFolder(self::$SUB_FOLDER_DELETE_FULL_PATH); self::assertContains(self::$SUB_FOLDER_DELETE_FULL_PATH, $result['deleted']); } /** * Create a folder and asserts that creation succeeded. * * @param string $path * * @return ApiResponse * @throws ApiError * @throws \Exception */ private static function createTestFolder($path) { $result = self::$adminApi->createFolder($path); $pathAsArray = explode('/', $path); $name = array_pop($pathAsArray); self::assertValidFolder($result, ['path' => $path, 'name' => $name]); self::assertTrue($result['success']); self::retryAssertionIfThrows( static function () use ($path, $name, $pathAsArray) { $folders = self::$adminApi->subfolders(implode('/', $pathAsArray)); self::assertArrayContainsArray( $folders['folders'], [ 'name' => $name, 'path' => $path, ] ); } ); return $result; } /** * Should throw exception on non-existing folder. * * @throws ApiError */ public function testFolderListingError() { $this->expectException(NotFound::class); self::$adminApi->subfolders('non-existent-subfolder'); } }