Skip to content

Commit

Permalink
Merge pull request #3 from romainneutron/nlegoff-replace_users-fix-un…
Browse files Browse the repository at this point in the history
…it-tests

Fix unit tests
  • Loading branch information
nlegoff committed Feb 20, 2014
2 parents ad34bfa + 2507372 commit 47305c9
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 48 deletions.
70 changes: 32 additions & 38 deletions lib/Alchemy/Phrasea/Controller/Root/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,47 +362,41 @@ public function updateAccount(PhraseaApplication $app, Request $request)
];

if (0 === count(array_diff($accountFields, array_keys($request->request->all())))) {
$app['authentication']->getUser()
->setGender($request->request->get("form_gender"))
->setFirstName($request->request->get("form_firstname"))
->setLastName($request->request->get("form_lastname"))
->setAddress($request->request->get("form_address"))
->setZipCode($request->request->get("form_zip"))
->setPhone($request->request->get("form_phone"))
->setFax($request->request->get("form_fax"))
->setJob($request->request->get("form_activity"))
->setCompany($request->request->get("form_company"))
->setActivity($request->request->get("form_function"))
->setMailNotificationsActivated((Boolean) $request->request->get("mail_notifications"));

$app['manipulator.user']->setGeonameId($app['authentication']->getUser(), $request->request->get("form_geonameid"));

$ftpCredential = $app['authentication']->getUser()->getFtpCredential();

if (null === $ftpCredential) {
$ftpCredential = new FtpCredential();
$ftpCredential->setUser($app['authentication']->getUser());
}

try {

$app['authentication']->getUser()
->setGender($request->request->get("form_gender"))
->setFirstName($request->request->get("form_firstname"))
->setLastName($request->request->get("form_lastname"))
->setAddress($request->request->get("form_address"))
->setZipCode($request->request->get("form_zip"))
->setPhone($request->request->get("form_phone"))
->setFax($request->request->get("form_fax"))
->setJob($request->request->get("form_activity"))
->setCompany($request->request->get("form_company"))
->setActivity($request->request->get("form_function"))
->setMailNotificationsActivated((Boolean) $request->request->get("mail_notifications"));

$app['manipulator.user']->setGeonameId($app['authentication']->getUser(), $request->request->get("form_geonameid"));

$ftpCredential = $app['authentication']->getUser()->getFtpCredential();

if (null === $ftpCredential) {
$ftpCredential = new FtpCredential();
}

$ftpCredential->setActive($request->request->get("form_activeFTP"));
$ftpCredential->setAddress($request->request->get("form_addressFTP"));
$ftpCredential->setLogin($request->request->get("form_loginFTP"));
$ftpCredential->setPassword($request->request->get("form_pwdFTP"));
$ftpCredential->setPassive($request->request->get("form_passifFTP"));
$ftpCredential->setReceptionFolder($request->request->get("form_destFTP"));
$ftpCredential->setRepositoryPrefixName($request->request->get("form_prefixFTPfolder"));
$ftpCredential->setActive($request->request->get("form_activeFTP"));
$ftpCredential->setAddress($request->request->get("form_addressFTP"));
$ftpCredential->setLogin($request->request->get("form_loginFTP"));
$ftpCredential->setPassword($request->request->get("form_pwdFTP"));
$ftpCredential->setPassive($request->request->get("form_passifFTP"));
$ftpCredential->setReceptionFolder($request->request->get("form_destFTP"));
$ftpCredential->setRepositoryPrefixName($request->request->get("form_prefixFTPfolder"));

$app['EM']->persist($ftpCredential);
$app['EM']->persist($app['authentication']->getUser());
$app['EM']->persist($ftpCredential);
$app['EM']->persist($app['authentication']->getUser());

$app['EM']->flush();
$app->addFlash('success', $app->trans('login::notification: Changements enregistres'));
} catch (\Exception $e) {
$app->addFlash('error', $app->trans('forms::erreurs lors de l\'enregistrement des modifications'));
$app['phraseanet.appbox']->get_connection()->rollBack();
}
$app['EM']->flush();
$app->addFlash('success', $app->trans('login::notification: Changements enregistres'));
}

