feat: init

This commit is contained in:
montaghanmy
2023-03-23 11:03:16 +01:00
commit 10fe6f78d1
11518 changed files with 509786 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace Tests\UsersBundle;
require_once __DIR__ . "/../WebTestCaseExtended.php";
use Tests\WebTestCaseExtended;
class Error200Test extends WebTestCaseExtended
{
public function testErrorRemoveSecondaryMail()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$result = $this->login($user->getUsernameCanonical());
$result = $this->doPost("/ajax/users/account/removemail", Array(
"mail" => "14005200-48b1-11e9-a0b4-0242ac120005"
));
$this->assertEquals(Array("badmail"), $result["errors"]);
}
public function testCheckNumberForAddNewMail()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001", "usertest001@twake_phpunit.fr");
$this->login($user->getUsernameCanonical());
$result = $this->doPost("/ajax/users/account/addmail", Array(
"mail" => "usertest0021@twake_phpunit.fr"
));
$token = $result["data"]["token"];
$verif = $this->get("app.twake_doctrine")->getRepository("Twake\Users:VerificationNumberMail")->findOneBy(Array("token" => $token));
$code = $verif->getCleanCode();
$result = $this->doPost("/ajax/users/account/addmailverify", Array(
"token" => $token,
"code" => $code
));
$this->assertEquals(Array(), $result["errors"]);
}
}
+238
View File
@@ -0,0 +1,238 @@
<?php
namespace Tests\AccessBundle;
require_once __DIR__ . "/../WebTestCaseExtended.php";
use Tests\WebTestCaseExtended;
use Twake\Channels\Entity\Channel;
use Twake\Channels\Entity\ChannelMember;
use Twake\Users\Entity\User;
use Twake\Workspaces\Entity\WorkspaceUser;
use Twake\Workspaces\Entity\Workspace;
use Twake\Workspaces\Entity\Group;
use Twake\Workspaces\Entity\WorkspaceLevel;
class ExterneUserTest extends WebTestCaseExtended
{
public function testWexterne()
{
list($g1, $w1, $c1, $u1) = $this->getStuff();
$u2 = $this->newUserByName("usertest002");
$this->login($u1->getUsernameCanonical());
$result = $this->doPost("/ajax/workspace/members/addlist", Array("list" => $u2->getUsernameCanonical() . "|1", "workspaceId" => $w1->getId()));
$this->assertEquals(Array($u2->getUsernameCanonical()), $result["data"]["added"]["user"], "User2 not invited");
// on se connecte à u2 pour voir ce qu'il en est
$this->assertEquals(true, $this->verifyIfUserIsInChannel($u2, $w1, $c1, true), "u2 is not invited as wexterne");
}
public function testChainvite()
{
list($g1, $w1, $c1, $u1) = $this->getStuff();
$u3 = $this->newUserByName("usertest003");
$this->login($u1->getUsernameCanonical());
$result = $this->updateChainviteFromFront($w1, $c1, $u1, [$u3->getId()], []);
$this->assertEquals(true, $this->verifyIfUserIsInChannel($u3, $w1, $c1, true), "u3 is not invited as chanvité");
$this->updateChainviteFromFront($w1, $c1, $u1, [], [$u3->getId()]);
$this->assertEquals(false, $this->verifyIfUserIsInChannel($u3, $w1, $c1, true), "u3 is still invited as chanvité");
}
public function testChainviteMail()
{
list($g1, $w1, $c1, $u1) = $this->getStuff();
$mail1 = "mail1@benoit.best";
$mailEntity = $this->getDoctrine()->getRepository("Twake\Users:Mail")->findOneBy(Array("mail" => $mail1));
if ($mailEntity) {
if ($mailEntity->getUserId()) {
$groupUsers = $this->getDoctrine()->getRepository("Twake\Workspaces:GroupUser")->findBy(Array("user" => $mailEntity->getUserId()));
foreach ($groupUsers as $groupUser) {
$this->getDoctrine()->remove($groupUser);
}
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->find($mailEntity->getUserId());
$this->getDoctrine()->remove($user);
}
$this->getDoctrine()->remove($mailEntity);
}
$this->getDoctrine()->flush();
$this->updateChainviteFromFront($w1, $c1, $u1, [$mail1], []);
$u4 = $this->newUserByName("usertest004", $mail1);
$this->assertEquals(true, $this->verifyIfUserIsInChannel($u4, $w1, $c1, true), "u4 is not invited as chanvité");
// on vérifi que $mail1 n'est plus dans la liste
$this->assertEquals(false, $this->verifyIfUserIsInChannel($u4, $w1, $c1, true, $mail1), "mail1 is still invited as chanvité");
}
public function testRemoveAutoAddFromChannel()
{
list($g1, $w1, $c1, $u1) = $this->getStuff();
$u2 = $this->newUserByName("usertest002");
$this->login($u1->getUsernameCanonical());
$result = $this->doPost("/ajax/workspace/members/addlist", Array("list" => $u2->getUsernameCanonical() . "|1", "workspaceId" => $w1->getId()));
$this->updateChainviteFromFront($w1, $c1, $u1, [], [$u2->getId()]);
$this->assertEquals(true, $this->verifyIfUserIsInChannel($u2, $w1, $c1, true), "User can be remove from channel as wexterne");
}
public function testRemoveAutoAddFromPrivateChannel()
{
list($g1, $w1, $c1, $u1) = $this->getStuff();
$c1->setPrivate(true);
$this->getDoctrine()->persist($c1);
$this->getDoctrine()->flush();
$u2 = $this->newUserByName("usertest002");
$this->login($u1->getUsernameCanonical());
$result = $this->doPost("/ajax/workspace/members/addlist", Array("list" => $u2->getUsernameCanonical() . "|1", "workspaceId" => $w1->getId()));
$this->assertEquals(false, $this->verifyIfUserIsInChannel($u2, $w1, $c1, true), "Wexterne is auto add in private channel");
$this->updateChainviteFromFront($w1, $c1, $u1, [$u2->getId()], []);
$this->assertEquals(true, $this->verifyIfUserIsInChannel($u2, $w1, $c1, true), "Wexterne can't be add in private channel");
$this->updateChainviteFromFront($w1, $c1, $u1, [], [$u2->getId()]);
$this->assertEquals(false, $this->verifyIfUserIsInChannel($u2, $w1, $c1, true), "Wexterne can't be remove from private channel");
}
public function testRemoveUserWexterne()
{
list($g1, $w1, $c1, $u1) = $this->getStuff();
$this->login($u1->getUsernameCanonical());
$u2 = $this->newUserByName("usertest002");
$result = $this->doPost("/ajax/workspace/members/addlist", Array("list" => $u2->getUsernameCanonical() . "|1", "workspaceId" => $w1->getId()));
$this->assertEquals(true, $this->verifyIfUserIsInChannel($u2, $w1, $c1, true), "Wexterne was not added in private channel");
$this->login($u1->getUsernameCanonical());
$result = $this->doPost("/ajax/workspace/members/remove", Array("ids" => Array($u2->getId()), "workspaceId" => $w1->getId()));
$this->assertEquals(Array("removed" => 1), $result["data"]);
$linkChannel = $this->getDoctrine()->getRepository("Twake\Channels:ChannelMember")->findOneBy(Array("direct" => false, "user_id" => $u2->getId() . "", "channel_id" => $c1->getId()));
$this->assertNull($linkChannel, "Wexterne is still in channel (entity) on remove from workspace");
$this->assertEquals(false, $this->verifyIfUserIsInChannel($u1, $w1, $c1, true, $u2->getUsernameCanonical()), "Wexterne is still in channel (front) on remove from workspace");
$this->logout();
}
private function getStuff()
{
$u1 = $this->newUserByName("usertest001");
$g1 = $this->newGroup($u1->getId(), "grptest1");
$w1 = $this->newWorkspace("workspace1", $g1);
$w1->setMemberCount(1);
$this->getDoctrine()->persist($w1);
$rightAdmin = new WorkspaceLevel();
$rightAdmin->setIsAdmin(true);
$rightAdmin->setWorkspace($w1);
$this->getDoctrine()->persist($rightAdmin);
$linkWorkspaceUser = new WorkspaceUser($w1, $u1, $rightAdmin->getId());
$this->getDoctrine()->persist($linkWorkspaceUser);
$c1 = $this->newChannel($g1, $w1, $u1);
return Array($g1, $w1, $c1, $u1);
}
private function getChannelsFromFront($workspace, $channel, $user)
{
$this->login($user->getUsernameCanonical());
$result = $this->doPost("/ajax/core/collections/init", Array(
"collection_id" => "channels/workspace/" . $workspace->getId(),
"options" => Array(
"type" => "channels/workspace",
"get_options" => Array(
"workspace_id" => $workspace->getId(),
),
"_grouped" => true,
)
));
if (!isset($result["data"])) {
return [];
}
$channels = $result["data"]["get"];
return $channels;
}
private function updateChainviteFromFront($workspace, $channel, $user, $toAdd = [], $toRemove = [])
{
$channels = $this->getChannelsFromFront($workspace, $channel, $user);
$frontChan = $this->getChannelById($channels, $channel->getId());
if ($frontChan) {
$members = $frontChan["ext_members"];
foreach ($toAdd as $adding) {
if (!in_array($adding, $members)) {
$members[] = $adding;
}
}
foreach ($toRemove as $removing) {
if (($index = array_search($removing . "", $members)) !== false) {
array_splice($members, $index, 1);
}
}
$frontChan["ext_members"] = $members;
$result = $this->doPost("/ajax/channels/save", Array(
"collection_id" => "",
"object" => $frontChan,
));
return true;
}
return false;
}
private function verifyIfUserIsInChannel($user, $workspace, $channel, $hasToBeExterne, $mailOrUsername = null)
{
$this->login($user->getUsernameCanonical());
$result = $this->doPost("/ajax/core/collections/init", Array(
"collection_id" => "channels/workspace/" . $workspace->getId(),
"options" => Array(
"type" => "channels/workspace",
"get_options" => Array(
"workspace_id" => $workspace->getId(),
),
"_grouped" => true,
)
));
if (isset($result["data"]["get"])) {
$channels = $result["data"]["get"];
} else {
$channels = [];
}
$isOk = $this->isInChannel($channels, $user, $channel, $hasToBeExterne, $mailOrUsername);
$this->logout();
return $isOk;
}
private function isInChannel($channelInWorkspace, $user, $channel, $hasToBeExterne, $mailOrUsername = null)
{
$chan = $this->getChannelById($channelInWorkspace, $channel->getId());
if ($chan) {
if ($hasToBeExterne) {
$externeMembers = $chan["ext_members"];
foreach ($externeMembers as $ext) {
if ($mailOrUsername) {
if ($ext == $mailOrUsername) {
return true;
}
} elseif ($ext == $user->getId()) {
return true;
}
}
} else {
$members = $chan["members"];
foreach ($members as $memb) {
if ($memb == $user->getId()) {
return true;
}
}
}
}
return false;
}
private function getChannelById($channelList, $channelId)
{
if (is_array($channelList)) {
foreach ($channelList as $chan) {
if ($chan["id"] == $channelId) {
return $chan;
}
}
}
return false;
}
}
+420
View File
@@ -0,0 +1,420 @@
<?php
namespace Tests\UsersBundle;
require_once __DIR__ . "/../WebTestCaseExtended.php";
use Tests\WebTestCaseExtended;
use Twake\Users\Entity\Mail;
class UserAccountTest extends WebTestCaseExtended
//Tests when the user is already connected
{
public function testAlive()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$alive = $this->get("app.user")->Alive($user->getId());
$lastActivityUser = $user->getLastActivity();
$currentDate = date("U");
$difference = $currentDate - $lastActivityUser;
$this->assertLessThanOrEqual(10, $difference);
}
public function testChangePassword()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->changePassword($user->getId(), "usertest001", "newPassword");
$this->assertEquals(true, $result);
$result = $this->get("app.user")->checkPassword($user->getId(), "newPassword");
$this->assertEquals(true, $result);
$result = $this->get("app.user")->changePassword($user->getId(), "usertest001", "3");
$this->assertEquals(false, $result);
$result = $this->get("app.user")->checkPassword($user->getId(), "newPassword");
$this->assertEquals(true, $result);
$result = $this->get("app.user")->changePassword($user->getId(), "usertest001", null);
$this->assertEquals(false, $result);
$result = $this->get("app.user")->checkPassword($user->getId(), "newPassword");
$this->assertEquals(true, $result);
$result = $this->get("app.user")->changePassword("14005200-48b1-11e9-a0b4-0242ac120005", "usertest001", "newpasswordbis");
$this->assertEquals(false, $result);
$result = $this->get("app.user")->checkPassword($user->getId(), "newPassword");
$this->assertEquals(true, $result);
}
public function testChangePseudo()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->changePseudo($user->getId(), "newpseudo");
$this->assertEquals(true, $result);
$this->assertEquals("newpseudo", $user->getUsername());
$this->removeUserByName("newpseudo");
$user2 = $this->newUserByName("usertest002");
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->changePseudo($user->getId(), "usertest002");
$this->assertEquals(false, $result);
$this->removeUserByName("usertest002");
$result = $this->get("app.user")->changePseudo($user->getId(), null);
$this->assertEquals(false, $result);
$result = $this->get("app.user")->changePseudo("14005200-48b1-11e9-a0b4-0242ac120005", "newPseudoBis");
$this->assertEquals(false, $result);
}
public function testChangeMainMail()
{
$user = $this->newUserByName("usertest001");
$mail = new Mail();
$mail->setMail("emailforphpunittest@twake_phpunit.fr");
$mail->setUserId($user->getId());
$this->getDoctrine()->persist($mail);
$this->getDoctrine()->flush();
$id = $mail->getId() . "";
$result = $this->get("app.user")->changeMainMail($user->getId(), $id);
$this->assertEquals(true, $result);
$this->assertEquals("emailforphpunittest@twake_phpunit.fr", $user->getEmail());
$this->getDoctrine()->remove($mail);
$this->removeUserByName("usertest001");
$this->getDoctrine()->flush();
$result = $this->get("app.user")->changeMainMail("14005200-48b1-11e9-a0b4-0242ac120005", $id);
$this->assertEquals(false, $result);
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$result = $this->get("app.user")->changeMainMail($user->getId(), "14005200-48b1-11e9-a0b4-0242ac120005");
$this->assertEquals(false, $result);
}
public function testSetNotificationPreferences()
{
$user = $this->newUserByName("usertest001");
$notif = Array(
"key1" => "notif1",
"key2" => "notif2"
);
$result = $this->get("app.user")->setNotificationPreferences($user->getId(), $notif);
$i = 1;
foreach ($notif as $key => $value) {
$this->assertArrayHasKey($key, $user->getNotificationPreference());
$this->assertEquals("notif" . $i, $user->getNotificationPreference()[$key]);
$i++;
}
}
public function testGetNotificationPreferences()
{
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->getNotificationPreferences($user->getId());
$bool = is_array($result);
$this->assertEquals(true, $bool);
$result = $this->get("app.user")->getNotificationPreferences("14005200-48b1-11e9-a0b4-0242ac120005");
$this->assertEquals(false, $result);
}
public function testSetWorkspacesPreferences()
{
$user = $this->newUserByName("usertest001");
$preferences = Array(
"key1" => "pref1",
"key2" => "pref2"
);
$result = $this->get("app.user")->setWorkspacesPreferences($user->getId(), $preferences);
$i = 1;
foreach ($preferences as $key => $value) {
$this->assertArrayHasKey($key, $user->getWorkspacesPreference());
$this->assertEquals("pref" . $i, $user->getWorkspacesPreference()[$key]);
$i++;
}
}
public function testUpdateTutorialStatus()
{
$user = $this->newUserByName("usertest001");
$status = Array(
"key1" => "status1",
"key2" => "status2"
);
$result = $this->get("app.user")->setTutorialStatus($user->getId(), $status);
$i = 1;
foreach ($status as $key => $value) {
$this->assertArrayHasKey($key, $user->getTutorialStatus());
$this->assertEquals("status" . $i, $user->getTutorialStatus()[$key]);
$i++;
}
}
public function testUpdateLanguage()
{
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->updateLanguage($user->getId(), "langage");
$this->assertEquals("langage", $user->getLanguage());
}
public function testSetIsNew()
{
$user = $this->newUserByName("usertest001");
$this->assertEquals(true, $user->getisNew());
$result = $this->get("app.user")->setIsNew(false, $user->getId());
$this->assertEquals(false, $user->getisNew());
}
/*public function testUpdateNotificationPreferenceByWorkspace()
{
$user = $this->newUserByName("usertest001");
$result = $this->login($user->getUsernameCanonical());
$result = $this->doPost("/ajax/users/account/update_notifications", Array(
"workspaceId" => "14005200-48b1-11e9-a0b4-0242ac120005",
"appNotification" => Array()
));
$this->assertEquals("success", $result["data"]);
$this->assertArrayHasKey("14005200-48b1-11e9-a0b4-0242ac120005", $user->getNotificationPreference()["workspace"]);
$this->assertEquals(Array(), $user->getNotificationPreference()["workspace"]["14005200-48b1-11e9-a0b4-0242ac120005"]);
}*/
public function testRemoveUserByUsername()
{
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->removeUserByUsername($user->getUsername());
$result = $this->doPost("/ajax/users/current/get", Array());
$this->assertEquals("disconnected", $result["errors"]["0"]);
$this->assertEquals(false, $this->get("app.user")->removeUserByUsername($user->getUsername()));
}
public function testThreeNewPassword()
{
$user = $this->newUserByName("usertest001");
$result = $this->doPost("/ajax/users/recover/mail", Array(
"email" => "usertest001@twake_phpunit.fr"
));
$token = $result["data"]["token"];
$boolean = false;
if (is_string($token) && strlen($result["data"]["token"]) > 5) {
$boolean = true;
}
$this->assertEquals(true, $boolean);
//---------------------------------------------------------------------------
$result = $this->doPost("/ajax/users/recover/mail", Array(
"email" => "emai1fortest@twake_phpunit.fr"
));
$this->assertEquals("nosuchmail", $result["errors"][0]);
$verif = $this->getDoctrine()->getRepository("Twake\Users:VerificationNumberMail")->findOneBy(Array("token" => $token));
$code = $verif->getcode();
$this->getDoctrine()->persist($verif);
$this->getDoctrine()->flush();
$result = $this->doPost("/ajax/users/recover/verify", Array(
"code" => $code,
"token" => $token
));
$res = $result["data"]["status"];
$this->assertEquals("success", $res);
$result = $this->doPost("/ajax/users/recover/verify", Array(
"code" => $code,
"token" => "tokenfortest"
));
$res = $result["errors"][0];
$this->assertEquals("badcodeortoken", $res);
//-------------------------------------------------------------------------------
$result = $this->doPost("/ajax/users/recover/password", Array(
"code" => $code,
"token" => $token,
"password" => "usertest001"
));
$res = $result["data"]["status"];
$this->assertEquals("success", $res);
$result = $this->doPost("/ajax/users/recover/password", Array(
"code" => $code,
"token" => "tokenfortest",
"password" => "usertest001"
));
$res = $result["errors"][0];
$this->assertEquals("badcodeortoken", $res);
}
public function testSubscribeMail()
{
$user = $this->newUserByName("usertest001");
$user->setMailVerified(false);
$user->setisNew(true);
$this->getDoctrine()->persist($user);
$mail = $this->getDoctrine()->getRepository("Twake\Users:Mail")->findOneBy(Array("mail" => "usertest001@twake_phpunit.fr"));
$this->getDoctrine()->remove($mail);
$this->getDoctrine()->flush();
$result = $this->doPost("/ajax/users/subscribe/mail", Array(
"email" => "usertest001@twake_phpunit.fr",
"username" => "usertestfortest",
"password" => "usertest001",
"name" => "namefortest",
"firstname" => "firstnamefortest",
"phone" => "phonefortest"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$this->assertEquals("disconnected", $result["errors"]["0"]);
$this->assertEquals(Array(), $result["data"]);
$this->removeUserByName("usertest001");
$result = $this->doPost("/ajax/users/subscribe/mail", Array(
"email" => "usertest001@twake_phpunit.fr",
"username" => "usertest001",
"password" => "usertest001",
"name" => "namefortest",
"firstname" => "firstnamefortest",
"phone" => "phonefortest"
));
$token = $result["data"]["token"];
$boolean = false;
if (is_string($token) && strlen($result["data"]["token"]) > 5) {
$boolean = true;
}
$this->assertEquals(true, $boolean);
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$result = $this->doPost("/ajax/users/subscribe/mail", Array(
"email" => "usertest001_notused@twake_phpunit.fr",
"username" => "usertest001",
"password" => "usertest001",
"name" => "namefortest",
"firstname" => "firstnamefortest",
"phone" => "phonefortest"
));
$result = $result["errors"][0];
$this->assertEquals("usernamealreadytaken", $result, "testing username available");
$result = $this->doPost("/ajax/users/subscribe/mail", Array(
"email" => "12345678",
"username" => "usertestfortest",
"password" => "usertest00D222",
"name" => "namefortest",
"firstname" => "firstnamefortest",
"phone" => "phonefortest"
));
$result = $result["errors"][0];
$this->assertEquals("mailalreadytaken", $result, "Testing wrong mail format");
$result = $this->doPost("/ajax/users/subscribe/mail", Array(
"email" => "usertest001@twake_phpunit.fr",
"username" => "usertestfortest",
"password" => "usertest001",
"name" => "namefortest",
"firstname" => "firstnamefortest",
"phone" => "phonefortest"
));
$result = $result["errors"][0];
$this->assertEquals("mailalreadytaken", $result, "testing mail available");
$mailfortest = new Mail();
$mailfortest->setMail("emailforphpunittest@twake_phpunit.fr");
$this->getDoctrine()->persist($mailfortest);
$this->getDoctrine()->flush();
$result = $this->doPost("/ajax/users/subscribe/mail", Array(
"email" => "emailforphpunittest@twake_phpunit.fr",
"username" => "usertestfortest",
"password" => "usertest001",
"name" => "namefortest",
"firstname" => "firstnamefortest",
"phone" => "phonefortest"
));
$this->removeUserByName("usertest001");
}
}
+355
View File
@@ -0,0 +1,355 @@
<?php
namespace Tests\UsersBundle;
require_once __DIR__ . "/../WebTestCaseExtended.php";
use Tests\WebTestCaseExtended;
use Twake\Users\Entity\Device;
class UserLoginTest extends WebTestCaseExtended
//Tests when the user is not connected yet
{
public function testLoginCorrect()
{
$user = $this->newUserByName("usertest001");
$this->login("usertest001");
$result = $this->doPost("/ajax/users/current/get", Array());
$name = $result["data"]["username"];
$this->assertEquals("usertest001", $name);
}
public function testLoginIncorrect()
{
$user = $this->newUserByName("usertest001");
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "wrong email",
));
$result = $this->doPost("/ajax/users/current/get", Array());
$this->assertEquals("disconnected", $result["errors"]["0"]);
$this->assertEquals(Array(), $result["data"]);
}
public function testEmailCorrect()
{
$user = $this->newUserByName("usertest001");
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001@twake_phpunit.fr",
"_password" => "usertest001"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$email = $result["data"]["mails"][0]["email"];
$this->assertEquals("usertest001@twake_phpunit.fr", $email);
}
public function testPasswordIncorrect()
{
$user = $this->newUserByName("usertest001");
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "wrong password"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$this->assertEquals("disconnected", $result["errors"]["0"]);
$this->assertEquals(Array(), $result["data"]);;
}
public function testBanuser()
{
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$this->assertEquals(false, $user->getBanned());
$ban = $this->get("app.user")->ban($user->getId());
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$this->assertEquals(true, $user->getBanned());
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "usertest001"
));
$this->assertEquals("disconnected", $result["data"]["status"]);
//test for unban
$unban = $this->get("app.user")->unban($user->getId());
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "usertest001"
));
$this->assertEquals("connected", $result["data"]["status"]);
}
public function testPassword()
{
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$checkPass = $this->get("app.user")->checkPassword($user->getId(), "usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$this->assertEquals(true, $checkPass);
$checkPass = $this->get("app.user")->checkPassword($user->getId(), "wrong password");
$this->assertEquals(false, $checkPass);
}
public function testPasswordNoExistingUser()
{
$this->removeUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$checkPass = $this->get("app.user")->checkPassword("14005200-48b1-11e9-a0b4-0242ac120005", "usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$this->assertEquals(false, $checkPass);
}
public function testAvailableMail()
{
$this->removeUserByName("usertest001");
$result = $this->get("app.user")->getAvaibleMailPseudo("usertest001@twake_phpunit.fr", "usertest001");
$this->assertEquals(true, $result);
$user = $this->newUserByName("usertest001");
$result = $this->get("app.user")->getAvaibleMailPseudo("usertest001@twake_phpunit.fr", "usertest001");
$this->assertGreaterThan(0, count($result));
$result = $this->get("app.user")->getAvaibleMailPseudo("wrong email", "usertest001");
$this->assertGreaterThan(0, count($result));
}
public function testLogoutCorrect()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "usertest001"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$name = $result["data"]["username"];
$this->assertEquals("usertest001", $name);
$result = $this->doPost("/ajax/users/logout", Array());
$this->clearClient();
$result = $this->doPost("/ajax/users/current/get", Array());
$this->assertEquals(Array(), $result["data"]);
}
public function testVerifyMail()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$result = $this->doPost("/ajax/users/recover/mail", Array(
"email" => "usertest001@twake_phpunit.fr"
));
$token = $result["data"]["token"];
$verif = $this->getDoctrine()->getRepository("Twake\Users:VerificationNumberMail")->findOneBy(Array("token" => $token));
$code = $verif->getcode();
$this->getDoctrine()->persist($verif);
$this->getDoctrine()->flush();
$res = $this->doPost("/ajax/users/subscribe/doverifymail", Array(
"code" => $code,
"token" => $token,
"mail" => "usertest001@twake_phpunit.fr"
));
$verificationRepository = $this->getDoctrine()->getRepository("Twake\Users:VerificationNumberMail");
$ticket = $verificationRepository->findOneBy(Array("token" => $token));
$mail = trim(strtolower("usertest001@twake_phpunit.fr"));
$this->assertEquals(true, $ticket->getVerified());
$this->assertEquals(true, $user->getMailVerifiedExtended());
$email = $this->getDoctrine()->getRepository("Twake\Users:Mail")->findOneBy(Array("mail" => "usertest001@twake_phpunit.fr"));
$email = $email->getMail();
$this->assertEquals("usertest001@twake_phpunit.fr", $email);
$workspaceUerByMailRepository = $this->getDoctrine()->getRepository("Twake\Workspaces:WorkspaceUserByMail")->findOneBy(Array("mail" => "usertest001@twake_phpunit.fr"));
$this->assertEquals(null, $workspaceUerByMailRepository);
$res = $this->doPost("/ajax/users/subscribe/doverifymail", Array(
"code" => "ftvg",
"token" => "bgfsdngfn",
"mail" => "usertest001@twake_phpunit.fr"
));
}
public function testAddDevice()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "usertest001"
));
$device = Array(
"type" => "APNS",
"value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890",
"version" => "1.2.0"
);
$existedDevice = $this->getDoctrine()->getRepository("Twake\Users:Device")->findOneBy(Array("value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890"));
if (isset($existedDevice)) {
$this->getDoctrine()->remove($existedDevice);
$this->getDoctrine()->flush();
}
$res = $this->doPost("/ajax/users/current/get", Array(
"device" => $device
));
$existedDevice = $this->getDoctrine()->getRepository("Twake\Users:Device")->findOneBy(Array("value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890"));
$existedDeviceValue = $existedDevice->getValue();
$this->assertEquals("AZERTYUIOPQSDFGHJKLMWXCVBN134567890", $existedDeviceValue);
$device = Array(
"type" => "APNS",
"value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890",
"version" => "1.3.0"
);
$res = $this->doPost("/ajax/users/current/get", Array(
"device" => $device
));
$existedDevice = $this->getDoctrine()->getRepository("Twake\Users:Device")->findOneBy(Array("value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890"));
$existedDeviceValue = $existedDevice->getValue();
$this->assertEquals("1.3.0", $existedDevice->getVersion());
$this->removeUserByName("usertest002");
$user = $this->newUserByName("usertest002");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest002"));
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest002",
"_password" => "usertest002"
));
$res = $this->doPost("/ajax/users/current/get", Array(
"device" => $device
));
$existedDevice = $this->getDoctrine()->getRepository("Twake\Users:Device")->findOneBy(Array("value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890"));
$this->assertEquals($user->getId(), $existedDevice->getUserId());
}
public function testRemoveDevice()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest002",
"_password" => "usertest002"
));
$device_array = Array(
"type" => "APNS",
"value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890",
"version" => "1.2.0"
);
$device = $this->getDoctrine()->getRepository("Twake\Users:Device")->findOneBy(Array("value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890"));
$deviceValue = $device->getValue();
$this->assertEquals("AZERTYUIOPQSDFGHJKLMWXCVBN134567890", $deviceValue);
$res = $this->doPost("/ajax/users/logout", Array(
"device" => $device_array
));
$device = $this->getDoctrine()->getRepository("Twake\Users:Device")->findOneBy(Array("value" => "AZERTYUIOPQSDFGHJKLMWXCVBN134567890"));
$this->assertEquals(null, $device);
}
public function testAddNewMail()
{
$this->removeUserByName("usertest001");
$user = $this->newUserByName("usertest001");
$user = $this->getDoctrine()->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => "usertest001"));
$result = $this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "usertest001"
));
$result = $this->doPost("/ajax/users/account/addmail", Array(
"mail" => "usertest001secondmail@twake_phpunit.fr"
));
}
}