/** * @covers Alchemy\Phrasea\Controller\Prod\Property::changeStatus */ public function testChangeStatus() { $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/cestlafete.jpg'), self::$DI['collection']); $record = \record_adapter::createFromFile($file, self::$DI['app']); $record2 = \record_adapter::createFromFile($file, self::$DI['app']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); $story->appendChild($record2); self::$DI['client']->request('POST', '/prod/records/property/status/', ['apply_to_children' => [$story->get_sbas_id() => true], 'status' => [$record->get_sbas_id() => [6 => true, 8 => true, 11 => true]], 'lst' => implode(';', [$record->get_serialize_key(), $story->get_serialize_key()])]); $response = self::$DI['client']->getResponse(); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); $this->assertTrue($datas['success']); $this->assertArrayHasKey('updated', $datas); $record = new \record_adapter(self::$DI['app'], $record->get_sbas_id(), $record->get_record_id()); $story = new \record_adapter(self::$DI['app'], $story->get_sbas_id(), $story->get_record_id()); $recordStatus = strrev($record->get_status()); $storyStatus = strrev($story->get_status()); $this->assertEquals(1, substr($recordStatus, 6, 1)); $this->assertEquals(1, substr($recordStatus, 8, 1)); $this->assertEquals(1, substr($recordStatus, 11, 1)); $this->assertEquals(1, substr($storyStatus, 6, 1)); $this->assertEquals(1, substr($storyStatus, 8, 1)); $this->assertEquals(1, substr($storyStatus, 11, 1)); foreach ($story->get_children() as $child) { $childStatus = strrev($child->get_status()); $this->assertEquals(1, substr($childStatus, 6, 1)); $this->assertEquals(1, substr($childStatus, 8, 1)); $this->assertEquals(1, substr($childStatus, 11, 1)); } $record->delete(); $record2->delete(); $story->delete(); unset($response, $datas, $story, $record, $record2, $story, $file); }
public function testRemoveElementFromStory() { $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); $records = [self::$DI['record_1'], self::$DI['record_2']]; foreach ($records as $record) { $story->appendChild($record); } $totalRecords = $story->get_children()->get_count(); $n = 0; foreach ($records as $record) { /* @var $record \record_adapter */ $route = sprintf("/prod/story/%s/%s/delete/%s/%s/", $story->get_sbas_id(), $story->get_record_id(), $record->get_sbas_id(), $record->get_record_id()); if ($n % 2 === 0) { $crawler = self::$DI['client']->request('POST', $route); $response = self::$DI['client']->getResponse(); $this->assertEquals(302, $response->getStatusCode()); } else { $crawler = self::$DI['client']->request('POST', $route, [], [], ["HTTP_ACCEPT" => "application/json"]); $response = self::$DI['client']->getResponse(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getContent(), true); $this->assertTrue($data['success']); } $n++; $this->assertEquals($totalRecords - $n, $story->get_children()->get_count()); } $story->delete(); }
/** * @covers Alchemy\Phrasea\Controller\Prod\Property::changeStatus */ public function testChangeStatus() { $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/cestlafete.jpg'), self::$DI['collection']); $record = \record_adapter::createFromFile($file, self::$DI['app']); $record2 = \record_adapter::createFromFile($file, self::$DI['app']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); $story->appendChild($record2); $acl = $this->getMockBuilder('ACL')->disableOriginalConstructor()->getMock(); $acl->expects($this->any())->method('has_access_to_record')->with($this->isInstanceOf('\\record_adapter'))->will($this->returnValue(true)); $acl->expects($this->any())->method('has_right_on_base')->with($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT), $this->equalTo('chgstatus'))->will($this->returnValue(true)); $acl->expects($this->any())->method('has_right_on_sbas')->with($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT), $this->equalTo('chgstatus'))->will($this->returnValue(true)); $aclProvider = $this->getMockBuilder('Alchemy\\Phrasea\\Authentication\\ACLProvider')->disableOriginalConstructor()->getMock(); $aclProvider->expects($this->any())->method('get')->will($this->returnValue($acl)); self::$DI['app']['acl'] = $aclProvider; self::$DI['client']->request('POST', '/prod/records/property/status/', ['apply_to_children' => [$story->get_sbas_id() => true], 'status' => [$record->get_sbas_id() => [6 => true, 8 => true, 11 => true]], 'lst' => implode(';', [$record->get_serialize_key(), $story->get_serialize_key()])]); $response = self::$DI['client']->getResponse(); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); $this->assertTrue($datas['success']); $this->assertArrayHasKey('updated', $datas); $record = new \record_adapter(self::$DI['app'], $record->get_sbas_id(), $record->get_record_id()); $story = new \record_adapter(self::$DI['app'], $story->get_sbas_id(), $story->get_record_id()); $recordStatus = strrev($record->get_status()); $storyStatus = strrev($story->get_status()); $this->assertEquals(1, substr($recordStatus, 6, 1)); $this->assertEquals(1, substr($recordStatus, 8, 1)); $this->assertEquals(1, substr($recordStatus, 11, 1)); $this->assertEquals(1, substr($storyStatus, 6, 1)); $this->assertEquals(1, substr($storyStatus, 8, 1)); $this->assertEquals(1, substr($storyStatus, 11, 1)); foreach ($story->get_children() as $child) { $childStatus = strrev($child->get_status()); $this->assertEquals(1, substr($childStatus, 6, 1)); $this->assertEquals(1, substr($childStatus, 8, 1)); $this->assertEquals(1, substr($childStatus, 11, 1)); } $record->delete(); $record2->delete(); $story->delete(); unset($response, $datas, $story, $record, $record2, $story, $file); }
public function postCreateFormAction(Request $request) { $collection = \collection::get_from_base_id($this->app, $request->request->get('base_id')); if (!$this->getAclForUser()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { throw new AccessDeniedHttpException('You can not create a story on this collection'); } $story = \record_adapter::createStory($this->app, $collection); $records = RecordsRequest::fromRequest($this->app, $request, true); foreach ($records as $record) { if ($story->hasChild($record)) { continue; } $story->appendChild($record); } $metadatas = []; foreach ($collection->get_databox()->get_meta_structure() as $meta) { if ($meta->get_thumbtitle()) { $value = $request->request->get('name'); } else { continue; } $metadatas[] = ['meta_struct_id' => $meta->get_id(), 'meta_id' => null, 'value' => $value]; break; } $story->set_metadatas($metadatas)->rebuild_subdefs(); $storyWZ = new StoryWZ(); $storyWZ->setUser($this->getAuthenticatedUser()); $storyWZ->setRecord($story); $manager = $this->getEntityManager(); $manager->persist($storyWZ); $manager->flush(); if ($request->getRequestFormat() == 'json') { $data = ['success' => true, 'message' => $this->app->trans('Story created'), 'WorkZone' => $storyWZ->getId(), 'story' => ['sbas_id' => $story->get_sbas_id(), 'record_id' => $story->get_record_id()]]; return $this->app->json($data); } return $this->app->redirectPath('prod_stories_story', ['sbas_id' => $storyWZ->getSbasId(), 'record_id' => $storyWZ->getRecordId()]); }
public function testDelRecordFromStory() { $this->setToken($this->userAccessToken); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/extractfile.jpg'), self::$DI['collection']); $record = \record_adapter::createFromFile($file, self::$DI['app']); $story->appendChild($record); $route = sprintf('/api/v1/stories/%s/%s/delrecords', $story->getDataboxId(), $story->getRecordId()); $records = array('databox_id' => $record->getDataboxId(), 'record_id' => $record->getRecordId()); self::$DI['client']->request('DELETE', $route, $this->getParameters(), $this->getAddRecordFile(), ['HTTP_ACCEPT' => $this->getAcceptMimeType(), 'CONTENT_TYPE' => 'application/json'], json_encode(array('story_records' => array($records)))); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); $this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateMeta200($content); $data = $content['response']; $this->assertArrayHasKey('records', $data); $this->assertCount(1, $data['records']); $story->delete(); $record->delete(); }
private function generateRecord(\Pimple $DI) { foreach (range(1, 7) as $i) { $file = new File($this->container, $this->container['mediavorus']->guess(__DIR__ . '/../../../../../tests/files/test001.jpg'), $DI['coll']); $record = \record_adapter::createFromFile($file, $this->container); $this->container['subdef.generator']->generateSubdefs($record); $DI['record_' . $i] = $record; } $media = $this->container['mediavorus']->guess($this->container['root.path'] . '/tests/files/cestlafete.jpg'); foreach (range(1, 3) as $i) { $story = \record_adapter::createStory($this->container, $DI['coll']); if ($i < 3) { $this->container['subdef.substituer']->substitute($story, 'preview', $media); $this->container['subdef.substituer']->substitute($story, 'thumbnail', $media); } $DI['record_story_' . $i] = $story; } }
/** * @covers Alchemy\Phrasea\Border\Manager::createRecord */ public function testCreateRecord() { $records = []; $postProcessRecord = function ($record) use(&$records) { $records[] = $record; }; $file = File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']); $first = $odd = false; $tofetch = []; foreach (self::$DI['collection']->get_databox()->get_meta_structure() as $databox_field) { if ($databox_field->is_readonly()) { continue; } if ($databox_field->is_on_error() || !$databox_field->get_tag()->getTagname()) { continue; } if ($databox_field->is_multi()) { $data = ['a', 'Hello Multi ' . $databox_field->get_tag()->getTagname()]; $tofetch[$databox_field->get_name()] = $data; $data[] = null; $value = new \PHPExiftool\Driver\Value\Multi($data); $file->addAttribute(new Metadata(new \PHPExiftool\Driver\Metadata\Metadata($databox_field->get_tag(), $value))); } else { $data = ['Hello Mono ' . $databox_field->get_tag()->getTagname()]; if (!$first) { if ($odd) { $value = new \PHPExiftool\Driver\Value\Mono(current($data)); $tofetch[$databox_field->get_name()] = $data; $file->addAttribute(new Metadata(new \PHPExiftool\Driver\Metadata\Metadata($databox_field->get_tag(), $value))); } else { $value = new \PHPExiftool\Driver\Value\Mono(current($data)); $tofetch[$databox_field->get_name()] = $data; $file->addAttribute(new MetaField($databox_field, [current($data)])); } } if ($first) { $value = new \PHPExiftool\Driver\Value\Mono(null); $first = false; $file->addAttribute(new Metadata(new \PHPExiftool\Driver\Metadata\Metadata($databox_field->get_tag(), $value))); } } $odd = !$odd; } $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); $file->addAttribute(new Story($story)); $status = ''; foreach (range(0, 31) as $i) { if ($i == 4 || $i == 8) { $status .= '1'; } else { $status .= '0'; } } $file->addAttribute(new Status(self::$DI['app'], strrev($status))); self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock(); $this->assertEquals(Manager::RECORD_CREATED, $this->object->process($this->session, $file, $postProcessRecord, Manager::FORCE_RECORD)); $record = current($records); $found = false; foreach ($record->get_grouping_parents()->get_elements() as $parent_story) { if ($parent_story->get_serialize_key() === $story->get_serialize_key()) { $found = true; } } if (!$found) { $this->fail('Unable to find story in parents'); } $status = strrev($record->get_status()); $this->assertEquals(32, strlen($status)); $this->assertEquals('1', substr($status, 4, 1)); $this->assertEquals('1', substr($status, 8, 1)); foreach ($tofetch as $name => $values) { $found = []; foreach ($record->get_caption()->get_field($name)->get_values() as $value) { $found[] = $value->getValue(); } $this->assertEquals($values, $found); } foreach ($records as $record) { if ($record instanceof \record_adapter) { $record->delete(); } } $story->delete(); }
public function createStory(Application $app, \collection $collection, $pathfile, $captionFile, $stat0, $stat1) { $status = \databox_status::operation_or($stat0, $stat1); $media = $app->getMediaFromUri($pathfile); $databox = $collection->get_databox(); $metadatasStructure = $databox->get_meta_structure(); $metadatas = $this->getIndexByFieldName($metadatasStructure, $media->getMetadatas()); $metaFields = null; if ($captionFile !== null && true === $app['filesystem']->exists($captionFile)) { $metaFields = $this->readXMLForDatabox($app, $metadatasStructure, $captionFile); $captionStatus = $this->parseStatusBit(@simplexml_load_file($captionFile)); if ($captionStatus) { $status = \databox_status::operation_mask($status, $captionStatus); } } $story = \record_adapter::createStory($app, $collection); $app['subdef.substituer']->substitute($story, 'document', $media); $story->set_metadatas($metadatas->toMetadataArray($metadatasStructure), true); if ($metaFields) { $story->set_metadatas($metaFields->toMetadataArray($metadatasStructure), true); } $story->set_binary_status(\databox_status::operation_or($stat0, $stat1)); $story->rebuild_subdefs(); unset($media); return $story; }
public function connect(Application $app) { $app['controller.prod.story'] = $this; $controllers = $app['controllers_factory']; $app['firewall']->addMandatoryAuthentication($controllers); $controllers->get('/create/', function (Application $app) { return $app['twig']->render('prod/Story/Create.html.twig', []); })->bind('prod_stories_create'); $controllers->post('/', function (Application $app, Request $request) { /* @var $request \Symfony\Component\HttpFoundation\Request */ $collection = \collection::get_from_base_id($app, $request->request->get('base_id')); if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { throw new AccessDeniedHttpException('You can not create a story on this collection'); } $Story = \record_adapter::createStory($app, $collection); $records = RecordsRequest::fromRequest($app, $request, true); foreach ($records as $record) { if ($Story->hasChild($record)) { continue; } $Story->appendChild($record); } $metadatas = []; foreach ($collection->get_databox()->get_meta_structure() as $meta) { if ($meta->get_thumbtitle()) { $value = $request->request->get('name'); } else { continue; } $metadatas[] = ['meta_struct_id' => $meta->get_id(), 'meta_id' => null, 'value' => $value]; break; } $Story->set_metadatas($metadatas)->rebuild_subdefs(); $StoryWZ = new StoryWZ(); $StoryWZ->setUser($app['authentication']->getUser()); $StoryWZ->setRecord($Story); $app['EM']->persist($StoryWZ); $app['EM']->flush(); if ($request->getRequestFormat() == 'json') { $data = ['success' => true, 'message' => $app->trans('Story created'), 'WorkZone' => $StoryWZ->getId(), 'story' => ['sbas_id' => $Story->get_sbas_id(), 'record_id' => $Story->get_record_id()]]; return $app->json($data); } else { return $app->redirectPath('prod_stories_story', ['sbas_id' => $StoryWZ->getSbasId(), 'record_id' => $StoryWZ->getRecordId()]); } })->bind('prod_stories_do_create'); $controllers->get('/{sbas_id}/{record_id}/', function (Application $app, $sbas_id, $record_id) { $Story = new \record_adapter($app, $sbas_id, $record_id); $html = $app['twig']->render('prod/WorkZone/Story.html.twig', ['Story' => $Story]); return new Response($html); })->bind('prod_stories_story')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+'); $controllers->post('/{sbas_id}/{record_id}/addElements/', function (Application $app, Request $request, $sbas_id, $record_id) { $Story = new \record_adapter($app, $sbas_id, $record_id); if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) { throw new AccessDeniedHttpException('You can not add document to this Story'); } $n = 0; $records = RecordsRequest::fromRequest($app, $request, true); foreach ($records as $record) { if ($Story->hasChild($record)) { continue; } $Story->appendChild($record); $n++; } $data = ['success' => true, 'message' => $app->trans('%quantity% records added', ['%quantity%' => $n])]; if ($request->getRequestFormat() == 'json') { return $app->json($data); } else { return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]); } })->assert('sbas_id', '\\d+')->assert('record_id', '\\d+'); $controllers->post('/{sbas_id}/{record_id}/delete/{child_sbas_id}/{child_record_id}/', function (Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) { $Story = new \record_adapter($app, $sbas_id, $record_id); $record = new \record_adapter($app, $child_sbas_id, $child_record_id); if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) { throw new AccessDeniedHttpException('You can not add document to this Story'); } $Story->removeChild($record); $data = ['success' => true, 'message' => $app->trans('Record removed from story')]; if ($request->getRequestFormat() == 'json') { return $app->json($data); } else { return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]); } })->bind('prod_stories_story_remove_element')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+')->assert('child_sbas_id', '\\d+')->assert('child_record_id', '\\d+'); /** * Get the Basket reorder form */ $controllers->get('/{sbas_id}/{record_id}/reorder/', function (Application $app, $sbas_id, $record_id) { $story = new \record_adapter($app, $sbas_id, $record_id); if (!$story->is_grouping()) { throw new \Exception('This is not a story'); } return new Response($app['twig']->render('prod/Story/Reorder.html.twig', ['story' => $story])); })->bind('prod_stories_story_reorder')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+'); $controllers->post('/{sbas_id}/{record_id}/reorder/', function (Application $app, $sbas_id, $record_id) { $ret = ['success' => false, 'message' => $app->trans('An error occured')]; try { $story = new \record_adapter($app, $sbas_id, $record_id); if (!$story->is_grouping()) { throw new \Exception('This is not a story'); } if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($story->get_base_id(), 'canmodifrecord')) { throw new ControllerException($app->trans('You can not edit this story')); } $sql = 'UPDATE regroup SET ord = :ord WHERE rid_parent = :parent_id AND rid_child = :children_id'; $stmt = $story->get_databox()->get_connection()->prepare($sql); foreach ($app['request']->request->get('element') as $record_id => $ord) { $params = [':ord' => $ord, ':parent_id' => $story->get_record_id(), ':children_id' => $record_id]; $stmt->execute($params); } $stmt->closeCursor(); $ret = ['success' => true, 'message' => $app->trans('Story updated')]; } catch (ControllerException $e) { $ret = ['success' => false, 'message' => $e->getMessage()]; } catch (\Exception $e) { } return $app->json($ret); })->assert('sbas_id', '\\d+')->assert('record_id', '\\d+'); return $controllers; }
/** * @covers Alchemy\Phrasea\Controller\Prod\Lazaret::addElement */ public function testAddElement() { self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock(); $originalEm = self::$DI['app']['EM']; $em = $this->createEntityManagerMock(); $lazaretFile = $this->getOneLazaretFile(); $lazaretFileName = self::$DI['app']['tmp.lazaret.path'] . '/' . $lazaretFile->getFilename(); $lazaretThumbFileName = self::$DI['app']['tmp.lazaret.path'] . '/' . $lazaretFile->getThumbFilename(); copy(__DIR__ . '/../../../../../files/cestlafete.jpg', $lazaretFileName); copy(__DIR__ . '/../../../../../files/cestlafete.jpg', $lazaretThumbFileName); //mock lazaret Attribute $lazaretAttribute = $this->getMock('Alchemy\\Phrasea\\Model\\Entities\\LazaretAttribute', [], [], '', false); //Expect to be called 3 times since we add 5 attribute to lazaretFile //and each one is called to verify if it is an attribute to keep $lazaretAttribute->expects($this->exactly(5))->method('getId')->will($this->onConsecutiveCalls(1, 2, 3, 4, 5)); //Provide consecutive value for all type of attributes //Expect 4 call since the Fifth attribute is not eligible (see request attributes) $lazaretAttribute->expects($this->exactly(4))->method('getName')->will($this->onConsecutiveCalls(AttributeInterface::NAME_METADATA, AttributeInterface::NAME_STORY, AttributeInterface::NAME_STATUS, AttributeInterface::NAME_METAFIELD)); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); //Provide some valid test values $lazaretAttribute->expects($this->exactly(4))->method('getValue')->will($this->onConsecutiveCalls('metadataValue', $story->get_serialize_key(), '00001111', 'metafieldValue')); //Add the 5 attribute $lazaretFile->addAttribute($lazaretAttribute); $lazaretFile->addAttribute($lazaretAttribute); $lazaretFile->addAttribute($lazaretAttribute); $lazaretFile->addAttribute($lazaretAttribute); $lazaretFile->addAttribute($lazaretAttribute); $id = 1; self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock(); self::$DI['app']['repo.lazaret-files']->expects($this->once())->method('find')->with($this->equalTo($id))->will($this->returnValue($lazaretFile)); //In any case we expect the deletion of the lazaret file $em->expects($this->once())->method('remove')->with($this->equalTo($lazaretFile)); //Then flush $em->expects($this->once())->method('flush'); self::$DI['app']['EM'] = $em; self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', ['bas_id' => $lazaretFile->getBaseId(), 'keep_attributes' => 1, 'attributes' => [1, 2, 3, 4]]); $response = self::$DI['client']->getResponse(); $this->assertResponseOk($response); $this->assertGoodJsonContent(json_decode($response->getContent())); self::$DI['app']['EM'] = $originalEm; $story->delete(); }
public function testSearchWithStories() { $this->authenticate(self::$DI['app']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); if (!$story->hasChild(self::$DI['record_1'])) { $story->appendChild(self::$DI['record_1']); } $request = new Request(['search_type' => 1], [], [], [], [], ['HTTP_Accept' => 'application/json']); $result = $this->object->search($request); $this->assertEquals(200, $result->get_http_code()); $this->assertEquals('application/json', $result->get_content_type()); $this->assertTrue(is_array(json_decode($result->format(), true))); $data = json_decode($result->format(), true); $this->assertArrayHasKey('records', $data['response']['results']); $this->assertArrayHasKey('stories', $data['response']['results']); $found = false; foreach ($data['response']['results']['stories'] as $retStory) { if ($retStory['story_id'] == $story->get_record_id() && $retStory['databox_id'] == $story->get_sbas_id()) { $found = true; break; } } if (!$found) { $this->fail('unable to find the story back'); } }
private function substituteAndCheck($name) { $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); $media = $this->getMockBuilder('MediaVorus\\Media\\MediaInterface')->disableOriginalConstructor()->getMock(); $symfoFile = new UploadedFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'cestlafete.jpg'); $media->expects($this->any())->method('getFile')->will($this->returnValue($symfoFile)); self::$DI['app']['subdef.substituer']->substitute($story, $name, $media); $path = self::$DI['app']['url_generator']->generate('datafile', ['sbas_id' => $story->get_sbas_id(), 'record_id' => $story->get_record_id(), 'subdef' => $name]); self::$DI['client']->request('GET', $path); $response = self::$DI['client']->getResponse(); $this->assertEquals(200, $response->getStatusCode()); }
/** * @param $data * @param $schemaStory * @param $schemaRecordStory * @return \record_adapter * @throws \Exception */ protected function createStory($data, $schemaStory, $schemaRecordStory) { $validator = $this->getJsonSchemaValidator(); $validator->check($data, $schemaStory); if (false === $validator->isValid()) { $this->app->abort(400, 'Request body does not contains a valid "story" object'); } $collection = \collection::get_from_base_id($this->app, $data->{'base_id'}); if (!$this->getAclForUser()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { $this->app->abort(403, sprintf('You can not create a story on this collection %s', $collection->get_base_id())); } $story = \record_adapter::createStory($this->app, $collection); if (isset($data->{'title'})) { $story->set_original_name((string) $data->{'title'}); } // set metadata for the story $metadatas = array(); $thumbtitle_set = false; /** @var \databox_field $field */ foreach ($collection->get_databox()->get_meta_structure() as $field) { // the title goes into the first 'thumbtitle' field if (isset($data->{'title'}) && !$thumbtitle_set && $field->get_thumbtitle()) { $metadatas[] = array('meta_struct_id' => $field->get_id(), 'meta_id' => null, 'value' => $data->{'title'}); $thumbtitle_set = true; } // if the field is set into data->metadatas, set it $meta = null; // the meta form json can be keyed by id or name if (isset($data->{'metadatas'}->{$field->get_id()})) { $meta = $data->{'metadatas'}->{$field->get_id()}; } elseif (isset($data->{'metadatas'}->{$field->get_name()})) { $meta = $data->{'metadatas'}->{$field->get_name()}; } if ($meta !== null) { if (!is_array($meta)) { $meta = array($meta); } foreach ($meta as $value) { $metadatas[] = array('meta_struct_id' => $field->get_id(), 'meta_id' => null, 'value' => $value); } } } if (count($metadatas) > 0) { $story->set_metadatas($metadatas); } if (isset($data->{'story_records'})) { $recordsData = (array) $data->{'story_records'}; $this->addOrDelStoryRecordsFromData($story, $recordsData, 'ADD'); } return $story; }