/** * Test broken method: get_parent_path_from_tree() */ public function test_get_parent_path_from_tree() { global $USER; $this->resetAfterTest(true); $dataset = $this->get_parent_data_provider(); $i = 0; foreach ($dataset as $data) { $childuuid = $data[0]; $parentname = $data[1]; // This condition was added to test if the uuid was false, assert for a fals value and then report on the error // The idea is to mimic a data provider method where by the test will continue if there is one false assertion if (empty($childuuid)) { $this->assertFalse($childuuid, 'Data set#'.$i.': '.$data[2].' in parent '.$data[1].' is false '); $i++; continue; } $foldertree = elis_files_folder_structure(); $resultpath = array(); $this->repo->get_parent_path_from_tree($childuuid, $foldertree, $resultpath, 0, 0, false, 0); if ($parentname != 'Company Home') { $this->assertTrue(!empty($resultpath), 'Data set#'.$i.' childuuid = '.$childuuid); if ($parentname == USERS_HOME) { $parentname = elis_files_transform_username($USER->username); } $this->assertEquals($parentname, $resultpath[count($resultpath) -1]['name'], 'Data set#'.$i); } else { $this->assertTrue(empty($resultpath), 'Data set#'.$i); } $i++; } }
function get_parent_path($uuid, &$path, $cid, $uid, $shared, $oid, $type = 'parent') { if (ELIS_FILES_DEBUG_TRACE) mtrace("\n".'get_alt_parent_path ' . $uuid . ', ' . $cid . ', ' . $uid . ', ' . $shared . ', ' . $oid . ')'); // Call the appropriate get_parent_path method if ($type == 'tree') { $foldertree = elis_files_folder_structure(); self::get_parent_path_from_tree($uuid, $foldertree, $path, $cid, $uid, $shared, $oid); // add Company Home to the top of the array that has been returned, as elis files folder structure does not return Company Home $encodedpath = self::build_encodedpath($this->elis_files->get_root()->uuid, $uid, $cid, $oid, $shared); $folderparent = array('name'=> $this->elis_files->get_root()->title,'path'=>$encodedpath); array_unshift($path,$folderparent); } elseif ($type == 'parent') { self::get_parent_path_from_parent($uuid, $path, $cid, $uid, $shared, $oid); $path = array_reverse($path); } }
/** * Recursively determine whether the specified path is actually valid on the * configured repository. * * @param string $path * @return bool True if the path is valid, False otherwise. */ function elis_files_validate_path($path, $folders = null) { if ($path == '/') { return true; } /// Remove any extraneous slashes from the ends of the string $path = trim($path, '/'); $parts = explode('/', $path); /// Initialize the folder structure if a structure piece wasn't passed to this function. if ($folders == null) { $folders = elis_files_folder_structure(); } /// Get the first piece from the list of path elements. $pathpiece = array_shift($parts); if (!empty($folders)) { foreach ($folders as $folder) { if ($folder['name'] == $pathpiece) { /// If there are no more path elements, we've succeeded! if (empty($parts)) { return true; /// If there are path elements left but no children from the current /// folder, we've failed. } else if (!empty($parts) && empty($folder['children'])) { return false; /// Otherwise, keep looking below. } else { return elis_files_validate_path(implode('/', $parts), $folder['children']); } } } } return false; }
/** * Test times for get_parent using recursive get_parent alfresco calls * @uses $CFG, $DB */ public function test_get_parent_path_tree() { global $CFG, $DB; $this->resetAfterTest(true); $this->setup_test_data_xml(); $options = array( 'ajax' => false, 'name' => 'elis files phpunit test', 'type' => 'elisfiles' ); $repo = new repository_elisfiles('elisfiles', context_system::instance(), $options); // Make sure we connected to the repository successfully. if (empty($repo->elis_files)) { $this->markTestSkipped('Repository not configured or enabled'); } // set up the storage for the full path of the path's UUIDs to validate against $expectedpath = array(); // create folder, get uuid, get path via get_parent_path and elis_files_folder structure // for first folder, create under moodle, then create under the previous folder... $parentfolderuuid = $repo->elis_files->get_root()->uuid; $times = array(); for ($i = 1; $i <= 20; $i++) { $currentfolder = FOLDER_NAME_PREFIX.$i; $currentfolderuuid = $repo->elis_files->create_dir($currentfolder, $parentfolderuuid, '', true); // add the parent folder to our expected sequence of UUIDs $expectedpath[] = repository_elisfiles::build_encodedpath($parentfolderuuid); // elis_files_folder_structure get_parent_path test $starttime = microtime(); $folders = elis_files_folder_structure(); $altrecursivepath = array(); $repo->get_parent_path($currentfolderuuid, $altrecursivepath, 0, 0, 0, 0, 'tree'); $endtime = time(); $structuretime = microtime_diff($starttime, microtime()); // validate the count $this->assertEquals($i, count($altrecursivepath)); // validate the encoded folder UUIDs // look over the expected path parts foreach ($expectedpath as $pathindex => $expectedpart) { // obtain the matching part from the actual return value $resultpart = $altrecursivepath[$pathindex]; $this->assertEquals($expectedpart, $resultpart['path']); } // NOTE: add this back in if we are testing performance $times[] = $times[] = "Folder: $currentfolder and time: $structuretime"; // or nested folders $parentfolderuuid = $currentfolderuuid; } }
/** * Recursively builds a dynamic tree menu for seleting the categories to filter * search results by. * * @param array $cats An array of category objects from the DB. * @param array $selected An array of currently selected category IDs. * @return array An array of completed HTML_TreeMenu nodes. */ function make_root_folder_select_tree($folders = false, $path = '') { global $CFG; if (ELIS_FILES_DEBUG_TRACE) mtrace('make_root_folder_select_tree()'); if (empty($folders) && (!$folders = elis_files_folder_structure())) { return false; } $icon = 'folder.gif'; $eicon = 'folder-expanded.gif'; $nodes = array(); foreach ($folders as $i => $folder) { $npath = $path . '/' . $folder['name']; $text = ' <a href="#" onclick="set_value(\\\'' . $npath . '\\\')" title="' . $npath . '">' . $folder['name'] . (!empty(elis::$config->elisfiles->root_folder) && elis::$config->elisfiles->root_folder == $npath ? ' <span class="pathok">✔</span>' : '') . '</a>'; $node = new HTML_TreeNode(array( 'text' => $text, 'icon' => $icon, 'expandedIcon' => $eicon, 'expanded' => false )); if (!empty($folder['children'])) { if ($cnodes = $this->make_root_folder_select_tree($folder['children'], $npath)) { for ($j = 0; $j < count($cnodes); $j++) { $node->addItem($cnodes[$j]); } } } $nodes[] = $node; } return $nodes; }