Merge with 3.6

This commit is contained in:
Romain Neutron
2012-03-12 18:40:21 +01:00
212 changed files with 18953 additions and 32930 deletions

View File

@@ -363,6 +363,39 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
}
}
public function testRecordsCaptionRoute()
{
foreach (static::$databoxe_ids as $databox_id)
{
$databox = databox::get_instance($databox_id);
$collection = array_shift($databox->get_collections());
$system_file = new system_file(__DIR__ . '/../../../testfiles/cestlafete.jpg');
$record = record_adapter::create($collection, $system_file);
$record_id = $record->get_record_id();
$route = '/records/' . $databox_id . '/' . $record_id . '/caption/?oauth_token=' . self::$token;
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
$crawler = $this->client->request('GET', $route);
$content = json_decode($this->client->getResponse()->getContent());
$this->evaluateResponse200($this->client->getResponse());
$this->evaluateMetaJson200($content);
$this->evaluateRecordsCaptionResponse($content);
$record->delete();
}
$route = '/records/24892534/51654651553/metadatas/?oauth_token=' . self::$token;
$this->evaluateNotFoundRoute($route, array('GET'));
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/?oauth_token=' . self::$token;
$this->evaluateBadRequestRoute($route, array('GET'));
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
}
public function testRecordsMetadatasRoute()
{
foreach (static::$databoxe_ids as $databox_id)
@@ -1160,6 +1193,20 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
}
}
protected function evaluateRecordsCaptionResponse($content)
{
foreach ($content->response as $field)
{
$this->assertTrue(is_object($field), 'Un bloc field est un objet');
$this->assertObjectHasAttribute('meta_structure_id', $meta);
$this->assertTrue(is_int($field->meta_structure_id));
$this->assertObjectHasAttribute('name', $field);
$this->assertTrue(is_string($meta->name));
$this->assertObjectHasAttribute('value', $field);
$this->assertTrue(is_string($meta->value));
}
}
protected function evaluateRecordsMetadataResponse($content)
{
$this->assertObjectHasAttribute("metadatas", $content->response);

View File

@@ -369,6 +369,39 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
}
}
public function testRecordsCaptionRoute()
{
foreach (static::$databoxe_ids as $databox_id)
{
$databox = databox::get_instance($databox_id);
$collection = array_shift($databox->get_collections());
$system_file = new system_file(__DIR__ . '/../../../testfiles/cestlafete.jpg');
$record = record_adapter::create($collection, $system_file);
$record_id = $record->get_record_id();
$route = '/records/' . $databox_id . '/' . $record_id . '/caption/?oauth_token=' . self::$token;
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
$crawler = $this->client->request('GET', $route , array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
$content = self::$yaml->parse($this->client->getResponse()->getContent());
$this->evaluateResponse200($this->client->getResponse());
$this->evaluateMetaYaml200($content);
$this->evaluateRecordsCaptionResponse($content);
$record->delete();
}
$route = '/records/24892534/51654651553/metadatas/?oauth_token=' . self::$token;
$this->evaluateNotFoundRoute($route, array('GET'));
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/?oauth_token=' . self::$token;
$this->evaluateBadRequestRoute($route, array('GET'));
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
}
public function testRecordsMetadatasRoute()
{
foreach (static::$databoxe_ids as $databox_id)
@@ -1197,6 +1230,20 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
}
}
protected function evaluateRecordsCaptionResponse($content)
{
foreach ($content["response"] as $field)
{
$this->assertTrue(is_array($field), 'Un bloc field est un objet');
$this->assertArrayHasKey('meta_structure_id', $meta);
$this->assertTrue(is_int($field["meta_structure_id"]));
$this->assertArrayHasKey('name', $field);
$this->assertTrue(is_string($meta["name"]));
$this->assertArrayHasKey('value', $field);
$this->assertTrue(is_string($meta["value"]));
}
}
protected function evaluateRecordsMetadataResponse($content)
{
$this->assertArrayHasKey("metadatas", $content["response"]);

View File

@@ -312,7 +312,7 @@ class ApplicationLightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertTrue($datas->error);
$validationBasket = $this->insertOneValidationBasket();
$crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $validationBasket->getId() . '/');

View File

@@ -59,9 +59,6 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
@@ -149,9 +146,6 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
@@ -169,9 +163,6 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
@@ -194,9 +185,6 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
@@ -220,9 +208,6 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
@@ -251,9 +236,6 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());

View File

