public static function suite() { $oResult = new PHPUnit_Framework_TestSuite("ResourceFinder test suite"); foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) { if (StringUtil::endsWith($sFileName, "Tests.php") && (StringUtil::startsWith($sFileName, "ResourceFinder") || StringUtil::startsWith($sFileName, "FileResource") || StringUtil::startsWith($sFileName, "ResourceIncluder"))) { $oResult->addTestFile($sFilePath); } } return $oResult; }
public static function suite() { $oResult = new PHPUnit_Framework_TestSuite("Complete test suite"); foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) { if (StringUtil::endsWith($sFileName, ".php") && StringUtil::startsWith($sFileName, "Test") && !StringUtil::startsWith($sFileName, "TestUtil") && $sFilePath !== __FILE__) { require_once $sFilePath; $oResult->addTest(call_user_func(array(substr($sFileName, 0, -strlen('.php')), "suite"))); } } return $oResult; }
private static function findInPathByExpressions(&$aResult, $aExpressions, $sPath, $sInstancePrefix, $sParentName = null, $sRelativePath = null) { if (count($aExpressions) === 0) { return; } $sPathExpression = array_shift($aExpressions); $bAllowPathItemToBeSkipped = is_array($sPathExpression); if ($bAllowPathItemToBeSkipped) { if (count($aExpressions) === 0) { //Add the current path (parent recursive invocation added nothing because there were still items on the stack, next invocation would return empty since the stack is empty) $aResult[$sRelativePath] = new FileResource($sPath, $sInstancePrefix, $sRelativePath); } else { //call current function without the optional element self::findInPathByExpressions($aResult, $aExpressions, $sPath, $sInstancePrefix, $sParentName, $sRelativePath); } if (count($sPathExpression) === 0) { //emtpy array means look recursively in all subdirs => put the any-item-specifier (true) and the empty array on the local stack array_unshift($aExpressions, array()); $sPathExpression = null; } else { //array has a path element => put the optional argument(s) on the local stack $sNextItem = array_shift($sPathExpression); $aExpressions = array_merge($sPathExpression, $aExpressions); $sPathExpression = $sNextItem; } } if (!is_dir($sPath)) { return; } if ($sParentName !== null && is_string($sPathExpression)) { $sPathExpression = str_replace('${parent_name}', $sParentName, $sPathExpression); $sPathExpression = str_replace('${parent_name_camelized}', StringUtil::camelize($sParentName, true), $sPathExpression); } if (is_string($sPathExpression) && !StringUtil::startsWith($sPathExpression, "/")) { //Take the shortcut when only dealing with a static file name $sFilePath = "{$sPath}/{$sPathExpression}"; if ($sRelativePath === null) { $sNextRelativePath = $sPathExpression; } else { $sNextRelativePath = "{$sRelativePath}/{$sPathExpression}"; } if (file_exists($sFilePath)) { if (count($aExpressions) > 0) { self::findInPathByExpressions($aResult, $aExpressions, $sFilePath, $sInstancePrefix, $sPathExpression, $sNextRelativePath); } else { $aResult[$sNextRelativePath] = new FileResource($sFilePath, $sInstancePrefix, $sNextRelativePath); } } } else { foreach (ResourceFinder::getFolderContents($sPath) as $sFileName => $sFilePath) { if ($sPathExpression === self::WILDCARD_ANY || $sPathExpression === self::WILDCARD_FILE && is_file($sFilePath) || $sPathExpression === self::WILDCARD_DIR && is_dir($sFilePath) || is_string($sPathExpression) && preg_match($sPathExpression, $sFileName) !== 0) { $sNextRelativePath = $sFileName; if ($sRelativePath !== null) { $sNextRelativePath = "{$sRelativePath}/{$sFileName}"; } if (count($aExpressions) > 0) { self::findInPathByExpressions($aResult, $aExpressions, $sFilePath, $sInstancePrefix, $sFileName, $sNextRelativePath); } else { $aResult[$sNextRelativePath] = new FileResource($sFilePath, $sInstancePrefix, $sNextRelativePath); } } } } }
public function getDetail() { // display error info if ($this->iError) { $oTemplate = $this->constructTemplate('error_message'); $oTemplate->replaceIdentifier('error_title', StringPeer::getString('webdav.error_message') . ' ' . $this->sErrorLocation); $oTemplate->replacePstring("error_details", array('dir_name' => $this->sWebdavBaseDirPath), 'webdav.error_' . $this->iError); return $oTemplate; } // display module info if ($this->sFilePath === null) { $oTemplate = $this->constructTemplate('module_info'); if (count($this->aFiles) > 0) { $oTemplate->replaceIdentifier('edit_or_create_message', StringPeer::getString('webdav.choose_or_create')); } $oTemplate->replaceIdentifier('create_link', TagWriter::quickTag('a', array('class' => 'edit_related_link highlight', 'href' => LinkUtil::link('webdav', null, array('action' => 'create'))), StringPeer::getString('webdav.create'))); $oTemplate->replaceIdentifier('user_backend_link', TagWriter::quickTag('a', array('class' => 'edit_related_link highlight', 'href' => LinkUtil::link('users')), StringPeer::getString('module.backend.users'))); return $oTemplate; } $oTemplate = $this->constructTemplate('detail'); $oTemplate->replaceIdentifier('module_info_link', TagWriter::quickTag('a', array('title' => StringPeer::getString('module_info'), 'class' => 'info', 'href' => LinkUtil::link('webdav', null, array('get_module_info' => 'true'))))); if ($this->sFilePath === self::NEW_DIR_IDENTIFIER) { $aDirPermissionsGroupIds = array(); } else { $aDirPermissionsGroupIds = DirectoryPermissionPeer::getPermissionGroupIdsByFileName($this->sFilePath); $oDeleteTemplate = $this->constructTemplate("delete_button", true); $oDeleteTemplate->replacePstring("delete_item", array('name' => $this->sFilePath)); $oTemplate->replaceIdentifier("delete_button", $oDeleteTemplate, null, Template::LEAVE_IDENTIFIERS); // show users with usergroups $oUsersWithGroups = UserPeer::getUsersWithRights($aDirPermissionsGroupIds); $oUsersTemplate = $this->constructTemplate('detail_users'); if (count($oUsersWithGroups) > 0) { foreach ($oUsersWithGroups as $oUser) { $oUsersTemplate->replaceIdentifierMultiple('users', TagWriter::quickTag('a', array('class' => 'highlight', 'title' => StringPeer::getString('user.edit'), 'class' => 'webdav_files', 'href' => LinkUtil::link(array('users', $oUser->getId()), null, array('check_userkind' => true))), $oUser->getFullName() . ' [Benutzername:' . $oUser->getUserName() . ']')); } } else { $oUsersTemplate->replaceIdentifier('users', TagWriter::quickTag('div', array('class' => 'webdav_files'), StringPeer::getString('webdav.no_users_with_permission_message'))); } $oUsersTemplate->replaceIdentifier('user_backend_link', TagWriter::quickTag('a', array('class' => 'edit_related_link', 'href' => LinkUtil::link('users', null, array('check_userkind' => 'true'))), StringPeer::getString('user.edit'))); $oTemplate->replaceIdentifier("users_with_permission", $oUsersTemplate); $sServerPath = LinkUtil::absoluteLink(substr($this->sWebdavBaseDirPath, strrpos($this->sWebdavBaseDirPath, '/')) . '/' . $this->sFilePath); $oTemplate->replaceIdentifier("server_address", $sServerPath); // show files in current dir $aDirFiles = array_keys(ResourceFinder::getFolderContents($this->sWebdavBaseDirPath . '/' . $this->sFilePath)); if (count($aDirFiles) > 0) { $oFilesTemplate = $this->constructTemplate("detail_files"); $sWebDavDirPath = $this->sWebdavBaseDirPath . '/' . $this->sFilePath . '/'; foreach ($aDirFiles as $i => $sFilePath) { $iFileSize = filesize($sWebDavDirPath . $sFilePath); $sFileSize = DocumentUtil::getDocumentSize($iFileSize); if (substr($sFileSize, 0, 1) == '0') { $sFileSize = 'unknown'; } $oFilesTemplate->replaceIdentifierMultiple('files', TagWriter::quickTag('div', array('class' => 'webdav_files'), $sFilePath . ' [' . $sFileSize . ']')); } $oTemplate->replaceIdentifier('detail_files', $oFilesTemplate); } } $oTemplate->replaceIdentifier('name', $this->sFilePath); $oTemplate->replaceIdentifier('file_path_old', $this->sFilePath); if (isset($_POST['file_path'])) { $this->sFilePath = $_POST['file_path']; } $oTemplate->replaceIdentifier('file_path', $this->sFilePath === self::NEW_DIR_IDENTIFIER ? '' : $this->sFilePath); $oTemplate->replaceIdentifier('file_path_readonly', $this->sFilePath != self::NEW_DIR_IDENTIFIER ? ' readonly="readonly"' : '', null, Template::NO_HTML_ESCAPE); $aGroups = GroupPeer::getAll(); $oTemplate->replaceIdentifier('group_options', TagWriter::optionsFromObjects($aGroups, 'getId', 'getName', $aDirPermissionsGroupIds, array())); $oTemplate->replaceIdentifier('group_backend_link', TagWriter::quickTag('a', array('class' => 'edit_related_link highlight', 'href' => LinkUtil::link('groups')), StringPeer::getString('group.edit'))); return $oTemplate; }