diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php index d8d19f74cf..c1a404b294 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php @@ -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 = ' 0 my_new_value '; - $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 = ' '; - $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 { diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php index 61dabd3af2..45630c4bc6 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php @@ -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) { diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php index 9782a41dc1..b7a42e6448 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php @@ -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']); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php index fc838ed95b..069ced705a 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php @@ -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()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php index 6cc15e8318..c0d2088b82 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php @@ -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); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index 898e0049f0..e8bfa58d8f 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php @@ -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); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php index 78b38c5c8d..792b23e2a6 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php @@ -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); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php index 865b29dfb0..ed4edb22b5 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php @@ -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()); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php index 7fefc9ee5f..f3fbc55fb5 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php @@ -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()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php index c5d176ca0c..1c0f34f26f 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php @@ -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() diff --git a/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php index 65e1f2a182..6b67f97b60 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php @@ -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); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php b/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php index 2adbe080c7..2b1251e1ad 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php @@ -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')); diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index 8da9666e7d..3a57ad97f7 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -484,6 +484,24 @@ abstract class PhraseanetTestCase extends WebTestCase }); } + /** + * @param string $method + * @param string $uri + * @param array $parameters + * @param array $server + * @param string $content + * + * @return Response + */ + protected function request($method, $uri, array $parameters = [], array $server = [], $content = null) + { + $client = $this->getClient(); + + $client->request($method, $uri, $parameters, [], $server, $content); + + return $client->getResponse(); + } + /** * Calls a URI as XMLHTTP request. * @@ -492,11 +510,11 @@ abstract class PhraseanetTestCase extends WebTestCase * @param array $parameters The Request parameters * @param string $httpAccept Contents of the Accept header * - * @return Crawler + * @return Response */ protected function XMLHTTPRequest($method, $uri, array $parameters = [], $httpAccept = 'application/json') { - return self::$DI['client']->request($method, $uri, $parameters, [], [ + return $this->request($method, $uri, $parameters, [ 'HTTP_ACCEPT' => $httpAccept, 'HTTP_X-Requested-With' => 'XMLHttpRequest', ]);