@@ -461,6 +461,74 @@ class ControllerBasketTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(2, $basket->getElements()->count());
}
public function testAddElementToValidationPost()
{
$em = self::$core->getEntityManager();
$datas = $em->getRepository('Entities\ValidationData')->findAll();
$countDatas = count($datas);
$validationSession = new \Entities\ValidationSession();
$validationSession->setDescription('Une description au hasard');
$validationSession->setName('Un nom de validation');
$expires = new \DateTime();
$expires->modify('+1 week');
$validationSession->setExpires($expires);
$validationSession->setInitiator(self::$user);
$basket = new \Entities\Basket();
$basket->setName('test');
$basket->setDescription('description');
$basket->setOwner(self::$user);
$basket->setValidation($validationSession);
$validationSession->setBasket($basket);
$validationParticipant = new \Entities\ValidationParticipant();
$validationParticipant->setSession($validationSession);
$validationParticipant->setUser(self::$user_alt1);
$validationSession->addValidationParticipant($validationParticipant);
$em->persist($validationParticipant);
$em->persist($basket);
$em->persist($validationSession);
$em->flush();
$route = sprintf('/baskets/%s/addElements/', $basket->getId());
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key(),
' ',
'42',
'abhak',
self::$record_no_access->get_serialize_key(),
);
$lst = implode(';', $records);
$this->client->request('POST', $route, array('lst' => $lst));
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertEquals(2, $basket->getElements()->count());
$datas = $em->getRepository('Entities\ValidationData')->findAll();
$this->assertTrue($countDatas < count($datas), 'assert that '.count($datas).' > '.$countDatas );
}
public function testAddElementPostJSON()
{
$basket = $this->insertOneBasket();

View File

@@ -50,7 +50,7 @@ class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
public function tearDown()
{
parent::tearDown();
if(self::$api instanceof Bridge_Api)
if (self::$api instanceof Bridge_Api)
self::$api->delete();
if (self::$account instanceof Bridge_Account)
self::$account->delete();
@@ -163,16 +163,6 @@ class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou');
}
public function testLogoutDeconnected()
{
$this->client->followRedirects();
$url = sprintf('/bridge/adapter/%d/logout/', self::$account->get_id());
$crawler = $this->client->request('GET', $url);
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains("/adapter/" . self::$account->get_id() . "/logout/", $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testLogout()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
@@ -193,16 +183,6 @@ class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
}
public function testLoadElementsDisconnected()
{
$url = sprintf("/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isOk());
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testLoadRecords()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
@@ -216,7 +196,8 @@ class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
public function testLoadRecordsDisconnected()
{
self::$account->get_settings()->set("auth_token", null);//deconnected
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-records/", self::$account->get_id());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$pageContent = $this->client->getResponse()->getContent();
@@ -236,7 +217,8 @@ class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
public function testLoadContainersDisconnected()
{
self::$account->get_settings()->set("auth_token", null);//deconnected
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-containers/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$pageContent = $this->client->getResponse()->getContent();
@@ -244,9 +226,33 @@ class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->deconnected($crawler, $pageContent);
}
public function testLoadElementsDisconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isOk());
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testLogoutDeconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf('/bridge/adapter/%d/logout/', self::$account->get_id());
$crawler = $this->client->request('GET', $url);
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains("/adapter/" . self::$account->get_id() . "/logout/", $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testActionDeconnected()
{
self::$account->get_settings()->set("auth_token", null);//deconnected
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/action/%s/une action/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url);
$pageContent = $this->client->getResponse()->getContent();

View File

@@ -33,7 +33,7 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*
* @var \record_adapter
*/
protected static $need_story = true;
protected static $need_story = true;
protected static $need_records = 2;
public function setUp()
@@ -53,16 +53,16 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$route = "/story/";
$collections = self::$core->getAuthenticatedUser()
->ACL()
->get_granted_base(array('canaddrecord'));
->ACL()
->get_granted_base(array('canaddrecord'));
$collection = array_shift($collections);
$crawler = $this->client->request(
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story',
'description' => 'test_description')
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story'
)
);
$response = $this->client->getResponse();
@@ -70,7 +70,7 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(302, $response->getStatusCode());
$query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
);
$count = $query->getSingleScalarResult();
@@ -83,17 +83,16 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$route = "/story/";
$collections = self::$core->getAuthenticatedUser()
->ACL()
->get_granted_base(array('canaddrecord'));
->ACL()
->get_granted_base(array('canaddrecord'));
$collection = array_shift($collections);
$crawler = $this->client->request(
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story',
'description' => 'test_description'), array(), array(
"HTTP_ACCEPT" => "application/json")
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story'), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
@@ -117,9 +116,6 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$filter = "form[action='/prod/story/'] input[name='name']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/story/'] textarea[name='description']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/story/'] select[name='base_id']";
$this->assertEquals(1, $crawler->filter($filter)->count());
}
@@ -144,8 +140,8 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$route = sprintf("/story/%s/%s/addElements/", $story->get_sbas_id(), $story->get_record_id());
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
);
$lst = implode(';', $records);
@@ -166,15 +162,15 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$route = sprintf("/story/%s/%s/addElements/", $story->get_sbas_id(), $story->get_record_id());
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
);
$lst = implode(';', $records);
$crawler = $this->client->request('POST', $route, array('lst' => $lst)
, array(), array(
"HTTP_ACCEPT" => "application/json"));
, array(), array(
"HTTP_ACCEPT" => "application/json"));
$response = $this->client->getResponse();
@@ -188,21 +184,21 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$story = self::$story_1;
$records = array(
self::$record_1,
self::$record_2
self::$record_1,
self::$record_2
);
$totalRecords = count($records);
$n = 0;
$n = 0;
foreach ($records as $record)
{
/* @var $record \record_adapter */
$route = sprintf(
"/story/%s/%s/delete/%s/%s/"
, $story->get_sbas_id()
, $story->get_record_id()
, $record->get_sbas_id()
, $record->get_record_id()
"/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)
@@ -216,10 +212,10 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
else
{
$crawler = $this->client->request(
'POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json")
'POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
@@ -229,7 +225,4 @@ class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
}
}
}

View File

@@ -300,72 +300,6 @@ class databox_fieldTest extends PhraseanetPHPUnitAbstract
);
}
/**
* @todo Implement testSet_regdate().
*/
public function testSet_regdate()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testSet_regdesc().
*/
public function testSet_regdesc()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testSet_regname().
*/
public function testSet_regname()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testIs_regname().
*/
public function testIs_regname()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testIs_regdesc().
*/
public function testIs_regdesc()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testIs_regdate().
*/
public function testIs_regdate()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_thumbtitle().
*/

