public function setUp() { TaoPhpUnitTestRunner::initTest(); $this->test = new \core_kernel_classes_Resource('http://myFancyDomain.com/myGreatResourceUriForTest'); $this->item = new \core_kernel_classes_Resource('http://myFancyDomain.com/myGreatResourceUriForItem'); $this->item->setPropertyValue(new \core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemModel'), 'http://www.tao.lu/Ontologies/TAOItem.rdf#QTI'); $this->testModel = new TestModel(); $this->storage = \tao_models_classes_service_FileStorage::singleton(); $this->testModel->save($this->test, array()); }
/** * @return tao_models_classes_service_FileStorage */ public static function singleton() { if (is_null(self::$instance)) { $config = common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getConfig(self::CONFIG_KEY); $privateFs = new core_kernel_fileSystem_FileSystem($config['private']); $publicFs = new core_kernel_fileSystem_FileSystem($config['public']); $accessProvider = WebsourceManager::singleton()->getWebsource($config['provider']); self::$instance = new self($privateFs, $publicFs, $accessProvider); } return self::$instance; }
public function testFileStorage() { $storage = tao_models_classes_service_FileStorage::singleton(); $publicFolder1 = $storage->spawnDirectory(true); $publicFolder2 = $storage->spawnDirectory(true); $privateFolder = $storage->spawnDirectory(false); $this->assertTrue($publicFolder1->isPublic()); $this->assertTrue(file_exists($publicFolder1->getPath())); $this->assertTrue($publicFolder1->isPublic()); $this->assertTrue(file_exists($publicFolder2->getPath())); $this->assertNotEqual($publicFolder1->getPath(), $publicFolder2->getPath()); $this->assertFalse($privateFolder->isPublic()); $this->assertTrue(file_exists($privateFolder->getPath())); }
public function run() { $publicDataPath = FILES_PATH . 'tao' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR; $privateDataPath = FILES_PATH . 'tao' . DIRECTORY_SEPARATOR . 'private' . DIRECTORY_SEPARATOR; if (file_exists($publicDataPath)) { helpers_File::emptyDirectory($publicDataPath); } if (file_exists($privateDataPath)) { helpers_File::emptyDirectory($privateDataPath); } $publicFs = tao_models_classes_FileSourceService::singleton()->addLocalSource('public service storage', $publicDataPath); $privateFs = tao_models_classes_FileSourceService::singleton()->addLocalSource('private service storage', $privateDataPath); $provider = tao_models_classes_fsAccess_TokenAccessProvider::spawnProvider($publicFs); tao_models_classes_service_FileStorage::configure($privateFs, $publicFs, $provider); }
public function getPrevious($compilationId) { if (!isset($this->previousCache[$compilationId])) { $previous = false; $dir = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($compilationId); $json = $dir->getFile('data.json')->read(); $config = json_decode($json, true); if (!is_array($config)) { throw new \common_exception_Error('Unable to load compilation data for ' . $compilationId); } if (isset($config['previous'])) { $previous = $config['previous']; } $this->previousCache[$compilationId] = $previous; } return $this->previousCache[$compilationId]; }
/** * export a compiled delivery into an archive * * @param core_kernel_classes_Resource $compiledDelivery * @throws Exception * @return string */ public static function exportCompiledDelivery(core_kernel_classes_Resource $compiledDelivery) { $fileName = tao_helpers_Display::textCleaner($compiledDelivery->getLabel()) . '.zip'; $path = tao_helpers_File::concat(array(tao_helpers_Export::getExportPath(), $fileName)); if (!tao_helpers_File::securityCheck($path, true)) { throw new Exception('Unauthorized file name'); } $zipArchive = new ZipArchive(); if ($zipArchive->open($path, ZipArchive::CREATE) !== true) { throw new Exception('Unable to create archive at ' . $path); } $taoDeliveryVersion = common_ext_ExtensionsManager::singleton()->getInstalledVersion('taoDelivery'); $data = array('dir' => array(), 'label' => $compiledDelivery->getLabel(), 'version' => $taoDeliveryVersion); $directories = $compiledDelivery->getPropertyValues(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_DIRECTORY)); foreach ($directories as $id) { $directory = tao_models_classes_service_FileStorage::singleton()->getDirectoryById($id); tao_helpers_File::addFilesToZip($zipArchive, $directory->getPath(), $directory->getRelativePath()); $data['dir'][$id] = $directory->getRelativePath(); } $runtime = $compiledDelivery->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME)); $serviceCall = tao_models_classes_service_ServiceCall::fromResource($runtime); $data['runtime'] = base64_encode($serviceCall->serializeToString()); $rdfExporter = new tao_models_classes_export_RdfExporter(); $rdfdata = $rdfExporter->getRdfString(array($compiledDelivery)); if (!$zipArchive->addFromString('delivery.rdf', $rdfdata)) { throw common_Exception('Unable to add metadata to exported delivery assembly'); } $data['meta'] = 'delivery.rdf'; $content = json_encode($data); //'<?php return '.common_Utils::toPHPVariableString($data).";"; if (!$zipArchive->addFromString(self::MANIFEST_FILE, $content)) { $zipArchive->close(); unlink($path); throw common_Exception('Unable to add manifest to exported delivery assembly'); } $zipArchive->close(); return $path; }
/** * Get file storage to test * Set service locator to have fileSystem with test adapters * Set publicFs & privateFs to match with adapters * * @return \tao_models_classes_service_FileStorage */ public function getFileStorage() { $fileStorage = new \tao_models_classes_service_FileStorage([\tao_models_classes_service_FileStorage::OPTION_PRIVATE_FS => $this->adapterFixture]); $fileStorage->setServiceLocator($this->getServiceLocatorWithFileSystem()); return $fileStorage; }
/** * Extracts the path of the compilation directory */ protected function initCompilationDirectory() { $fileStorage = \tao_models_classes_service_FileStorage::singleton(); $directoryIds = explode('|', $this->getTestCompilationUri()); $directories = array('private' => $fileStorage->getDirectoryById($directoryIds[0]), 'public' => $fileStorage->getDirectoryById($directoryIds[1])); $this->compilationDirectory = $directories; }
/** * (non-PHPdoc) * @see taoTests_models_classes_TestModel::deleteContent() */ public function deleteContent(core_kernel_classes_Resource $test) { /** @var \core_kernel_classes_Literal $directoryId */ $directoryId = $test->getOnePropertyValue($this->getProperty(TEST_TESTCONTENT_PROP)); if (is_null($directoryId)) { throw new \common_exception_FileSystemError(__('Unknown test directory')); } $directory = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryId->literal); $directory->deleteSelf(); $test->removePropertyValues($this->getProperty(TEST_TESTCONTENT_PROP)); }
/** * Create Assembly from template * * @author Lionel Lecaque, lionel@taotesting.com * @param \core_kernel_classes_Resource $deliveryTemplate * @return common_report_Report */ private function getAssemblyFromTemplate($deliveryTemplate) { $storage = \tao_models_classes_service_FileStorage::singleton(); $assemblyServiceMock = $this->getMockBuilder('oat\\taoDeliveryTemplate\\model\\TemplateAssemblyService')->setMethods(array('getCompiler'))->setMockClassName('TemplateAssemblyService_Mock')->disableOriginalConstructor()->getMock(); $assemblyServiceMock->expects($this->any())->method('getCompiler')->will($this->returnValue($this->getCompilerMock($this->content, $storage))); $report = $assemblyServiceMock->createAssemblyFromTemplate($deliveryTemplate); return $report; }
/** * Retrieve the Test Definition the test session is built from as an AssessmentTest object. * * @param string $qtiTestCompilation (e.g. <i>'http://sample/first.rdf#i14363448108243883-|http://sample/first.rdf#i14363448109065884+'</i>) * * @return AssessmentTest The AssessmentTest object the current test session is built from. */ public static function getTestDefinition($qtiTestCompilation) { $directoryIds = explode('|', $qtiTestCompilation); $dirPath = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[0])->getPath(); $testFilePath = $dirPath . TAOQTITEST_COMPILED_FILENAME; common_Logger::d("Loading QTI-PHP file at '{$testFilePath}'."); $doc = new PhpDocument(); $doc->load($testFilePath); return $doc->getDocumentComponent(); }
/** * Returns a directory from the service file storage * * @param string $id * @return tao_models_classes_service_StorageDirectory */ protected function getDirectory($id) { return tao_models_classes_service_FileStorage::singleton()->getDirectoryById($id); }
public function testCompileComplete() { $itemClass = new \core_kernel_classes_Class(TAO_ITEM_CLASS); $report = $this->importService->importXhtmlFile($this->dataFolder . 'complete.zip', $itemClass, false); $complete = $report->getData(); $this->assertInstanceOf('\\core_kernel_classes_Resource', $complete); $storage = \tao_models_classes_service_FileStorage::singleton(); $compiler = new OwiItemCompiler($complete, $storage); $report = $compiler->compile(); $this->assertEquals($report->getType(), \common_report_Report::TYPE_SUCCESS, 'this test try to retrieve http://forge.taotesting.com/themes/tao-theme/images/logo.gif check if available'); $serviceCall = $report->getData(); $this->assertNotNull($serviceCall); $this->assertInstanceOf('\\tao_models_classes_service_ServiceCall', $serviceCall); $itemService = \taoItems_models_classes_ItemsService::singleton(); $this->assertTrue($itemService->deleteItem($complete)); }
/** * Get file storage mock for testDeleteDeliveryDirectory() * * @return object */ protected function getFileSystemWithServiceLocator() { $fileStorage = \tao_models_classes_service_FileStorage::singleton(); $adapter = $fileStorage->getOption('private'); $adaptersFixture = array('filesPath' => $this->sampleDir, 'adapters' => array($adapter => array('class' => 'Local', 'options' => array('root' => $this->directoryPath)))); $reflectionClass = new \ReflectionClass(\tao_models_classes_service_FileStorage::class); $reflectionProperty = $reflectionClass->getProperty('privateFs'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($fileStorage, $this->getFileSystemMock($adapter, $this->directoryPath)); $fileSystemService = new FileSystemService($adaptersFixture); $smProphecy = $this->prophesize(ServiceLocatorInterface::class); $smProphecy->get(FileSystemService::SERVICE_ID)->willReturn($fileSystemService); $fileStorage->setServiceLocator($smProphecy->reveal()); return $fileStorage; }
/** * * @param core_kernel_classes_Resource $test * @param array $itemUris * @return boolean */ public function save(core_kernel_classes_Resource $test, array $itemUris) { $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); //get Directory ID $directoryId = $test->getOnePropertyValue($propInstanceContent); //null so create one if (is_null($directoryId)) { $directory = \tao_models_classes_service_FileStorage::singleton()->spawnDirectory(true); } else { //get the real directory (or the encoded items if an old test) $directory = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryId->literal); if (!is_dir($directory->getPath())) { //create a new directory if items are stored in content $directory = \tao_models_classes_service_FileStorage::singleton()->spawnDirectory(true); } } $file = $directory->getPath() . 'content.json'; file_put_contents($file, json_encode($itemUris)); return $test->editPropertyValues($propInstanceContent, $directory->getId()); }
/** * Returns a directory that is not accessible to the client * * @return tao_models_classes_service_StorageDirectory */ protected function spawnPrivateDirectory() { return $this->compilationStorage->spawnDirectory(false); }
/** * Get rubric to be printed * Rubric is considered printed if it included to the section which has an item tagged by specified tag * (@see ) * * @param \taoDelivery_models_classes_execution_DeliveryExecution $deliveryExecution * @return string */ public function getPrintableRubric(\taoDelivery_models_classes_execution_DeliveryExecution $deliveryExecution) { $testSessionService = ServiceManager::getServiceManager()->get(TestSessionService::SERVICE_ID); $session = $testSessionService->getTestSession($deliveryExecution); $inputParameters = $testSessionService->getRuntimeInputParameters($deliveryExecution); $testDefinition = \taoQtiTest_helpers_Utils::getTestDefinition($inputParameters['QtiTestCompilation']); $sections = $testDefinition->getComponentsByClassName('assessmentSection'); $tag = $this->getOption(self::OPTION_PRINTABLE_RUBRIC_TAG); $directoryIds = explode('|', $inputParameters['QtiTestCompilation']); $compilationDirs = array('private' => \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[0]), 'public' => \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[1])); $rubrics = []; // -- variables used in the included rubric block templates. // base path (base URI to be used for resource inclusion). $basePathVarName = TAOQTITEST_BASE_PATH_NAME; ${$basePathVarName} = $compilationDirs['public']->getPublicAccessUrl(); // state name (the variable to access to get the state of the assessmentTestSession). $stateName = TAOQTITEST_RENDERING_STATE_NAME; ${$stateName} = $session; // views name (the variable to be accessed for the visibility of rubric blocks). $viewsName = TAOQTITEST_VIEWS_NAME; ${$viewsName} = array(View::CANDIDATE); foreach ($sections as $section) { $assessmentItemsRef = $section->getComponentsByClassName('assessmentItemRef'); foreach ($assessmentItemsRef as $item) { foreach ($item->getCategories() as $category) { if ($category === $tag) { foreach ($section->getRubricBlockRefs() as $rubric) { ob_start(); include $compilationDirs['private']->getPath() . $rubric->getHref(); $rubrics[] = ob_get_clean(); } } } } } return $rubrics; }
/** * Retrieve the Test Definition the test session is built from as an AssessmentTest object. * * @param string $qtiTestCompilation (e.g. <i>'http://sample/first.rdf#i14363448108243883-|http://sample/first.rdf#i14363448109065884+'</i>) * * @return AssessmentTest The AssessmentTest object the current test session is built from. */ public static function getTestDefinition($qtiTestCompilation) { $directoryIds = explode('|', $qtiTestCompilation); $data = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[0])->read(TAOQTITEST_COMPILED_FILENAME); common_Logger::d("Loading QTI-PHP file from stream"); $doc = new PhpDocument(); $doc->loadFromString($data); return $doc->getDocumentComponent(); }
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg (under the project TAO & TAO2); * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung (under the project TAO-TRANSFER); * 2009-2012 (update and modification) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV); * */ /* * This post-installation script creates a new local file source for file uploaded * by end-users through the TAO GUI. */ $publicDataPath = FILES_PATH . 'tao' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR; $privateDataPath = FILES_PATH . 'tao' . DIRECTORY_SEPARATOR . 'private' . DIRECTORY_SEPARATOR; if (file_exists($publicDataPath)) { helpers_File::emptyDirectory($publicDataPath); } if (file_exists($privateDataPath)) { helpers_File::emptyDirectory($privateDataPath); } $publicFs = tao_models_classes_FileSourceService::singleton()->addLocalSource('public service storage', $publicDataPath); $privateFs = tao_models_classes_FileSourceService::singleton()->addLocalSource('private service storage', $privateDataPath); $websource = TokenWebSource::spawnWebsource($publicFs); tao_models_classes_service_FileStorage::configure($privateFs, $publicFs, $websource);
public function __construct() { $this->storage = tao_models_classes_service_FileStorage::singleton(); }