/**
  * (non-PHPdoc)
  * @see tao_models_classes_Compiler::compile()
  */
 public function compile()
 {
     $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Test Compilation'));
     $map = array();
     $model = new TestModel();
     foreach ($model->getItems($this->getResource()) as $item) {
         $subReport = $this->subCompile($item);
         $report->add($subReport);
         if ($subReport->getType() == common_report_Report::TYPE_SUCCESS) {
             $serviceCall = $subReport->getdata();
             $map[$item->getUri()] = $serviceCall->serializeToString();
         } else {
             $report->setType(common_report_Report::TYPE_ERROR);
         }
     }
     if (count($map) === 0) {
         $report->setType(common_report_Report::TYPE_ERROR);
         $report->setMessage(__("A Test must contain at least one item to be compiled."));
     }
     if ($report->getType() === common_report_Report::TYPE_SUCCESS) {
         $config = array();
         $private = $this->spawnPrivateDirectory();
         $file = $private->getPath() . 'data.json';
         $config['items'] = $map;
         $config = array_merge($config, $model->getConfig($this->getResource()));
         file_put_contents($file, json_encode($config));
         $report->setData($this->buildServiceCall($private));
     }
     return $report;
 }
 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();
     if (!file_exists(sys_get_temp_dir() . '/sample/compile/')) {
         mkdir(sys_get_temp_dir() . '/sample/compile/', 0777, true);
     }
     $directoryMock->expects($this->once())->method('getPath')->willReturn(sys_get_temp_dir() . '/sample/compile/');
     $testCompiler->expects($this->once())->method('spawnPrivateDirectory')->willReturn($directoryMock);
     $report = $testCompiler->compile();
     $this->assertEquals(__('Test Compilation'), $report->getMessage(), __('Compilation should work'));
     $this->assertFileExists(sys_get_temp_dir() . '/sample/compile/data.json', __('Compilation file not created'));
     $compile = '{"items":{"http:\\/\\/myFancyDomain.com\\/myGreatResourceUriForItem":"greatString"},"previous":true}';
     $this->assertEquals($compile, file_get_contents(sys_get_temp_dir() . '/sample/compile/data.json', __('File content error')));
 }
Exemplo n.º 3
0
 /**
  * 
  * @param string $initialVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $this->skip('0.1', '0.1.5');
     if ($this->isVersion('0.1.5')) {
         OntologyUpdater::syncModels();
         $testModelService = new TestModel();
         $testModelService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(TestModel::SERVICE_ID, $testModelService);
         $this->setVersion('0.2.0');
     }
     if ($this->isVersion('0.2.0')) {
         $this->getServiceManager()->register('taoTestLinear/storage', new DeprecatedStorage());
         $testModelService = $this->getServiceManager()->get(TestModel::SERVICE_ID);
         $testModelService->setOption(TestModel::OPTION_STORAGE, 'taoTestLinear/storage');
         $this->getServiceManager()->register(TestModel::SERVICE_ID, $testModelService);
         $this->setVersion('1.0.0');
     }
 }
 public function testSaveNew()
 {
     $testMock = $this->getMockBuilder('core_kernel_classes_Resource')->disableOriginalConstructor()->setMethods(array('getOnePropertyValue', 'editPropertyValues'))->getMock();
     $propInstanceContent = new \core_kernel_classes_Property(TEST_TESTCONTENT_PROP);
     $itemUris = array("http://tao.localdomain:8888/tao.rdf#i9988776057890756", "http://tao.localdomain:8888/tao.rdf#i0099886059556677");
     //new stock method (in file)
     $directoryId = "MyGreatDirectoryId";
     $returnValue = new \core_kernel_classes_Literal($directoryId);
     $testMock->expects($this->once())->method('getOnePropertyValue')->with($propInstanceContent)->willReturn($returnValue);
     $testMock->expects($this->once())->method('editPropertyValues')->with($propInstanceContent, $directoryId)->willReturn(true);
     //will spawn a new directory and store the content file
     $storageMock = $this->getMockBuilder('tao_models_classes_service_FileStorage')->disableOriginalConstructor()->setMethods(array('getDirectoryById'))->getMock();
     $ref = new \ReflectionProperty('tao_models_classes_service_FileStorage', 'instance');
     $ref->setAccessible(true);
     $ref->setValue(null, $storageMock);
     $directoryMock = $this->getMockBuilder('tao_models_classes_service_StorageDirectory')->disableOriginalConstructor()->setMethods(array('getPath', 'getId'))->getMock();
     $directoryMock->expects($this->exactly(2))->method('getPath')->willReturn(sys_get_temp_dir() . '/sample/');
     $directoryMock->expects($this->once())->method('getId')->willReturn($directoryId);
     $storageMock->expects($this->once())->method('getDirectoryById')->with($directoryId)->willReturn($directoryMock);
     $edit = $this->testModel->save($testMock, $itemUris);
     $file = json_decode(file_get_contents(sys_get_temp_dir() . '/sample/content.json'));
     $this->assertEquals(true, $edit, __('Should edit the property value'));
     $this->assertEquals($itemUris, $file, __('The content file doesn\'t contain the right items'));
 }
Exemplo n.º 5
0
 /**
  * save the related items from the checkbox tree or from the sequence box
  * @return void
  */
 public function saveItems()
 {
     $test = new \core_kernel_classes_Resource($this->getRequestParameter('uri'));
     if (!tao_helpers_Request::isAjax()) {
         throw new \Exception("wrong request mode");
     }
     $itemUris = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost();
     foreach ($this->getRequestParameters() as $key => $value) {
         if (preg_match("/^instance_/", $key)) {
             $itemUris[] = tao_helpers_Uri::decode($value);
         }
     }
     $config = array('previous' => $this->getRequestParameter('previous') === "true");
     $testContent = array('itemUris' => $itemUris, 'config' => $config);
     $model = new TestModel();
     $saved = $model->save($test, $testContent);
     $this->returnJson(array('saved' => $saved));
 }