Fix unit tests

This commit is contained in:
Romain Neutron
2013-01-24 17:04:50 +01:00
parent 6dcdd4e892
commit 62a27940b9
29 changed files with 163 additions and 153 deletions

View File

@@ -123,17 +123,17 @@ class ApplicationSpecification implements SpecificationInterface
$this->delete(); $this->delete();
copy( copy(
$this->getRealRootPath() . "/conf.d/connexions.yml" $this->getRealRootPath() . "/lib/conf.d/connexions.yml"
, $this->getConnexionsPathFile() , $this->getConnexionsPathFile()
); );
copy( copy(
$this->getRealRootPath() . "/conf.d/services.yml" $this->getRealRootPath() . "/lib/conf.d/services.yml"
, $this->getServicesPathFile() , $this->getServicesPathFile()
); );
copy( copy(
$this->getRealRootPath() . "/conf.d/config.yml" $this->getRealRootPath() . "/lib/conf.d/config.yml"
, $this->getConfigurationsPathFile() , $this->getConfigurationsPathFile()
); );

View File

@@ -31,7 +31,7 @@ class Builder
} }
try { try {
$options = $configuration->get("options"); $options = $configuration->get("options") ?: array() ;
} catch (\Exception $e) { } catch (\Exception $e) {
$options = array(); $options = array();
} }

View File

@@ -40,12 +40,12 @@ class TaskManager extends ServiceAbstract
$options = $this->getOptions(); $options = $this->getOptions();
$registry = $this->app['phraseanet.registry']; $registry = $this->app['phraseanet.registry'];
if (null !== $syslogLevel = constant($options['syslog_level'])) { if (isset($options['syslog_level']) && null !== $syslogLevel = constant($options['syslog_level'])) {
$handler = new SyslogHandler("Phraseanet-Task", "user", $syslogLevel); $handler = new SyslogHandler("Phraseanet-Task", "user", $syslogLevel);
$logger->pushHandler($handler); $logger->pushHandler($handler);
} }
if (null !== $maillogLevel = constant($options['maillog_level'])) { if (isset($options['maillog_level']) && null !== $maillogLevel = constant($options['maillog_level'])) {
if ('' === $adminMail = trim($registry->get('GV_adminMail'))) { if ('' === $adminMail = trim($registry->get('GV_adminMail'))) {
throw new RuntimeException("Admininstrator mail must be set to get log by mail."); throw new RuntimeException("Admininstrator mail must be set to get log by mail.");
} }

View File

@@ -2089,7 +2089,7 @@ class task_period_archive extends task_abstract
$fields = caption_field::get_multi_values($field, $meta->get_separator()); $fields = caption_field::get_multi_values($field, $meta->get_separator());
if (!$metadataBag->containsKey($meta->get_name())) { if (!$metadataBag->containsKey($meta->get_name())) {
$values = new \PHPExiftool\Driver\Value\Multi($fields); $values = $fields;
} else { } else {
$values = array_merge($metadataBag->get($meta->get_name())->getValue(), $fields); $values = array_merge($metadataBag->get($meta->get_name())->getValue(), $fields);
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Tests\Phrasea\Application;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Exception\HttpException;
class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
@@ -20,12 +19,11 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
$this->assertEquals(self::$DI['record_1']->get_preview()->get_size(), $response->headers->get('content-length')); $this->assertEquals(self::$DI['record_1']->get_preview()->get_size(), $response->headers->get('content-length'));
} }
/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
function testDatafilesNonExistentSubdef() function testDatafilesNonExistentSubdef()
{ {
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/asubdefthatdoesnotexists/'); self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/asubdefthatdoesnotexists/');
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
function testEtag() function testEtag()
@@ -58,25 +56,17 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
function testDatafilesRouteNotAuthenticated() function testDatafilesRouteNotAuthenticated()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
try { self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
$this->fail('should throw an HttpException'); $this->assertForbiddenResponse(self::$DI['client']->getResponse());
} catch (HttpException $e) {
$response = self::$DI['client']->getResponse();
$this->assertEquals(403, $e->getStatusCode());
}
} }
function testDatafilesRouteNotAuthenticatedUnknownSubdef() function testDatafilesRouteNotAuthenticatedUnknownSubdef()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
try { self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/notfoundreview/');
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/notfoundreview/');
$this->fail('should throw an HttpException'); $this->assertForbiddenResponse(self::$DI['client']->getResponse());
} catch (HttpException $e) {
$response = self::$DI['client']->getResponse();
$this->assertEquals(403, $e->getStatusCode());
}
} }
function testPermalinkAuthenticated() function testPermalinkAuthenticated()

