Fixup some tests using UserManipulator

This commit is contained in:
Benoît Burnichon
2015-11-03 17:41:48 +01:00
parent 67a9f9e106
commit 8ad5d05e43
3 changed files with 28 additions and 10 deletions

View File

@@ -839,7 +839,14 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testSearchRoute()
{
self::$DI['app']['manipulator.user'] = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')
->setConstructorArgs([self::$DI['app']['model.user-manager'], self::$DI['app']['auth.password-encoder'], self::$DI['app']['geonames.connector'], self::$DI['app']['repo.users'], self::$DI['app']['random.low']])
->setConstructorArgs([
self::$DI['app']['model.user-manager'],
self::$DI['app']['auth.password-encoder'],
self::$DI['app']['geonames.connector'],
self::$DI['app']['repo.users'],
self::$DI['app']['random.low'],
self::$DI['app']['dispatcher'],
])
->setMethods(['logQuery'])
->getMock();

View File

@@ -21,16 +21,26 @@ class QueryTest extends \PhraseanetAuthenticatedWebTestCase
{
$route = '/prod/query/';
self::$DI['app']['manipulator.user'] = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')
->setConstructorArgs([self::$DI['app']['model.user-manager'], self::$DI['app']['auth.password-encoder'], self::$DI['app']['geonames.connector'], self::$DI['app']['repo.users'], self::$DI['app']['random.low']])
$userManipulator = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')
->setConstructorArgs([
self::$DI['app']['model.user-manager'],
self::$DI['app']['auth.password-encoder'],
self::$DI['app']['geonames.connector'],
self::$DI['app']['repo.users'],
self::$DI['app']['random.low'],
self::$DI['app']['dispatcher'],
])
->setMethods(['logQuery'])
->getMock();
self::$DI['app']['manipulator.user']->expects($this->once())->method('logQuery');
self::$DI['app']['manipulator.user'] = $userManipulator;
self::$DI['client']->request('POST', $route);
$userManipulator->expects($this->once())->method('logQuery');
$response = self::$DI['client']->getResponse();
$client = $this->getClient();
$client->request('POST', $route);
$response = $client->getResponse();
$this->assertEquals('application/json', $response->headers->get('Content-type'));
$data = json_decode($response->getContent(), true);
$this->assertInternalType('array', $data);
@@ -48,12 +58,13 @@ class QueryTest extends \PhraseanetAuthenticatedWebTestCase
$options->onCollections($app->getAclForUser($app->getAuthenticatedUser())->get_granted_base());
$serializedOptions = $options->serialize();
self::$DI['client']->request('POST', '/prod/query/answer-train/', [
$client = $this->getClient();
$client->request('POST', '/prod/query/answer-train/', [
'options_serial' => $serializedOptions,
'pos' => 0,
'query' => ''
]);
$response = self::$DI['client']->getResponse();
$response = $client->getResponse();
$this->assertTrue($response->isOk());
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('current', $datas);

View File

@@ -84,7 +84,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
->getMock();
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
$manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks'], self::$DI['app']['random.low']);
$manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks'], self::$DI['app']['random.low'], self::$DI['app']['dispatcher']);
$manipulator->setGeonameId($user, 4);
$this->assertEquals(4, $user->getGeonameId());
@@ -150,7 +150,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
$passwordInterface = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface')
->getMock();
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
$manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks'], self::$DI['app']['random.low']);
$manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks'], self::$DI['app']['random.low'], self::$DI['app']['dispatcher']);
$this->setExpectedException(
'Alchemy\Phrasea\Exception\InvalidArgumentException',
'Invalid geonameid -1.'