Files
Phraseanet/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php
Nicolas Le Goff a8da584666 Merge branch '3.8'
Conflicts:
	composer.json
	composer.lock
	config/configuration.sample.yml
	lib/Alchemy/Phrasea/Application.php
	lib/Alchemy/Phrasea/Application/Api.php
	lib/Alchemy/Phrasea/Controller/Admin/Collection.php
	lib/Alchemy/Phrasea/Controller/Admin/Users.php
	lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php
	lib/Alchemy/Phrasea/Controller/Prod/Export.php
	lib/Alchemy/Phrasea/Controller/Prod/Language.php
	lib/Alchemy/Phrasea/Controller/Prod/Push.php
	lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php
	lib/Alchemy/Phrasea/Controller/Report/Informations.php
	lib/Alchemy/Phrasea/Controller/Report/Root.php
	lib/Alchemy/Phrasea/Controller/Root/Developers.php
	lib/Alchemy/Phrasea/Controller/Root/Login.php
	lib/Alchemy/Phrasea/Controller/Root/Session.php
	lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php
	lib/Alchemy/Phrasea/Controller/Utils/ConnectionTest.php
	lib/Alchemy/Phrasea/Controller/Utils/PathFileTest.php
	lib/Alchemy/Phrasea/Core/Version.php
	lib/Alchemy/Phrasea/Form/Login/PhraseaAuthenticationForm.php
	lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php
	lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php
	lib/classes/API/OAuth2/Application.php
	lib/classes/API/V1/adapter.php
	lib/classes/Feed/Adapter.php
	lib/classes/Feed/Aggregate.php
	lib/classes/Feed/Collection.php
	lib/classes/Feed/Entry/Adapter.php
	lib/classes/ZipArchiveImproved.php
	lib/classes/caption/Field/Value.php
	lib/classes/caption/record.php
	lib/classes/eventsmanager/notify/feed.php
	lib/classes/media/subdef.php
	lib/classes/module/report/connexion.php
	lib/classes/module/report/download.php
	lib/classes/record/adapter.php
	lib/classes/registry.php
	lib/classes/set/export.php
	lib/classes/setup.php
	lib/classes/task/abstract.php
	lib/classes/task/period/emptyColl.php
	lib/classes/uuid.php
	lib/conf.d/_GV_template.inc
	lib/conf.d/bases_structure.xml
	lib/conf.d/configuration.yml
	lib/conf.d/minifyGroupsConfig.php
	locale/de_DE/LC_MESSAGES/phraseanet.mo
	locale/de_DE/LC_MESSAGES/phraseanet.po
	locale/en_GB/LC_MESSAGES/phraseanet.mo
	locale/en_GB/LC_MESSAGES/phraseanet.po
	locale/fr_FR/LC_MESSAGES/phraseanet.mo
	locale/fr_FR/LC_MESSAGES/phraseanet.po
	locale/nl_NL/LC_MESSAGES/phraseanet.mo
	locale/nl_NL/LC_MESSAGES/phraseanet.po
	locale/phraseanet.pot
	templates/web/account/account.html.twig
	templates/web/account/base.html.twig
	templates/web/admin/databox/databox.html.twig
	templates/web/admin/index.html.twig
	templates/web/admin/setup.html.twig
	templates/web/admin/tree.html.twig
	templates/web/client/index.html.twig
	templates/web/common/caption.html.twig
	templates/web/common/caption_templates/answer.html.twig
	templates/web/common/caption_templates/basket_element.html.twig
	templates/web/common/caption_templates/internal_publi.html.twig
	templates/web/common/caption_templates/lazaret.html.twig
	templates/web/common/caption_templates/overview.html.twig
	templates/web/common/caption_templates/preview.html.twig
	templates/web/common/index_bootstrap.html.twig
	templates/web/common/indexfloat.html.twig
	templates/web/common/thumbnail.html.twig
	templates/web/developers/application_form.html.twig
	templates/web/lightbox/IE6/feed.html.twig
	templates/web/lightbox/IE6/validate.html.twig
	templates/web/lightbox/feed.html.twig
	templates/web/lightbox/validate.html.twig
	templates/web/prod/actions/Download/prepare.html.twig
	templates/web/prod/actions/publish/publish.html.twig
	templates/web/prod/index.html.twig
	templates/web/prod/preview/caption.html.twig
	templates/web/prod/results/answerlist.html.twig
	templates/web/thesaurus/accept.html.twig
	templates/web/thesaurus/export-text-dialog.html.twig
	templates/web/thesaurus/export-text.html.twig
	templates/web/thesaurus/export-topics-dialog.html.twig
	templates/web/thesaurus/export-topics.html.twig
	templates/web/thesaurus/index.html.twig
	templates/web/thesaurus/link-field-step1.html.twig
	templates/web/thesaurus/link-field-step2.html.twig
	templates/web/thesaurus/link-field-step3.html.twig
	templates/web/thesaurus/new-term.html.twig
	templates/web/thesaurus/properties.html.twig
	templates/web/thesaurus/search.html.twig
	templates/web/thesaurus/thesaurus.html.twig
	tests/Alchemy/Tests/Phrasea/Application/ApiJsonTest.php
	tests/Alchemy/Tests/Phrasea/Application/ApiYamlTest.php
	tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php
	tests/Alchemy/Tests/Phrasea/Application/OAuth2Test.php
	tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php
	tests/Alchemy/Tests/Phrasea/Authentication/PersistentCookie/ManagerTest.php
	tests/Alchemy/Tests/Phrasea/Cache/RedisCacheTest.php
	tests/Alchemy/Tests/Phrasea/Command/Compile/ConfigurationTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Admin/SubdefsTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJSONPTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/BasketTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/BridgeTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/EditTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/MoveCollectionTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/PrinterTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/TooltipTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/UsrListsTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Prod/WorkZoneTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Utils/PathFileTestTest.php
	tests/Alchemy/Tests/Phrasea/Core/Provider/FTPServiceProviderTest.php
	tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php
	tests/Alchemy/Tests/Phrasea/Core/Provider/PhraseanetServiceProviderTest.php
	tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php
	tests/Alchemy/Tests/Phrasea/Core/Provider/TaskManagerServiceProviderTest.php
	tests/Alchemy/Tests/Phrasea/Http/XSendFile/NginxModeTest.php
	tests/Alchemy/Tests/Phrasea/Metadata/Tag/TfEditDateTest.php
	tests/Alchemy/Tests/Phrasea/Metadata/Tag/TfMimeTypeTest.php
	tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php
	tests/classes/Feed/Feed_AggregateTest.php
	tests/classes/PhraseanetPHPUnitAbstract.php
	tests/db-ref.sqlite
