/** * Generate a new Booklet from a specific test * in a specific class and return a report * * @param core_kernel_classes_Resource $test * @param core_kernel_classes_Class $class * @return common_report_Report */ public static function generate(core_kernel_classes_Resource $test, core_kernel_classes_Class $class) { $report = new common_report_Report(common_report_Report::TYPE_SUCCESS); $model = \taoTests_models_classes_TestsService::singleton()->getTestModel($test); if ($model->getUri() != INSTANCE_TEST_MODEL_QTI) { $report->setType(common_report_Report::TYPE_ERROR); $report->setMessage(__('%s is not a QTI test', $test->getLabel())); return $report; } // generate file content $tmpFolder = \tao_helpers_File::createTempDir(); $tmpFile = $tmpFolder . 'test.txt'; $content = ''; foreach (self::getItems($test) as $item) { $content .= self::renderItem($item); } file_put_contents($tmpFile, $content); // generate tao instance $instance = BookletClassService::singleton()->createBookletInstance($class, __('%s Booklet', $test->getLabel()), $tmpFile); \tao_helpers_File::delTree($tmpFolder); // return report with instance $report->setMessage(__('%s created', $instance->getLabel())); $report->setData($instance); return $report; }
public function run() { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('ltiProvider'); if ($ext->isInstalled()) { common_Logger::t('Uninstall ltiProvider'); $db = core_kernel_classes_DbWrapper::singleton(); $sql = "DELETE from extensions where id ='ltiProvider';"; $db->exec($sql); tao_helpers_File::delTree($ext->getConstant('BASE_PATH')); $newExt = common_ext_ExtensionsManager::singleton()->getExtensionById('taoLti'); taoUpdate_models_classes_DataMigrationService::singleton()->installExtension($newExt); } }
/** * (non-PHPdoc) * @see taoTests_models_classes_TestModel::onTestModelSet() */ public function deleteContent(core_kernel_classes_Resource $test) { $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); /** @var \core_kernel_classes_Literal $directoryId */ $directoryId = $test->getOnePropertyValue($propInstanceContent); if (is_null($directoryId)) { throw new \common_exception_FileSystemError(__('Unknown test directory')); } $directory = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryId->literal); if (is_dir($directory->getPath())) { \tao_helpers_File::delTree($directory->getPath()); } $test->removePropertyValues(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); }
protected static function deleteDependencies(\core_kernel_classes_Triple $triple) { if ($triple->predicate == 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContent') { $file = new \core_kernel_versioning_File($triple->object); if ($file->exists()) { $sourceDir = dirname($file->getAbsolutePath()); $file->delete(); \tao_helpers_File::delTree($sourceDir); } } elseif (CloneHelper::isFileReference($triple)) { $file = new \core_kernel_versioning_File($triple->object); if ($file->exists()) { $file->delete(); } } }
public function testSend() { $testfolder = tao_helpers_File::createTempDir(); $expectedFilePath = $testfolder . 'testidentifier' . DIRECTORY_SEPARATOR . 'message.html'; $this->assertFileNotExists($expectedFilePath); $userMock = $this->prophesize('oat\\oatbox\\user\\User'); $userMock->getIdentifier()->willReturn('testidentifier'); $userMock->getIdentifier()->should(new CallTimesPrediction(1)); $messageMock = $this->prophesize('oat\\tao\\model\\messaging\\Message'); $messageMock->getTo()->willReturn($userMock->reveal()); $messageMock->getTo()->should(new CallTimesPrediction(1)); $messageMock->getBody()->willReturn('testBody'); $messageMock->getBody()->should(new CallTimesPrediction(1)); $transporter = new FileSink(array(FileSink::CONFIG_FILEPATH => $testfolder)); $result = $transporter->send($messageMock->reveal()); $this->assertTrue($result); $this->assertFileExists($expectedFilePath); $messageContent = file_get_contents($expectedFilePath); $this->assertEquals('testBody', $messageContent); $userMock->checkProphecyMethodsPredictions(); $messageMock->checkProphecyMethodsPredictions(); tao_helpers_File::delTree($testfolder); $this->assertFalse(is_dir($testfolder)); }
/** * Import a Portable element from an uploaded zip file * * @param $type * @param $zipFile * @return mixed * @throws PortableElementInconsistencyModelException */ public function import($type, $zipFile) { /** @var PortableElementPackageParser $parser */ $parser = $this->getPortableFactory()->getModel($type)->getPackageParser(); $source = $parser->extract($zipFile); $object = $parser->getModel()->createDataObject($parser->getManifestContent($zipFile)); $this->registerModel($object, $source); \tao_helpers_File::delTree($source); return $object; }
/** * Delete the content of a QTI test * @param core_kernel_classes_Resource $test * @throws common_exception_Error */ public function deleteContent(core_kernel_classes_Resource $test) { $content = $test->getOnePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); if (!is_null($content)) { $file = new core_kernel_file_File($content); try { $path = $file->getAbsolutePath(); if (is_dir($path)) { if (!tao_helpers_File::delTree($path)) { throw new common_exception_Error("Unable to remove test content directory located at '" . $file->getAbsolutePath() . "'."); } } } catch (common_Exception $e) { // Empty file... } $file->delete(); $test->removePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $file); } }
/** * Remove directory of $adapterFixture */ public function tearDown() { \tao_helpers_File::delTree($this->privateDir); }
public function testTracing() { $events = array('{"name":"div","type":"click","time":"1288780765981","id":"qunit-fixture"}', '{"name":"BUSINESS","type":"TEST","time":"1288780765982","id":"12"}', '{"name":"h2","type":"click","time":"1288780766000","id":"qunit-banner"}', '{"name":"h1","type":"click","time":"1288780765999","id":"qunit-header"}'); $folder = tao_helpers_File::createTempDir(); $processId = '123456789'; $eventFilter = $this->eventsService->getEventList($this->eventFile, 'server'); $this->assertTrue($this->eventsService->traceEvent($events, $processId, $folder, $eventFilter)); $this->assertTrue($this->eventsService->traceEvent($events, $processId, $folder)); $this->assertTrue(file_exists($folder . '/' . $processId . '_0.xml')); foreach (glob($folder . '/' . $processId . '*') as $trace_file) { if (preg_match('/(xml|lock)$/', $trace_file)) { unlink($trace_file); } } tao_helpers_File::delTree($folder); }
public function testIsIdentical() { $testfolder = tao_helpers_File::createTempDir(); $this->assertTrue(is_dir($testfolder)); $zip = new ZipArchive(); $this->assertTrue($zip->open(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . 'fileHelper.zip')); $this->assertTrue($zip->extractTo($testfolder)); $zip->close(); $reference = $testfolder . 'reference'; $this->assertTrue(is_dir($reference)); $testContent = $testfolder . DIRECTORY_SEPARATOR . 'testContent'; $testEmptyDir = $testfolder . DIRECTORY_SEPARATOR . 'testEmptyDir'; $testIdent = $testfolder . DIRECTORY_SEPARATOR . 'testIdent'; $testMissingDir = $testfolder . DIRECTORY_SEPARATOR . 'testMissingDir'; $testRenamedFile = $testfolder . DIRECTORY_SEPARATOR . 'testRenamedFile'; $testRenamedEmptyDir = $testfolder . DIRECTORY_SEPARATOR . 'testRenamedEmptyDir'; $this->assertTrue(tao_helpers_File::isIdentical($reference, $reference)); $this->assertTrue(tao_helpers_File::isIdentical($reference, $testIdent)); $this->assertFalse(tao_helpers_File::isIdentical($reference, $testContent)); $this->assertFalse(tao_helpers_File::isIdentical($reference, $testEmptyDir)); $this->assertFalse(tao_helpers_File::isIdentical($reference, $testMissingDir)); $this->assertFalse(tao_helpers_File::isIdentical($reference, $testRenamedFile)); $this->assertFalse(tao_helpers_File::isIdentical($reference, $testRenamedEmptyDir)); $this->assertTrue(tao_helpers_File::delTree($testfolder)); $this->assertFalse(is_dir($testfolder)); }
public function testExport() { $packageValid = dirname(__FILE__) . '/samples/package/likertScaleInteraction_v1.0.0'; $pciModel = new PciModel('likertScaleInteraction', '1.0.0'); $pciModel->exchangeArray(json_decode(file_get_contents($packageValid . DIRECTORY_SEPARATOR . PciModel::PCI_MANIFEST), true)); $service = new PortableElementService(); $service->setServiceLocator(ServiceManager::getServiceManager()); $reflectionClass = new \ReflectionClass(PortableElementService::class); $reflectionMethod = $reflectionClass->getMethod('getRegistry'); $reflectionMethod->setAccessible(true); $registry = $reflectionMethod->invoke($service, new PciModel()); $registry->setSource($packageValid); $registry->register($pciModel); $exportDirectory = $registry->export($pciModel); $parser = new PortableElementPackageParser($exportDirectory); $parser->setModel(new PciModel()); $source = $parser->extract(); $original = $this->fillArrayWithFileNodes(new \DirectoryIterator($packageValid)); $exported = $this->fillArrayWithFileNodes(new \DirectoryIterator($source)); $this->assertEquals(preg_replace('/\\s+/', '', file_get_contents($packageValid . DIRECTORY_SEPARATOR . PciModel::PCI_MANIFEST)), preg_replace('/\\s+/', '', file_get_contents($source . DIRECTORY_SEPARATOR . PciModel::PCI_MANIFEST))); $this->assertTrue(empty($this->array_diff_assoc_recursive($original, $exported))); $registry->unregister($pciModel); \tao_helpers_File::delTree($source); }
/** * Removes the temporary directory */ public static function tearDownAfterClass() { tao_helpers_File::delTree(self::$tmpDir); }
public function testCompile() { //test with items $config = array('previous' => true); $items = array($this->item->getUri()); $this->testModel->save($this->test, array('itemUris' => $items, 'config' => $config)); $waitingReport = new \common_report_Report(\common_report_Report::TYPE_SUCCESS); $serviceCall = $this->getMockBuilder('tao_models_classes_service_ServiceCall')->disableOriginalConstructor()->setMethods(array('serializeToString'))->getMock(); $serviceCall->expects($this->once())->method('serializeToString')->willReturn('greatString'); $waitingReport->setData($serviceCall); $testCompiler = $this->getMockBuilder('oat\\taoTestLinear\\model\\TestCompiler')->setConstructorArgs(array($this->test, $this->storage))->setMethods(array('subCompile', 'spawnPrivateDirectory'))->getMock(); $testCompiler->expects($this->once())->method('subCompile')->willReturn($waitingReport); //will spawn a new directory and store the content file $directoryMock = $this->getMockBuilder('tao_models_classes_service_StorageDirectory')->disableOriginalConstructor()->setMethods(array('getPath'))->getMock(); $tmpDir = \tao_helpers_File::createTempDir(); $this->assertFileExists($tmpDir); $directoryMock->expects($this->once())->method('getPath')->willReturn($tmpDir); $testCompiler->expects($this->once())->method('spawnPrivateDirectory')->willReturn($directoryMock); $report = $testCompiler->compile(); $this->assertEquals(__('Test Compilation'), $report->getMessage(), __('Compilation should work')); $this->assertFileExists($tmpDir . 'data.json', __('Compilation file not created')); $compile = '{"items":{"http:\\/\\/myFancyDomain.com\\/myGreatResourceUriForItem":"greatString"},"previous":true}'; $this->assertEquals($compile, file_get_contents($tmpDir . 'data.json', __('File content error'))); \tao_helpers_File::delTree($tmpDir); $this->assertFileNotExists($tmpDir); }
public function tearDown() { if (file_exists($this->directoryPath)) { \tao_helpers_File::delTree($this->directoryPath); } }