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() public function testSearchRoute()
{ {
self::$DI['app']['manipulator.user'] = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator') 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']) ->setMethods(['logQuery'])
->getMock(); ->getMock();

View File

@@ -21,16 +21,26 @@ class QueryTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$route = '/prod/query/'; $route = '/prod/query/';
self::$DI['app']['manipulator.user'] = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator') $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']]) ->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']) ->setMethods(['logQuery'])
->getMock(); ->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')); $this->assertEquals('application/json', $response->headers->get('Content-type'));
$data = json_decode($response->getContent(), true); $data = json_decode($response->getContent(), true);
$this->assertInternalType('array', $data); $this->assertInternalType('array', $data);
@@ -48,12 +58,13 @@ class QueryTest extends \PhraseanetAuthenticatedWebTestCase
$options->onCollections($app->getAclForUser($app->getAuthenticatedUser())->get_granted_base()); $options->onCollections($app->getAclForUser($app->getAuthenticatedUser())->get_granted_base());
$serializedOptions = $options->serialize(); $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, 'options_serial' => $serializedOptions,
'pos' => 0, 'pos' => 0,
'query' => '' 'query' => ''
]); ]);
$response = self::$DI['client']->getResponse(); $response = $client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('current', $datas); $this->assertArrayHasKey('current', $datas);

View File

@@ -84,7 +84,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
->getMock(); ->getMock();
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); $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); $manipulator->setGeonameId($user, 4);
$this->assertEquals(4, $user->getGeonameId()); $this->assertEquals(4, $user->getGeonameId());
@@ -150,7 +150,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
$passwordInterface = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface') $passwordInterface = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface')
->getMock(); ->getMock();
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); $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( $this->setExpectedException(
'Alchemy\Phrasea\Exception\InvalidArgumentException', 'Alchemy\Phrasea\Exception\InvalidArgumentException',
'Invalid geonameid -1.' 'Invalid geonameid -1.'