Refactor tests using XmlHttpRequest

This commit is contained in:
Benoît Burnichon
2016-03-11 19:41:21 +01:00
parent f2e62abd8b
commit e22a60afc5
13 changed files with 191 additions and 192 deletions

View File

@@ -6,6 +6,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Border\File;
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Client;
/**
@@ -49,7 +50,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
parent::tearDown();
}
public function getJson($response)
public function getJson(Response $response)
{
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
@@ -134,8 +135,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(false);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -147,11 +148,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$prefs = '<?xml version="1.0" encoding="UTF-8"?> <baseprefs> <status>0</status> <sugestedValues> <Object> <value>my_new_value</value> </Object> </sugestedValues> </baseprefs>';
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [
'str' => $prefs
]);
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$collection = $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
@@ -168,11 +169,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$prefs = '<?xml version="1.0" encoding="UTF-alues> </baseprefs>';
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [
'str' => $prefs
]);
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertFalse($json->success);
}
@@ -207,9 +208,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
@@ -248,9 +249,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
$this->assertFalse($collection->is_active());
@@ -318,8 +319,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -329,11 +330,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/', [
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/', [
'pub_wm' => 'wm',
]);
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
$this->assertNotNull($collection->get_pub_wm());
@@ -409,8 +410,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -420,8 +421,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/labels/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/labels/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -433,11 +434,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/rename/', [
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/rename/', [
'name' => 'test_rename_coll'
]);
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
// Collection has to be reloaded since it was modified outside of the current process
@@ -459,7 +460,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/labels/', [
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/labels/', [
'labels' => [
'nl' => 'netherlands label',
'de' => 'german label',
@@ -469,7 +470,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
]
]);
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$databox = $this->getApplication()->findDataboxById($collection->get_sbas_id());
@@ -504,8 +505,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(false);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/empty/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/empty/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -524,9 +525,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No record were added');
}
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$this->assertEquals(0, $collection->get_record_amount());
}
@@ -573,9 +574,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No enough records added');
}
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) {
@@ -662,8 +663,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/delete/');
$json = $this->getJson($response);
$this->assertTrue($json->success);
}
@@ -712,9 +713,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
}
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/delete/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
}
@@ -760,9 +761,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/delete/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
}
@@ -837,9 +838,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
try {
\collection::getByBaseId(self::$DI['app'], $collection->get_base_id());
@@ -865,9 +866,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No record were added');
}
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertFalse($json->success);
$collection->empty_collection();
}
@@ -893,8 +894,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(false);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/unmount/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/unmount/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -906,9 +907,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/unmount/');
$response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/unmount/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
try {

View File

@@ -114,12 +114,13 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$app = $this->getApplication();
$collection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'TESTTODELETE');
$this->XMLHTTPRequest('POST', '/admin/databox/' . $databox->get_sbas_id() . '/collections/order/', [
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $databox->get_sbas_id() . '/collections/order/', [
'order' => [
2 => $collection->get_base_id()
]]);
]
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$this->assertTrue($response->isOk());
$databox->unmount_databox();
$databox->delete();
@@ -197,11 +198,11 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$cgusUpdate = 'Test update CGUS';
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/', [
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/', [
'TOU' => ['fr' => $cgusUpdate]
]);
$this->checkRedirection(self::$DI['client']->getResponse(), '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/?success=1');
$this->checkRedirection($response, '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/?success=1');
$databox = self::$DI['app']->findDataboxById(self::$DI['collection']->get_sbas_id());
$cgus = $databox->get_cgus();
@@ -228,9 +229,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$response = $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$this->assertObjectHasAttribute('sbas_id', $json);
$this->assertObjectHasAttribute('indexable', $json);
@@ -305,8 +306,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(false);
$this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -352,8 +353,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/reindex/');
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/reindex/');
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent());
@@ -382,11 +382,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/indexable/', [
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/indexable/', [
'indexable' => 1
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent());
@@ -418,9 +417,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/clear-logs/');
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/clear-logs/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent());
@@ -451,8 +449,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse());
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/');
$this->assertXMLHTTPBadJsonResponse($response);
}
/**
@@ -467,11 +465,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertEquals('old_databox_name', $databox->get_viewname());
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/', [
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/', [
'viewname' => 'new_databox_name'
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent());
@@ -491,9 +488,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$base = $this->createDatabox();
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/delete/');
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$this->assertObjectHasAttribute('sbas_id', $json);
@@ -557,9 +554,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No logo setted');
}
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/logo/delete/');
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/logo/delete/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$this->assertEmpty(\databox::getPrintLogo(self::$DI['collection']->get_sbas_id()));
}
@@ -573,9 +570,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$base = $this->createDatabox();
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/unmount/');
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/unmount/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$this->assertObjectHasAttribute('sbas_id', $json);
@@ -607,9 +604,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No record were added');
}
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
$this->assertEquals(0, $collection->get_record_amount());
@@ -630,7 +627,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->setAdmin(true);
$base = self::$DI['record_1']->get_databox();
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/labels/', [
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/labels/', [
'labels' => [
'fr' => 'frenchy label',
'en' => '',
@@ -639,10 +636,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
]
]);
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
$this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('content-type'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', $response->headers->get('content-type'));
$data = json_decode(self::$DI['client']->getResponse()->getContent(), true);
$data = json_decode($response->getContent(), true);
$this->assertTrue($data['success']);
$base = $this->getApplication()->findDataboxById($base->get_sbas_id());
@@ -693,9 +690,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No enough records added');
}
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
$response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse());
$json = $this->getJson($response);
$this->assertTrue($json->success);
if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) {

View File

@@ -48,8 +48,7 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
->getMock();
});
$this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', ['lst' => self::$DI['record_1']->get_serialize_key()]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', ['lst' => self::$DI['record_1']->get_serialize_key()]);
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success']);

View File

@@ -75,12 +75,11 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$triggered = true;
});
$this->XMLHTTPRequest('POST', '/prod/order/', [
'lst' => self::$DI['record_1']->get_serialize_key(),
$response = $this->XMLHTTPRequest('POST', '/prod/order/', [
'lst' => self::$DI['record_1']->get_serialize_key(),
'deadline' => '+10 minutes'
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$this->assertTrue($triggered);
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
@@ -97,13 +96,13 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
public function testDisplayOrders()
{
$this->XMLHTTPRequest('POST', '/prod/order/', [
'lst' => self::$DI['record_1']->get_serialize_key(),
'lst' => self::$DI['record_1']->get_serialize_key(),
'deadline' => '+10 minutes'
]);
self::$DI['client']->request('GET', '/prod/order/', [
$response = $this->request('GET', '/prod/order/', [
'sort' => 'usage'
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$this->assertTrue($response->isOk());
}
/**
@@ -151,8 +150,7 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
foreach ($order->getElements() as $element) {
$parameters[] = $element->getId();
}
$this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/send/', ['elements' => $parameters]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/send/', ['elements' => $parameters]);
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent());
@@ -199,8 +197,7 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
foreach ($order->getElements() as $element) {
$parameters[] = $element->getId();
}
$this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/deny/', ['elements' => $parameters]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/deny/', ['elements' => $parameters]);
$this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent());

View File

@@ -19,8 +19,13 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testDisplayStatusProperty()
{
$this->XMLHTTPRequest('GET', '/prod/records/property/', ['lst' => implode(';', [self::$DI['record_no_access']->get_serialize_key(), self::$DI['record_1']->get_serialize_key(), self::$DI['record_4']->get_serialize_key()])]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('GET', '/prod/records/property/', [
'lst' => implode(';', [
self::$DI['record_no_access']->get_serialize_key(),
self::$DI['record_1']->get_serialize_key(),
self::$DI['record_4']->get_serialize_key()
])
]);
$this->assertTrue($response->isOk());
unset($response);
}
@@ -40,10 +45,14 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testDisplayTypeProperty()
{
$this->XMLHTTPRequest('GET', '/prod/records/property/type/',['lst' => implode(';', [self::$DI['record_no_access']->get_serialize_key(), self::$DI['record_1']->get_serialize_key(), self::$DI['record_4']->get_serialize_key()])]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('GET', '/prod/records/property/type/', [
'lst' => implode(';', [
self::$DI['record_no_access']->get_serialize_key(),
self::$DI['record_1']->get_serialize_key(),
self::$DI['record_4']->get_serialize_key()
])
]);
$this->assertTrue($response->isOk());
unset($response);
}
/**

View File

@@ -36,8 +36,7 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
{
$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']);
$this->XMLHTTPRequest('POST', '/prod/records/delete/', ['lst' => $record->get_serialize_key()]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/prod/records/delete/', ['lst' => $record->get_serialize_key()]);
$datas = (array) json_decode($response->getContent());
$this->assertContains($record->get_serialize_key(), $datas);
try {
@@ -46,7 +45,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
} catch (\Exception $e) {
}
unset($response, $datas, $record);
}
/**
@@ -56,12 +54,10 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
{
$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']);
$this->XMLHTTPRequest('POST', '/prod/records/renew-url/', ['lst' => $record->get_serialize_key()]);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/prod/records/renew-url/', ['lst' => $record->get_serialize_key()]);
$datas = (array) json_decode($response->getContent());
$this->assertTrue(count($datas) > 0);
$record->delete();
unset($response, $datas, $record);
}
/**
@@ -92,13 +88,12 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['app']['orm.em']->persist($element);
self::$DI['app']['orm.em']->flush();
$this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'BASK',
'pos' => 0,
'query' => '',
'cont' => $basket->getId(),
$response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'BASK',
'pos' => 0,
'query' => '',
'cont' => $basket->getId(),
]);
$response = self::$DI['client']->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getContent(), true);
@@ -126,14 +121,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$options->onCollections($acl->get_granted_base());
$serializedOptions = $options->serialize();
$this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'RESULT',
$response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'RESULT',
'options_serial' => $serializedOptions,
'pos' => 0,
'query' => ''
'pos' => 0,
'query' => ''
]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent(), true);
$this->assertArrayHasKey('desc', $data);
@@ -145,8 +139,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertArrayHasKey('tools', $data);
$this->assertArrayHasKey('pos', $data);
$this->assertArrayHasKey('title', $data);
unset($response, $data);
}
/**
@@ -157,14 +149,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->authenticate(self::$DI['app']);
self::$DI['record_story_1'];
$this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'REG',
'pos' => 0,
$response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'REG',
'pos' => 0,
'query' => '',
'cont' => self::$DI['record_story_1']->get_serialize_key()
'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);
@@ -175,8 +166,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertObjectHasAttribute('tools', $data);
$this->assertObjectHasAttribute('pos', $data);
$this->assertObjectHasAttribute('title', $data);
unset($response, $data);
}
/**
@@ -187,14 +176,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->authenticate(self::$DI['app']);
$basket = self::$DI['app']['orm.em']->find('Phraseanet:Basket', 1);
$this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'BASK',
'pos' => 0,
$response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'BASK',
'pos' => 0,
'query' => '',
'cont' => $basket->getId()
'cont' => $basket->getId()
]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent());
$this->assertObjectHasAttribute('desc', $data);
@@ -224,14 +212,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$feed = self::$DI['app']['orm.em']->find('Phraseanet:Feed', 1);
$feedEntry = $feed->getEntries()->first();
$this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'FEED',
'pos' => 0,
$response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'FEED',
'pos' => 0,
'query' => '',
'cont' => $feedEntry->getId()
'cont' => $feedEntry->getId()
]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent());
$this->assertObjectHasAttribute('desc', $data);
$this->assertObjectHasAttribute('html_preview', $data);

View File

@@ -34,10 +34,8 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testGetTOUAJAX()
{
$this->XMLHTTPRequest('GET', '/prod/TOU/');
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('GET', '/prod/TOU/');
$this->assertTrue($response->isOk());
unset($response);
}
/**
@@ -48,8 +46,7 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase
$databoxes = self::$DI['app']->getDataboxes();
$databox = array_shift($databoxes);
self::$DI['app']['authentication']->setUser(self::$DI['user_alt2']);
$this->XMLHTTPRequest('POST', '/prod/TOU/deny/'.$databox->get_sbas_id() .'/');
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/prod/TOU/deny/' . $databox->get_sbas_id() . '/');
$this->assertTrue($response->isOk());
unset($response, $databoxes);

View File

@@ -34,13 +34,11 @@ class RootTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('GET', '/report/dashboard', [
$response = $this->XMLHTTPRequest('GET', '/report/dashboard', [
'dmin' => $this->dmin->format('Y-m-d'),
'dmax' => $this->dmin->format('Y-m-d'),
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
}

View File

@@ -115,10 +115,10 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testDeleteAppError()
{
$this->XMLHTTPRequest('DELETE', '/developers/application/0/');
$response = $this->XMLHTTPRequest('DELETE', '/developers/application/0/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertFalse($content->success);
}
@@ -134,8 +134,8 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
'http://phraseanet.com/'
);
$id = $oauthApp->getId();
$this->XMLHTTPRequest('DELETE', '/developers/application/' . $id . '/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$response = $this->XMLHTTPRequest('DELETE', '/developers/application/' . $id . '/');
$this->assertTrue($response->isOk());
$this->assertNull(self::$DI['app']['repo.api-applications']->find($id));
}
@@ -155,12 +155,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testRenewAppCallbackError()
{
$this->XMLHTTPRequest('POST', '/developers/application/0/callback/', [
$response = $this->XMLHTTPRequest('POST', '/developers/application/0/callback/', [
'callback' => 'my.callback.com'
]);
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertFalse($content->success);
}
@@ -170,9 +170,9 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
public function testRenewAppCallbackError2()
{
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/'.$oauthApp->getId().'/callback/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/');
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertFalse($content->success);
}
@@ -183,12 +183,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
{
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/', [
$response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/', [
'callback' => 'http://my.callback.com'
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertTrue($content->success);
$oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId());
$this->assertEquals('http://my.callback.com', $oauthApp->getRedirectUri());
@@ -209,12 +209,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testRenewAccessTokenError()
{
$this->XMLHTTPRequest('POST', '/developers/application/0/access_token/', [
$response = $this->XMLHTTPRequest('POST', '/developers/application/0/access_token/', [
'callback' => 'my.callback.com'
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertFalse($content->success);
}
@@ -225,10 +225,10 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
{
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/access_token/');
$response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/access_token/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertTrue($content->success);
$this->assertNotNull($content->token);
}
@@ -248,12 +248,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testAuthorizeGrantpasswordError()
{
$this->XMLHTTPRequest('POST', '/developers/application/0/authorize_grant_password/', [
$response = $this->XMLHTTPRequest('POST', '/developers/application/0/authorize_grant_password/', [
'callback' => 'my.callback.com'
]);
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertFalse($content->success);
}
@@ -264,12 +264,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
{
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/authorize_grant_password/', [
$response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/authorize_grant_password/', [
'grant' => '1'
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$content = json_decode($response->getContent());
$this->assertTrue($content->success);
$oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId());
$this->assertTrue($oauthApp->isPasswordGranted());

View File

@@ -19,9 +19,9 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
public function testUpdSessionLogout()
{
$this->logout(self::$DI['app']);
$this->XMLHTTPRequest('POST', '/session/update/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
$response = $this->XMLHTTPRequest('POST', '/session/update/');
$this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->checkSessionReturn($datas);
$this->assertEquals('disconnected', $datas->status);
}
@@ -31,11 +31,11 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testUpdSessionChangeUser()
{
$this->XMLHTTPRequest('POST', '/session/update/', [
$response = $this->XMLHTTPRequest('POST', '/session/update/', [
'usr' => self::$DI['user_alt1']->getId()
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->checkSessionReturn($datas);
$this->assertEquals('disconnected', $datas->status);
}
@@ -49,13 +49,12 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
/** @var User $user */
$user = self::$DI['user'];
$this->XMLHTTPRequest('POST', '/session/update/', [
$response = $this->XMLHTTPRequest('POST', '/session/update/', [
'usr' => $user->getId(),
'module' => 1
]);
$client = $this->getClient();
$this->assertTrue($client->getResponse()->isOk());
$data = json_decode($client->getResponse()->getContent());
$this->assertTrue($response->isOk());
$data = json_decode($response->getContent());
$this->checkSessionReturn($data);
$this->assertEquals('ok', $data->status);
}
@@ -67,12 +66,12 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('POST', '/session/update/', [
$response = $this->XMLHTTPRequest('POST', '/session/update/', [
'usr' => self::$DI['user']->getId()
]);
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
$datas = json_decode($response->getContent());
$datas = json_decode($response->getContent());
$this->checkSessionReturn($datas);
$this->assertEquals('unknown', $datas->status);
}
@@ -118,8 +117,8 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
->will($this->returnValue(null));
self::$DI['app']['orm.em'] = $em;
$this->XMLHTTPRequest('POST', '/session/delete/1');
$this->assertTrue(self::$DI['client']->getResponse()->isOK());
$response = $this->XMLHTTPRequest('POST', '/session/delete/1');
$this->assertTrue($response->isOK());
}
public function testDeleteSessionUnauthorized()

View File

@@ -17,10 +17,8 @@ class NotificationsTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testListNotifications()
{
$this->XMLHTTPRequest('GET', '/user/notifications/');
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('GET', '/user/notifications/');
$this->assertTrue($response->isOk());
unset($response);
}
/**
@@ -48,16 +46,14 @@ class NotificationsTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testSetNotificationsReaded()
{
$this->XMLHTTPRequest('POST', '/user/notifications/read/', [
$response = $this->XMLHTTPRequest('POST', '/user/notifications/read/', [
'notifications' => ''
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success'], $response->getContent());
$this->assertArrayHasKey('message', $datas);
unset($response);
}
/**

View File

@@ -17,8 +17,7 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testSaveUserPref()
{
$this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']);
$this->assertTrue($response->isOk());
$this->assertTrue(json_decode($response->getContent())->success);
$this->assertEquals('val_test', self::$DI['app']['settings']->getUserSetting(self::$DI['user'], 'prop_test'));
@@ -49,8 +48,10 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testSaveTemporaryPref()
{
$this->XMLHTTPRequest('POST', "/user/preferences/temporary/", ['prop' => 'prop_test', 'value' => 'val_test']);
$response = self::$DI['client']->getResponse();
$response = $this->XMLHTTPRequest('POST', "/user/preferences/temporary/", [
'prop' => 'prop_test',
'value' => 'val_test'
]);
$this->assertTrue($response->isOk());
$this->assertTrue(json_decode($response->getContent())->success);
$this->assertEquals('val_test', self::$DI['app']['session']->get('phraseanet.prop_test'));