View File

@@ -10,12 +10,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
protected $client; protected $client;
public static $createdCollections = array(); public static $createdCollections = array();
public function setUp()
{
parent::setUp();
self::$DI['app.use-exception-handler'] = true;
}
public function tearDown() public function tearDown()
{ {
self::$DI['app']['phraseanet.user'] = self::$DI['user']; self::$DI['app']['phraseanet.user'] = self::$DI['user'];
@@ -192,7 +186,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::enable * @covers Alchemy\Phrasea\Controller\Admin\Bas::enable
*/ */
public function testPostEnableUnauthorizedException() public function testPostEnableUnauthorizedException()
@@ -200,6 +193,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -232,7 +227,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled * @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled
*/ */
public function testPostDisabledUnauthorizedException() public function testPostDisabledUnauthorizedException()
@@ -240,6 +234,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -259,7 +255,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setOrderAdmins * @covers Alchemy\Phrasea\Controller\Admin\Bas::setOrderAdmins
*/ */
public function testPostOrderAdminsUnauthorizedException() public function testPostOrderAdminsUnauthorizedException()
@@ -267,6 +262,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/order/admins/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/order/admins/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -300,7 +297,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay
*/ */
public function testPostPublicationDisplayUnauthorizedException() public function testPostPublicationDisplayUnauthorizedException()
@@ -308,6 +304,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -356,7 +354,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::rename * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename
*/ */
public function testPostNameUnauthorizedException() public function testPostNameUnauthorizedException()
@@ -364,6 +361,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -509,7 +508,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo * @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo
*/ */
public function testSetMiniLogoBadRequest() public function testSetMiniLogoBadRequest()
@@ -517,10 +515,11 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setStamp * @covers Alchemy\Phrasea\Controller\Admin\Bas::setStamp
*/ */
public function testSetStampBadRequest() public function testSetStampBadRequest()
@@ -528,19 +527,21 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setWatermark * @covers Alchemy\Phrasea\Controller\Admin\Bas::setWatermark
*/ */
public function testSetWatermarkBadRequest() public function testSetWatermarkBadRequest()
{ {
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner * @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner
*/ */
public function testSetBannerBadRequest() public function testSetBannerBadRequest()
@@ -548,6 +549,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -741,7 +744,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection * @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection
*/ */
public function testGetCollectionUnauthorizedException() public function testGetCollectionUnauthorizedException()
@@ -749,10 +751,11 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/'); self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::getSuggestedValues * @covers Alchemy\Phrasea\Controller\Admin\Bas::getSuggestedValues
*/ */
public function testGetSuggestedValuesUnauthorizedException() public function testGetSuggestedValuesUnauthorizedException()
@@ -760,10 +763,11 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/'); self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::getDetails * @covers Alchemy\Phrasea\Controller\Admin\Bas::getDetails
*/ */
public function testInformationsDetailsUnauthorizedException() public function testInformationsDetailsUnauthorizedException()
@@ -771,6 +775,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/informations/details/'); self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/informations/details/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -788,7 +794,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::delete * @covers Alchemy\Phrasea\Controller\Admin\Bas::delete
*/ */
public function testDeleteCollectionUnauthorized() public function testDeleteCollectionUnauthorized()
@@ -796,6 +801,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/delete/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/delete/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -7,7 +7,6 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
protected $client; protected $client;
/** /**
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::slash * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::slash
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::connect * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::connect
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::call * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::call
@@ -16,6 +15,8 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/dashboard/'); self::$DI['client']->request('GET', '/admin/dashboard/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -62,7 +63,6 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::sendMail * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::sendMail
*/ */
public function testSendMailTestBadRequest() public function testSendMailTestBadRequest()
@@ -70,6 +70,8 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/'); self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::resetAdminRights * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::resetAdminRights

View File

@@ -126,7 +126,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetCGUHasNoRights() public function testGetCGUHasNoRights()
{ {
@@ -138,6 +137,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -199,7 +200,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos
*/ */
public function testGetInformationDocumentBadRequest() public function testGetInformationDocumentBadRequest()
@@ -207,6 +207,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -252,7 +254,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase
*/ */
public function testGetDataboxUnauthorizedException() public function testGetDataboxUnauthorizedException()
@@ -260,10 +261,11 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getReorder * @covers \Alchemy\Phrasea\Controller\Admin\Database::getReorder
*/ */
public function testGetCollectionOrderUnauthorizedException() public function testGetCollectionOrderUnauthorizedException()
@@ -271,10 +273,11 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collections/order/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collections/order/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU
*/ */
public function testGetCGUUnauthorizedException() public function testGetCGUUnauthorizedException()
@@ -282,6 +285,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -297,7 +302,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos
*/ */
public function testGetInformationDetailsUnauthorizedException() public function testGetInformationDetailsUnauthorizedException()
@@ -305,10 +309,11 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/details/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/details/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getNewCollection * @covers \Alchemy\Phrasea\Controller\Admin\Database::getNewCollection
*/ */
public function testGetNewCollectionUnauthorizedException() public function testGetNewCollectionUnauthorizedException()
@@ -316,6 +321,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collection/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collection/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -39,13 +39,14 @@ class DataboxesTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Admin\Databases::getDatabases * @covers Alchemy\Phrasea\Controller\Admin\Databases::getDatabases
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetSlashUnauthorizedException() public function testGetSlashUnauthorizedException()
{ {
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databoxes/'); self::$DI['client']->request('GET', '/admin/databoxes/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -2,8 +2,6 @@
namespace Alchemy\Tests\Phrasea\Controller\Admin; namespace Alchemy\Tests\Phrasea\Controller\Admin;
use Symfony\Component\HttpKernel\Exception\HttpException;
class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client; protected $client;
@@ -186,23 +184,19 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$field = \databox_field::create(self::$DI['app'], $databox, $name, false); $field = \databox_field::create(self::$DI['app'], $databox, $name, false);
$id = $field->get_id(); $id = $field->get_id();
try { self::$DI['client']->request("POST", "/admin/description/" . $databox->get_sbas_id() . "/", array(
self::$DI['client']->request("POST", "/admin/description/" . $databox->get_sbas_id() . "/", array( 'field_ids' => array($id)
'field_ids' => array($id) , 'name_' . $id => $name
, 'name_' . $id => $name , 'multi_' . $id => 1
, 'multi_' . $id => 1 , 'indexable_' . $id => 1
, 'indexable_' . $id => 1 , 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories' , 'required_' . $id => 0
, 'required_' . $id => 0 , 'readonly_' . $id => 0
, 'readonly_' . $id => 0 , 'type_' . $id => 'string'
, 'type_' . $id => 'string' , 'vocabulary_' . $id => 'User'
, 'vocabulary_' . $id => 'User' ));
));
print(self::$DI['client']->getResponse()->getContent());
$this->fail('Should throw an HttpException');
} catch (HttpException $e) {
} $this->assertForbiddenResponse(self::$DI['client']->getResponse());
$field->delete(); $field->delete();
} }
@@ -214,12 +208,9 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes(); $databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
$databox = array_shift($databoxes); $databox = array_shift($databoxes);
try { self::$DI['client']->request("GET", "/admin/description/" . $databox->get_sbas_id() . "/");
self::$DI['client']->request("GET", "/admin/description/" . $databox->get_sbas_id() . "/");
$this->fail('Should throw an HttpException');
} catch (HttpException $e) {
} $this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
public function testGetDescription() public function testGetDescription()

View File

@@ -8,12 +8,6 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic
public static $api = null; public static $api = null;
protected $client; protected $client;
public function setUp()
{
parent::setUp();
self::$DI['app.use-exception-handler'] = true;
}
public function testList() public function testList()
{ {
$crawler = self::$DI['client']->request('GET', '/admin/publications/list/'); $crawler = self::$DI['client']->request('GET', '/admin/publications/list/');

View File

@@ -18,14 +18,14 @@ class SetupTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Admin\Setup::getGlobals * @covers Alchemy\Phrasea\Controller\Admin\Setup::getGlobals
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetSlashUnauthorizedException() public function testGetSlashUnauthorizedException()
{ {
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/setup/'); self::$DI['client']->request('GET', '/admin/setup/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -46,22 +46,26 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPrepareDownloadTokenNotFound() public function testPrepareDownloadTokenNotFound()
{ {
$token = 'AzBdisusjA'; $token = 'AzBdisusjA';
self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token)); self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token));
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPrepareDownloadInvalidData() public function testPrepareDownloadInvalidData()
{ {
$token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail'))))); $token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail')))));
self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token)); self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token));
$response = self::$DI['client']->getResponse();
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'internal server error'));
} }
/** /**
@@ -185,7 +189,6 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDocumentsDownloadNotFound() public function testDocumentsDownloadNotFound()
{ {
@@ -215,29 +218,32 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
)); ));
$url = sprintf('/download/%s/get/', $token); $url = sprintf('/download/%s/get/', $token);
self::$DI['client']->request('POST', $url); self::$DI['client']->request('POST', $url);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertNotFoundResponse(self::$DI['client']->getResponse());
unset($response);
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDocumentsDownloadTokenNotFound() public function testDocumentsDownloadTokenNotFound()
{ {
$token = 'AzBdisusjA'; $token = 'AzBdisusjA';
self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token)); self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token));
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDocumentsDownloadInvalidData() public function testDocumentsDownloadInvalidData()
{ {
$token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail'))))); $token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail')))));
self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token)); self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token));
$response = self::$DI['client']->getResponse();
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'internal server error'));
} }
/** /**

View File

@@ -76,7 +76,6 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Export::testFtpConnexion * @covers Alchemy\Phrasea\Controller\Prod\Export::testFtpConnexion
*/ */
public function testFtpConnexionNoXMLHTTPRequests() public function testFtpConnexionNoXMLHTTPRequests()
@@ -98,10 +97,8 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key())); self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key()));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas);
$this->assertFalse($datas['success']); $this->assertBadResponse(self::$DI['client']->getResponse());
$this->assertArrayHasKey('message', $datas);
unset($response, $datas);
} }
/** /**
@@ -126,13 +123,14 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp * @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp
* @dataProvider getMissingArguments * @dataProvider getMissingArguments
*/ */
public function testExportFtpBadRequest($params) public function testExportFtpBadRequest($params)
{ {
self::$DI['client']->request('POST', '/prod/export/ftp/', $params); self::$DI['client']->request('POST', '/prod/export/ftp/', $params);
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
public function getMissingArguments() public function getMissingArguments()

View File

@@ -10,26 +10,21 @@ class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
self::$DI['client']->request('GET', '/prod/MustacheLoader/'); self::$DI['client']->request('GET', '/prod/MustacheLoader/');
$response = self::$DI['client']->getResponse(); $this->assertBadResponse(self::$DI['client']->getResponse());
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(400, $response->getStatusCode());
} }
public function testRouteSlashWrongUrl() public function testRouteSlashWrongUrl()
{ {
self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/config.yml')); self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/config.yml'));
$response = self::$DI['client']->getResponse(); $this->assertBadResponse(self::$DI['client']->getResponse());
$this->assertEquals(400, $response->getStatusCode());
/* @var $response \Symfony\Component\HttpFoundation\Response */
} }
public function testRouteSlashWrongFile() public function testRouteSlashWrongFile()
{ {
self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => 'patator_lala')); self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => 'patator_lala'));
$response = self::$DI['client']->getResponse(); $this->assertNotFoundResponse(self::$DI['client']->getResponse());
$this->assertEquals(404, $response->getStatusCode());
} }
public function testRouteGood() public function testRouteGood()