2014-06-17 15:30:41 +02:00

471 lines
20 KiB
PHP

<?php
namespace Alchemy\Tests\Phrasea\Controller\Admin;
class UsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $usersParameters;
public function setUp()
{
parent::setUp();
$this->usersParameters = ["users" => implode(';', [self::$DI['user']->getId(), self::$DI['user_alt1']->getId()])];
}
public function testRouteRightsPost()
{
self::$DI['client']->request('POST', '/admin/users/rights/', $this->usersParameters);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
}
public function testRouteRightsGet()
{
self::$DI['client']->request('GET', '/admin/users/rights/', $this->usersParameters);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
}
public function testRouteDelete()
{
$user = self::$DI['app']['manipulator.user']->createUser('login', "test");
self::$DI['client']->request('POST', '/admin/users/delete/', ['users' => $user->getId()]);
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
$this->assertTrue($user->isDeleted());
}
public function testRouteDeleteCurrentUserDoesNothing()
{
self::$DI['client']->request('POST', '/admin/users/delete/', ['users' => self::$DI['user']->getId()]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isRedirect());
$this->assertNotNull(self::$DI['app']['repo.users']->findByLogin(self::$DI['user']->getLogin()));
}
public function testRouteRightsApply()
{
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate', 2);
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), 'test', 'titi@titi.fr');
self::$DI['client']->request('POST', '/admin/users/rights/apply/', [
'users' => $user->getId(),
'values' => 'canreport_' . self::$DI['collection']->get_base_id() . '=1&manage_' . self::$DI['collection']->get_base_id() . '=1&canpush_' . self::$DI['collection']->get_base_id() . '=1',
'user_infos' => ['email' => 'toto@toto.fr' ]
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$datas = json_decode($response->getContent());
$this->assertFalse($datas->error);
$this->assertTrue(self::$DI['app']['acl']->get($user)->has_right_on_base(self::$DI['collection']->get_base_id(), "manage"));
$this->assertTrue(self::$DI['app']['acl']->get($user)->has_right_on_base(self::$DI['collection']->get_base_id(), "canpush"));
$this->assertTrue(self::$DI['app']['acl']->get($user)->has_right_on_base(self::$DI['collection']->get_base_id(), "canreport"));
self::$DI['app']['EM']->refresh($user);
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteRightsApplyException()
{
$this->markTestIncomplete();
self::$DI['client']->request('POST', '/admin/users/rights/apply/', [
'users' => 'unknow_id',
'values' => 'canreport_' . self::$DI['collection']->get_base_id() . '=1&manage_' . self::$DI['collection']->get_base_id() . '=1&canpush_' . self::$DI['collection']->get_base_id() . '=1',
'user_infos' => "user_infos[email]=toto@toto.fr"
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$data = json_decode($response->getContent());
$this->assertTrue(is_object($data));
$this->assertTrue($data->error);
}
public function testRouteQuota()
{
$keys = array_keys(self::$DI['app']['acl']->get(self::$DI['user'])->get_granted_base());
$base_id = array_pop($keys);
$params = ['base_id' => $base_id, 'users' => self::$DI['user']->getId()];
self::$DI['client']->request('POST', '/admin/users/rights/quotas/', $params);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteQuotaAdd()
{
$params = [
'base_id' => self::$DI['collection']->get_base_id()
, 'quota' => '1', 'droits' => 38, 'restes' => 15];
self::$DI['client']->request('POST', '/admin/users/rights/quotas/apply/', $params);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteQuotaRemove()
{
$keys = array_keys(self::$DI['app']['acl']->get(self::$DI['user'])->get_granted_base());
$base_id = array_pop($keys);
$params = ['base_id' => $base_id, 'users' => self::$DI['user']->getId()];
self::$DI['client']->request('POST', '/admin/users/rights/quotas/apply/', $params);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightTime()
{
$keys = array_keys(self::$DI['app']['acl']->get(self::$DI['user'])->get_granted_base());
$base_id = array_pop($keys);
$params = ['base_id' => $base_id, 'users' => self::$DI['user']->getId()];
self::$DI['client']->request('POST', '/admin/users/rights/time/', $params);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightTimeSbas()
{
$sbas_id = self::$DI['record_1']->get_databox()->get_sbas_id();
self::$DI['client']->request('POST', '/admin/users/rights/time/sbas/', ['sbas_id' => $sbas_id, 'users' => self::$DI['user']->getId()]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightTimeApply()
{
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
$base_id = self::$DI['collection']->get_base_id();
$date = new \Datetime();
$date->modify("-10 days");
$dmin = $date->format(DATE_ATOM);
$date->modify("+30 days");
$dmax = $date->format(DATE_ATOM);
self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['base_id' => $base_id, 'dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteRightTimeApplySbas()
{
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
$sbas_id = self::$DI['record_1']->get_databox()->get_sbas_id();
$date = new \Datetime();
$date->modify("-10 days");
$dmin = $date->format(DATE_ATOM);
$date->modify("+30 days");
$dmax = $date->format(DATE_ATOM);
self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['sbas_id' => $sbas_id, 'dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteRightTimeApplyWithtoutBasOrSbas()
{
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
$date = new \Datetime();
$date->modify("-10 days");
$dmin = $date->format(DATE_ATOM);
$date->modify("+30 days");
$dmax = $date->format(DATE_ATOM);
self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]);
$response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode());
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteRightMask()
{
$keys = array_keys(self::$DI['app']['acl']->get(self::$DI['user'])->get_granted_base());
$base_id = array_pop($keys);
$params = ['base_id' => $base_id, 'users' => self::$DI['user']->getId()];
self::$DI['client']->request('POST', '/admin/users/rights/masks/', $params);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightMaskApply()
{
$this->markTestIncomplete();
$base_id = self::$DI['collection']->get_base_id();
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
self::$DI['client']->request('POST', '/admin/users/rights/masks/apply/', [
'base_id' => $base_id, 'vand_and', 'vand_or', 'vxor_or', 'vxor_and'
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteSearch()
{
self::$DI['client']->request('POST', '/admin/users/search/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
}
public function testRoutesearchExport()
{
self::$DI['client']->request('POST', '/admin/users/search/export/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("text/csv; charset=UTF-8", $response->headers->get("Content-type"));
$date = new \DateTime();
$this->assertEquals('attachment; filename="user_export_'.$date->format('Ymd').'.csv"', $response->headers->get("content-disposition"));
}
public function testRouteThSearch()
{
self::$DI['client']->request('GET', '/admin/users/typeahead/search/', ['term' => 'admin']);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
}
public function testRouteApplyTp()
{
$this->authenticate(self::$DI['app']);
$template = self::$DI['app']['manipulator.user']->createUser(uniqid('template_'), "test");
$template->setTemplateOwner(self::$DI['user']);
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
self::$DI['client']->request('POST', '/admin/users/apply_template/', [
'template' => $template->getId(),
'users' => $user->getId()]
);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isRedirect());
self::$DI['app']['manipulator.user']->delete($template);
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteCreateException()
{
self::$DI['client']->request('POST', '/admin/users/create/', ['value' => '', 'template' => '1']);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
}
public function testRouteCreateExceptionUser()
{
self::$DI['client']->request('POST', '/admin/users/create/', ['value' => '', 'template' => '0']);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
}
public function testRouteCreateUserAndValidateEmail()
{
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation');
self::$DI['client']->request('POST', '/admin/users/create/', [
'value' => uniqid('user_') . "@email.com",
'template' => '0',
'validate_mail' => true,
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertFalse($datas->error);
$this->assertNotNull($user = (self::$DI['app']['repo.users']->find((int) $datas->data)));
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteCreateUserAndSendCredentials()
{
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup');
$username = uniqid('user_');
self::$DI['client']->request('POST', '/admin/users/create/', [
'value' => $username . "@email.com",
'template' => '0',
'send_credentials' => true,
]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertFalse($datas->error);
$this->assertNotNull($user = (self::$DI['app']['repo.users']->find((int) $datas->data)));
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRouteExportCsv()
{
self::$DI['client']->request('POST', '/admin/users/export/csv/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertRegexp("#text/csv#", $response->headers->get("content-type"));
$this->assertRegexp("#charset=UTF-8#", $response->headers->get("content-type"));
$date = new \DateTime();
$this->assertEquals('attachment; filename="user_export_'.$date->format('Ymd').'.csv"', $response->headers->get("content-disposition"));
}
public function testResetRights()
{
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
self::$DI['app']['acl']->get($user)->give_access_to_sbas(array_keys(self::$DI['app']['phraseanet.appbox']->get_databoxes()));
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
$rights = [
'bas_manage' => '1'
, 'bas_modify_struct' => '1'
, 'bas_modif_th' => '1'
, 'bas_chupub' => '1'
];
self::$DI['app']['acl']->get($user)->update_rights_to_sbas($databox->get_sbas_id(), $rights);
foreach ($databox->get_collections() as $collection) {
$base_id = $collection->get_base_id();
self::$DI['app']['acl']->get($user)->give_access_to_base([$base_id]);
$rights = [
'canputinalbum' => '1'
, 'candwnldhd' => '1'
, 'candwnldsubdef' => '1'
, 'nowatermark' => '1'
];
self::$DI['app']['acl']->get($user)->update_rights_to_base($collection->get_base_id(), $rights);
break;
}
}
self::$DI['client']->request('POST', '/admin/users/rights/reset/', ['users' => $user->getId()]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertFalse($datas->error);
$this->assertFalse(self::$DI['app']['acl']->get($user)->has_access_to_base($base_id));
self::$DI['app']['manipulator.user']->delete($user);
}
public function testRenderRegistrations()
{
self::$DI['client']->request('GET', '/admin/users/registrations/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
}
public function testPostRegistrations()
{
$id = self::$DI['user_alt1']->getId();
$baseId = self::$DI['collection']->get_base_id();
$param = sprintf('%s_%s', $id, $baseId);
$stmt = $this->getMock('PDOStatement');
$stmt->expects($this->any())
->method('fetchAll')
->will($this->returnValue([
'usr_id' => $id,
'base_id' => $baseId,
'en_cours' => 1,
'refuser' => 0,
]));
$pdo = $this->getMock('PDOMock');
$pdo->expects($this->any())
->method('prepare')
->will($this->returnValue($stmt));
$appbox = $this->getMockBuilder('\appbox')
->setMethods(['get_connection'])
->disableOriginalConstructor()
->getMock();
$appbox->expects($this->any())
->method('get_connection')
->will($this->returnValue($pdo));
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate');
self::$DI['client']->request('POST', '/admin/users/registrations/', [
'template' => [],
'accept' => [$param],
'accept_hd' => [$param],
'watermark' => [$param],
]);
self::$DI['app']['phraseanet.appbox'] = $appbox;
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
}
public function testRenderImportFile()
{
self::$DI['client']->request('GET', '/admin/users/import/file/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
}
public function testImportUserCSVFile()
{
// create a template
if (false === \User_Adapter::get_usr_id_from_login(self::$DI['app'], 'csv_template')) {
$created_user = \User_Adapter::create(self::$DI['app'], 'csv_template', \random::generatePassword(16), null, false, false);
$created_user->set_template(self::$DI['app']['authentication']->getUser());
$created_user->ACL()->update_rights_to_base(self::$DI['collection']->get_base_id(), array('actif'=> 1));
}
$data =
<<<CSV
gender;last name;first name;login;password;mail;adress;city;zipcode;phone;fax;function;company;activity;country;FTP_active;FTP_adress;loginFTP;pwdFTP;Destination_folder;Passive_mode;Retry;Prefix_creation_folder;by_default__send
;Martin;Léo;leo;XXX;mart.leo@alchemy.fr;;;;;;;Alchemy;;;;;;;;;;;
;Dupont;Iris;iris;XXX;dup.iris@alchemy.fr;;;;;;;Alchemy;;;;;;;;;;;
;Durand;Nathalie;nath;XXX;dur.nath@alchemy.fr;;;;;;;Alchemy;;;;;;;;;;;
;Legrand;Robert;rob;XXX;leg.rob@alchemy.fr;;;;;;;Alchemy;;;;;;;;;;;
CSV;
$filepath = sys_get_temp_dir().'/user.csv';
file_put_contents($filepath,$data);
$files = array(
'files' => new \Symfony\Component\HttpFoundation\File\UploadedFile($filepath, 'user.csv')
);
$crawler = self::$DI['client']->request('POST', '/admin/users/import/file/', array(), $files);
$this->assertGreaterThan(0, $crawler->filter('html:contains("4 Users")')->count());
}
public function testGetExampleCSVFile()
{
self::$DI['client']->request('GET', '/admin/users/import/example/csv/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
}
public function testGetExampleRtfFile()
{
self::$DI['client']->request('GET', '/admin/users/import/example/rtf/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
}
}