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'))); }
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')); }
/** * 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)); }