View File

@@ -20,12 +20,13 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Property::displayStatusProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayStatusProperty
*/ */
public function testDisplayStatusPropertyNotXMLHTTPRequets() public function testDisplayStatusPropertyNotXMLHTTPRequets()
{ {
self::$DI['client']->request('GET', '/prod/records/property/'); self::$DI['client']->request('GET', '/prod/records/property/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -40,12 +41,13 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Property::displayProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayProperty
*/ */
public function testDisplayTypePropertyNotXMLHTTPRequets() public function testDisplayTypePropertyNotXMLHTTPRequets()
{ {
self::$DI['client']->request('GET', '/prod/records/property/type/'); self::$DI['client']->request('GET', '/prod/records/property/type/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -70,11 +70,12 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetRecordDetailNotAjax() public function testGetRecordDetailNotAjax()
{ {
self::$DI['client']->request('POST', '/prod/records/'); self::$DI['client']->request('POST', '/prod/records/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -18,25 +18,22 @@ class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testRouteBasketFail() public function testRouteBasketFail()
{ {
$crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/notanid/'); $crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/notanid/');
$pageContent = self::$DI['client']->getResponse()->getContent(); $pageContent = self::$DI['client']->getResponse()->getContent();
$this->assertFalse(self::$DI['client']->getResponse()->isOk()); $this->assertFalse(self::$DI['client']->getResponse()->isOk());
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testRouteBasketFail2() public function testRouteBasketFail2()
{ {
$crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/-5/'); $crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/-5/');
$pageContent = self::$DI['client']->getResponse()->getContent(); $pageContent = self::$DI['client']->getResponse()->getContent();
$this->assertFalse(self::$DI['client']->getResponse()->isOk()); $this->assertFalse(self::$DI['client']->getResponse()->isOk());
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
public function testRoutePreview() public function testRoutePreview()

View File

@@ -20,7 +20,6 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
self::$DI['app.use-exception-handler'] = true;
$this->tmpFile = sys_get_temp_dir() . '/' . time() . mt_rand(1000, 9999) . '.jpg'; $this->tmpFile = sys_get_temp_dir() . '/' . time() . mt_rand(1000, 9999) . '.jpg';
copy(__DIR__ . '/../../../../../files/cestlafete.jpg', $this->tmpFile); copy(__DIR__ . '/../../../../../files/cestlafete.jpg', $this->tmpFile);
} }

View File

@@ -241,7 +241,7 @@ class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertBadResponse($response);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
@@ -251,11 +251,9 @@ class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertBadResponse($response);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$route = '/prod/lists/list/' . $list->getId() . '/share/' . self::$DI['user_alt1']->get_id() . '/'; $route = '/prod/lists/list/' . $list->getId() . '/share/' . self::$DI['user_alt1']->get_id() . '/';
self::$DI['client']->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN)); self::$DI['client']->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));

View File

@@ -28,8 +28,7 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['client']->request('POST', $route); self::$DI['client']->request('POST', $route);
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertBadResponse(self::$DI['client']->getResponse());
$this->assertFalse($response->isOk());
} }
public function testAttachStoryToWZ() public function testAttachStoryToWZ()
@@ -146,8 +145,7 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['client']->request('POST', $route); self::$DI['client']->request('POST', $route);
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(404, $response->getStatusCode()); $this->assertNotFoundResponse(self::$DI['client']->getResponse());
$this->assertFalse($response->isOk());
//attach //attach
$attachRoute = sprintf("/prod/WorkZone/attachStories/"); $attachRoute = sprintf("/prod/WorkZone/attachStories/");

View File

@@ -120,11 +120,12 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail * @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPostResetMailBadRequest() public function testPostResetMailBadRequest()
{ {
self::$DI['client']->request('POST', '/account/reset-email/'); self::$DI['client']->request('POST', '/account/reset-email/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -363,12 +364,11 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(count($ret), count($bases)); $this->assertEquals(count($ret), count($bases));
} }
/**
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testAUthorizedAppGrantAccessBadRequest() public function testAUthorizedAppGrantAccessBadRequest()
{ {
self::$DI['client']->request('GET', '/account/security/application/3/grant/'); self::$DI['client']->request('GET', '/account/security/application/3/grant/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
public function testAUthorizedAppGrantAccessNotSuccessfull() public function testAUthorizedAppGrantAccessNotSuccessfull()

View File

@@ -74,11 +74,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::getApp * @cover \Alchemy\Phrasea\Controller\Root\Developers::getApp
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetUnknowApp() public function testGetUnknowApp()
{ {
self::$DI['client']->request('GET', '/developers/application/0/'); self::$DI['client']->request('GET', '/developers/application/0/');
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -94,11 +95,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::deleteApp * @cover \Alchemy\Phrasea\Controller\Root\Developers::deleteApp
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDeleteAppBadRequest() public function testDeleteAppBadRequest()
{ {
self::$DI['client']->request('DELETE', '/developers/application/1/'); self::$DI['client']->request('DELETE', '/developers/application/1/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -134,11 +136,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAppCallback * @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAppCallback
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testRenewAppCallbackBadRequest() public function testRenewAppCallbackBadRequest()
{ {
self::$DI['client']->request('POST', '/developers/application/1/callback/'); self::$DI['client']->request('POST', '/developers/application/1/callback/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -189,11 +192,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAccessToken * @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAccessToken
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testRenewAccessTokenbadRequest() public function testRenewAccessTokenbadRequest()
{ {
self::$DI['client']->request('POST', '/developers/application/1/access_token/'); self::$DI['client']->request('POST', '/developers/application/1/access_token/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -228,11 +232,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::authorizeGrantpassword * @cover \Alchemy\Phrasea\Controller\Root\Developers::authorizeGrantpassword
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testAuthorizeGrantpasswordBadRequest() public function testAuthorizeGrantpasswordBadRequest()
{ {
self::$DI['client']->request('POST', '/developers/application/1/authorize_grant_password/'); self::$DI['client']->request('POST', '/developers/application/1/authorize_grant_password/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -386,12 +386,13 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Login::register * @covers \Alchemy\Phrasea\Controller\Root\Login::register
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPostRegisterBadRequest() public function testPostRegisterBadRequest()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
self::$DI['client']->request('POST', '/login/register/'); self::$DI['client']->request('POST', '/login/register/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -618,12 +619,13 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Login::sendConfirmMail * @covers \Alchemy\Phrasea\Controller\Root\Login::sendConfirmMail
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testSendConfirmMailBadRequest() public function testSendConfirmMailBadRequest()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
self::$DI['client']->request('GET', '/login/send-mail-confirm/'); self::$DI['client']->request('GET', '/login/send-mail-confirm/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -74,7 +74,6 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
self::$DI['app.use-exception-handler'] = true;
self::$feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'title', 'subtitle'); self::$feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'title', 'subtitle');
self::$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']); self::$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']);
self::$entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, self::$publisher, 'title_entry', 'subtitle', 'hello', "test@mail.com"); self::$entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, self::$publisher, 'title_entry', 'subtitle', 'hello', "test@mail.com");
@@ -334,12 +333,11 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testUnknowFeedId2() public function testUnknowFeedId2()
{ {
self::$DI['client']->request("GET", "/feeds/feed/titi/"); self::$DI['client']->request("GET", "/feeds/feed/titi/");
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
public function testGetFeedId() public function testGetFeedId()

View File

@@ -70,11 +70,12 @@ class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession * @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testUpdSessionBadRequest() public function testUpdSessionBadRequest()
{ {
self::$DI['client']->request('POST', '/session/update/'); self::$DI['client']->request('POST', '/session/update/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
private function checkSessionReturn(\stdClass $data) private function checkSessionReturn(\stdClass $data)

View File

@@ -18,21 +18,23 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Notifications::listNotifications * @covers Alchemy\Phrasea\Controller\User\Notifications::listNotifications
*/ */
public function testListNotificationsNoXMLHTTPRequests() public function testListNotificationsNoXMLHTTPRequests()
{ {
self::$DI['client']->request('GET', '/user/notifications/'); self::$DI['client']->request('GET', '/user/notifications/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Notifications::setNotificationsReaded * @covers Alchemy\Phrasea\Controller\User\Notifications::setNotificationsReaded
*/ */
public function testSetNotificationsReadedNoXMLHTTPRequests() public function testSetNotificationsReadedNoXMLHTTPRequests()
{ {
self::$DI['client']->request('POST', '/user/notifications/read/'); self::$DI['client']->request('POST', '/user/notifications/read/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -53,7 +55,6 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Notifications::connect * @covers Alchemy\Phrasea\Controller\User\Notifications::connect
* @covers Alchemy\Phrasea\Controller\User\Notifications::call * @covers Alchemy\Phrasea\Controller\User\Notifications::call
*/ */
@@ -69,5 +70,7 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->will($this->returnValue(true)); ->will($this->returnValue(true));
self::$DI['client']->request('GET', '/user/notifications/'); self::$DI['client']->request('GET', '/user/notifications/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
} }

View File

@@ -32,21 +32,23 @@ class PreferencesTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Preferences::saveUserPref * @covers Alchemy\Phrasea\Controller\User\Preferences::saveUserPref
*/ */
public function testSaveUserPrefNoXMLHTTPRequests() public function testSaveUserPrefNoXMLHTTPRequests()
{ {
self::$DI['client']->request('POST', '/user/preferences/', array('prop' => 'prop_test', 'value' => 'val_test')); self::$DI['client']->request('POST', '/user/preferences/', array('prop' => 'prop_test', 'value' => 'val_test'));
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Preferences::saveTemporaryPref * @covers Alchemy\Phrasea\Controller\User\Preferences::saveTemporaryPref
*/ */
public function testSaveTempPrefNoXMLHTTPRequests() public function testSaveTempPrefNoXMLHTTPRequests()
{ {
self::$DI['client']->request('POST', '/user/preferences/temporary/', array('prop' => 'prop_test', 'value' => 'val_test')); self::$DI['client']->request('POST', '/user/preferences/temporary/', array('prop' => 'prop_test', 'value' => 'val_test'));
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -100,8 +100,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
parent::setUp(); parent::setUp();
self::$DI['app.use-exception-handler'] = false;
\PHPUnit_Framework_Error_Warning::$enabled = true; \PHPUnit_Framework_Error_Warning::$enabled = true;
\PHPUnit_Framework_Error_Notice::$enabled = true; \PHPUnit_Framework_Error_Notice::$enabled = true;
@@ -112,10 +110,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$app['debug'] = true; $app['debug'] = true;
if (!$DI['app.use-exception-handler']) {
unset($app['exception_handler']);
}
$app['EM'] = $app->share($app->extend('EM', function($em) { $app['EM'] = $app->share($app->extend('EM', function($em) {
@unlink('/tmp/db.sqlite'); @unlink('/tmp/db.sqlite');
copy(__DIR__ . '/../db-ref.sqlite', '/tmp/db.sqlite'); copy(__DIR__ . '/../db-ref.sqlite', '/tmp/db.sqlite');
@@ -169,6 +163,25 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
set_time_limit(0); set_time_limit(0);
} }
protected function assertForbiddenResponse(Response $response)
{
$this->assertEquals(403, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'forbidden'));
}
protected function assertBadResponse(Response $response)
{
$this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'bad request'));
}
protected function assertNotFoundResponse(Response $response)
{
$this->assertEquals(404, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'not found'));
}
/** /**
* Insert fixture contained in the specified fixtureLoader * Insert fixture contained in the specified fixtureLoader
* into sqlLite test temporary database * into sqlLite test temporary database