$requestedNotifications = (array) $request->request->get('notifications', []);
Expand Down
2 changes: 1 addition & 1 deletion lib/Alchemy/Phrasea/Form/TaskForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'data_class' => 'Phraseanet:Task',
'data_class' => 'Alchemy\Phrasea\Model\Entities\Task',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Alchemy/Phrasea/Model/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function setGender($gender)
self::GENDER_MISS,
self::GENDER_MR,
self::GENDER_MRS
])) {
], true)) {
throw new InvalidArgumentException(sprintf("Invalid gender %s.", $gender));
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Alchemy/Phrasea/Model/Entities/ValidationSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public function setInitiator(User $user)
}

/**
* Get initiator_id
* Get validation initiator
*
* @return integer
* @return User
*/
public function getInitiator()
{
return $this->initiator_id;
return $this->initiator;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function findReceivedElementsByRecord(\record_adapter $record, User $user
LEFT JOIN b.validation s
LEFT JOIN s.participants p
WHERE b.user = :usr_id
AND b.pusher_id IS NOT NULL
AND b.pusher IS NOT NULL
AND e.record_id = :record_id
AND e.sbas_id = :sbas_id';

Expand Down
2 changes: 1 addition & 1 deletion lib/classes/API/V1/adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ public function list_basket(Basket $basket)
'created_on' => $basket->getCreated()->format(DATE_ATOM),
'description' => (string) $basket->getDescription(),
'name' => $basket->getName(),
'pusher_usr_id' => $basket->getPusher()->getId(),
'pusher_usr_id' => $basket->getPusher() ? $basket->getPusher()->getId() : null,
'updated_on' => $basket->getUpdated()->format(DATE_ATOM),
'unread' => !$basket->getIsRead(),
'validation_basket' => !!$basket->getValidation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Alchemy\Tests\Phrasea\Command\Developper\Utils;

use Alchemy\Phrasea\Command\Developer\Utils\GruntDriver;
use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider;
use Symfony\Component\Process\PhpExecutableFinder;

class GruntDriverTest extends \PhraseanetTestCase
{
public function testCreate()
{
$driver = GruntDriver::create();
$app = self::$DI['app'];
$app->register(new CLIDriversServiceProvider());
$driver = GruntDriver::create(['grunt.binaries' => $app['driver.binary-finder']('grunt', 'grunt_binary')]);
$this->assertInstanceOf('Alchemy\Phrasea\Command\Developer\Utils\GruntDriver', $driver);
$this->assertEquals('grunt', $driver->getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Alchemy\Tests\Phrasea\Command\Developper\Utils;

use Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver;
use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider;
use Symfony\Component\Process\PhpExecutableFinder;

class UglifyJsDriverTest extends \PhraseanetTestCase
{
public function testCreate()
{
$driver = UglifyJsDriver::create();
$app = self::$DI['app'];
$app->register(new CLIDriversServiceProvider());
$driver = UglifyJsDriver::create(['uglifyjs.binaries' => $app['driver.binary-finder']('uglifyjs', 'uglifyjs_binary')]);
$this->assertInstanceOf('Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver', $driver);
$this->assertEquals('uglifyjs', $driver->getName());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Alchemy/Tests/Phrasea/Model/Entities/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class UserTest extends \PhraseanetTestCase
{
/** @var User */
private $user;

public function setUp()
Expand Down Expand Up @@ -140,7 +141,7 @@ public function invalidGenderProvider()
return [
[false],
[''],
[1],
[4],
['madame']
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function testFindWithProviderAndIdReturnsOneResultWhenFound()
$repo = self::$DI['app']['EM']->getRepository('Phraseanet:UsrAuthProvider');

$auth = new UsrAuthProvider();
$auth->setUser(self::$DI['user']);
$auth->setProvider('provider-test');
$auth->setDistantId(12345);

Expand Down

0 comments on commit 47305c9

Please sign in to comment.