From a54b80b4b29c11d23df8f33a972a1d3ac8c8468c Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 25 Oct 2012 17:19:52 +0200 Subject: [PATCH] Add record preview Test Fix CS --- .../Phrasea/Controller/Prod/RecordsTest.php | 200 +++++++++++++++++- www/include/jquery.p4.preview.js | 4 +- 2 files changed, 197 insertions(+), 7 deletions(-) diff --git a/tests/Alchemy/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Phrasea/Controller/Prod/RecordsTest.php index 69bb217b9a..c7b5d4fa8a 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/RecordsTest.php @@ -8,13 +8,23 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract. class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { protected $client; + protected static $feed; + + public static function tearDownAfterClass() + { + if(self::$feed instanceof Feed_Adapter){ + self::$feed->delete(); + } + + parent::tearDownAfterClass(); + } /** * @covers Alchemy\Phrasea\Controller\Prod\Records::whatCanIDelete */ public function testWhatCanIDelete() { - self::$DI['client']->request('POST', '/prod/records/delete/what/', array('lst' => self::$DI['record_1']->get_serialize_key())); + self::$DI['client']->request('POST', '/prod/records/delete/what/', array('lst' => self::$DI['record_1']->get_serialize_key())); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); unset($response); @@ -27,14 +37,14 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $file = new Alchemy\Phrasea\Border\File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../testfiles/cestlafete.jpg'), self::$DI['collection']); $record = \record_adapter::createFromFile($file, self::$DI['app']); - $this->XMLHTTPRequest('POST', '/prod/records/delete/', array('lst' => $record->get_serialize_key())); + $this->XMLHTTPRequest('POST', '/prod/records/delete/', array('lst' => $record->get_serialize_key())); $response = self::$DI['client']->getResponse(); $datas = (array) json_decode($response->getContent()); $this->assertContains($record->get_serialize_key(), $datas); try { - new \record_adapter(self::$DI['app'], $record->get_sbas_id(), $record->get_record_id()); + new \record_adapter(self::$DI['app'], $record->get_sbas_id(), $record->get_record_id()); $this->fail('Record not deleted'); - } catch(\Exception $e) { + } catch (\Exception $e) { } unset($response, $datas, $record); @@ -47,7 +57,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $file = new Alchemy\Phrasea\Border\File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../testfiles/cestlafete.jpg'), self::$DI['collection']); $record = \record_adapter::createFromFile($file, self::$DI['app']); - $this->XMLHTTPRequest('POST', '/prod/records/renew-url/', array('lst' => $record->get_serialize_key())); + $this->XMLHTTPRequest('POST', '/prod/records/renew-url/', array('lst' => $record->get_serialize_key())); $response = self::$DI['client']->getResponse(); $datas = (array) json_decode($response->getContent()); $this->assertTrue(count($datas) > 0); @@ -55,4 +65,184 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract unset($response, $datas, $record); } + /** + * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testGetRecordDetailNotAjax() + { + self::$DI['client']->request('POST', '/prod/records/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord + */ + public function testGetRecordDetailResult() + { + \phrasea::start(self::$DI['app']['phraseanet.configuration']); + $auth = new \Session_Authentication_None(self::$DI['user']); + self::$DI['app']->openAccount($auth); + self::$DI['record_24']; + + $options = new \searchEngine_options(); + $acl = self::$DI['app']['phraseanet.user']->ACL(); + $options->set_bases(array_keys($acl->get_granted_base()), $acl); + $serializedOptions = serialize($options); + + $this->XMLHTTPRequest('POST', '/prod/records/', array( + 'env' => 'RESULT', + 'options_serial' => $serializedOptions, + 'pos' => 0, + 'query' => '' + )); + + $response = self::$DI['client']->getResponse(); + $data = json_decode($response->getContent()); + + $this->assertObjectHasAttribute('desc', $data); + $this->assertObjectHasAttribute('html_preview', $data); + $this->assertObjectHasAttribute('current', $data); + $this->assertObjectHasAttribute('others', $data); + $this->assertObjectHasAttribute('history', $data); + $this->assertObjectHasAttribute('popularity', $data); + $this->assertObjectHasAttribute('tools', $data); + $this->assertObjectHasAttribute('pos', $data); + $this->assertObjectHasAttribute('title', $data); + + unset($response, $data); + } + + /** + * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord + */ + public function testGetRecordDetailREG() + { + \phrasea::start(self::$DI['app']['phraseanet.configuration']); + $auth = new \Session_Authentication_None(self::$DI['user']); + self::$DI['app']->openAccount($auth); + self::$DI['record_story_1']; + + $this->XMLHTTPRequest('POST', '/prod/records/', array( + 'env' => 'REG', + 'pos' => 0, + 'query' => '', + 'cont' => self::$DI['record_story_1']->get_serialize_key() + )); + + $response = self::$DI['client']->getResponse(); + $data = json_decode($response->getContent()); + $this->assertObjectHasAttribute('desc', $data); + $this->assertObjectHasAttribute('html_preview', $data); + $this->assertObjectHasAttribute('current', $data); + $this->assertObjectHasAttribute('others', $data); + $this->assertObjectHasAttribute('history', $data); + $this->assertObjectHasAttribute('popularity', $data); + $this->assertObjectHasAttribute('tools', $data); + $this->assertObjectHasAttribute('pos', $data); + $this->assertObjectHasAttribute('title', $data); + + unset($response, $data); + } + + /** + * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord + */ + public function testGetRecordDetailBasket() + { + \phrasea::start(self::$DI['app']['phraseanet.configuration']); + $auth = new \Session_Authentication_None(self::$DI['user']); + self::$DI['app']->openAccount($auth); + $basket = $this->insertOneBasket(); + $record = self::$DI['record_1']; + + $basketElement = new \Entities\BasketElement(); + $basketElement->setBasket($basket); + $basketElement->setRecord($record); + $basketElement->setLastInBasket(); + + $basket->addBasketElement($basketElement); + + self::$DI['app']['EM']->persist($basket); + self::$DI['app']['EM']->flush(); + + $this->XMLHTTPRequest('POST', '/prod/records/', array( + 'env' => 'BASK', + 'pos' => 0, + 'query' => '', + 'cont' => $basket->getId() + )); + + $response = self::$DI['client']->getResponse(); + $data = json_decode($response->getContent()); + + $this->assertObjectHasAttribute('desc', $data); + $this->assertObjectHasAttribute('html_preview', $data); + $this->assertObjectHasAttribute('current', $data); + $this->assertObjectHasAttribute('others', $data); + $this->assertObjectHasAttribute('history', $data); + $this->assertObjectHasAttribute('popularity', $data); + $this->assertObjectHasAttribute('tools', $data); + $this->assertObjectHasAttribute('pos', $data); + $this->assertObjectHasAttribute('title', $data); + + unset($response, $data); + } + + /** + * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord + */ + public function testGetRecordDetailFeed() + { + \phrasea::start(self::$DI['app']['phraseanet.configuration']); + $auth = new \Session_Authentication_None(self::$DI['user']); + self::$DI['app']->openAccount($auth); + + self::$feed = Feed_Adapter::create( + self::$DI['app'], + self::$DI['user'], + 'titi', + 'toto' + ); + + $feedEntry = Feed_Entry_Adapter::create( + self::$DI['app'], + self::$feed, + Feed_Publisher_Adapter::getPublisher( + self::$DI['app']['phraseanet.appbox'], + self::$feed, + self::$DI['user'] + ), + 'titi', + 'toto', + 'tata', + 'tutu@test.fr' + ); + + Feed_Entry_Item::create( + self::$DI['app']['phraseanet.appbox'], + $feedEntry, + self::$DI['record_1'] + ); + + $this->XMLHTTPRequest('POST', '/prod/records/', array( + 'env' => 'FEED', + 'pos' => 0, + 'query' => '', + 'cont' => $feedEntry->get_id() + )); + + $response = self::$DI['client']->getResponse(); + $data = json_decode($response->getContent()); + $this->assertObjectHasAttribute('desc', $data); + $this->assertObjectHasAttribute('html_preview', $data); + $this->assertObjectHasAttribute('current', $data); + $this->assertObjectHasAttribute('others', $data); + $this->assertObjectHasAttribute('history', $data); + $this->assertObjectHasAttribute('popularity', $data); + $this->assertObjectHasAttribute('tools', $data); + $this->assertObjectHasAttribute('pos', $data); + $this->assertObjectHasAttribute('title', $data); + + unset($response, $data); + } } diff --git a/www/include/jquery.p4.preview.js b/www/include/jquery.p4.preview.js index da01bb2f84..68e25b4f13 100644 --- a/www/include/jquery.p4.preview.js +++ b/www/include/jquery.p4.preview.js @@ -85,8 +85,8 @@ function openPreview(env, pos, contId, reload){ pos: pos, cont: contId, roll: roll, - options_serial:options_serial, - query:query + options_serial:options_serial, + query:query }, beforeSend: function(){ if (prevAjaxrunning)