View File

@@ -13,7 +13,7 @@ class randomTest extends PhraseanetPHPUnitAbstract
{
$expires_on = new DateTime('-5 minutes');
$usr_id = self::$user->get_id();
$token = random::getUrlToken('password', $usr_id, $expires_on, 'some nice datas');
$token = random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
random::cleanTokens();
try
@@ -76,7 +76,7 @@ class randomTest extends PhraseanetPHPUnitAbstract
public function testGetUrlToken()
{
$usr_id = self::$user->get_id();
$token = random::getUrlToken('password', $usr_id, null, 'some nice datas');
$token = random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, null, 'some nice datas');
$datas = random::helloToken($token);
$this->assertEquals('some nice datas', $datas['datas']);
random::updateToken($token, 'some very nice datas');
@@ -101,7 +101,7 @@ class randomTest extends PhraseanetPHPUnitAbstract
public function testHelloToken()
{
$usr_id = self::$user->get_id();
$token = random::getUrlToken('password', $usr_id, null, 'some nice datas');
$token = random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, null, 'some nice datas');
$datas = random::helloToken($token);
$this->assertEquals('some nice datas', $datas['datas']);
$this->assertNull($datas['expire_on']);
@@ -125,7 +125,7 @@ class randomTest extends PhraseanetPHPUnitAbstract
$expires_on = new DateTime('+5 minutes');
$usr_id = self::$user->get_id();
$token = random::getUrlToken('password', $usr_id, $expires_on, 'some nice datas');
$token = random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
$datas = random::helloToken($token);
$this->assertEquals('some nice datas', $datas['datas']);
$sql_expires = new DateTime($datas['expire_on']);
@@ -151,7 +151,7 @@ class randomTest extends PhraseanetPHPUnitAbstract
$expires_on = new DateTime('-5 minutes');
$usr_id = self::$user->get_id();
$token = random::getUrlToken('password', $usr_id, $expires_on, 'some nice datas');
$token = random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expires_on, 'some nice datas');
try
{

View File

@@ -384,7 +384,18 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals(1, count($current_fields));
$field = $current_fields[0];
$multi_imploded = implode(' ' . $meta_el->get_separator() . ' ', array('un', 'jeu', 'de', 'test'));
$separator = $meta_el->get_separator();
if(strlen($separator) > 0)
{
$separator = $separator[0];
}
else
{
$separator = '';
}
$multi_imploded = implode(' ' . $separator . ' ', array('un', 'jeu', 'de', 'test'));
if ($meta_el->is_multi())
{
@@ -468,11 +479,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
);
}
public function testGet_reg_name()
{
$this->assertTrue(is_string(self::$story_1->get_reg_name()));
}
public function testGet_record_by_sha()
{
$tmp_records = record_adapter::get_record_by_sha(self::$record_1->get_sbas_id(), self::$record_1->get_sha256());