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
+821
View File
@@ -0,0 +1,821 @@
<?php
namespace Tests\AccessBundle;
require_once __DIR__ . "/../WebTestCaseExtended.php";
use Tests\WebTestCaseExtended;
use Twake\Calendar\Entity\Calendar;
use Twake\Channels\Entity\Channel;
use Twake\Discussion\Entity\Message;
use Twake\Users\Entity\User;
use Twake\Workspaces\Entity\WorkspaceUser;
use Twake\Workspaces\Entity\Workspace;
use Twake\Workspaces\Entity\Group;
class AccessTest extends WebTestCaseExtended
{
public function testAccess()
{
//// =================================================================================================================================================
//// =================================================================================================================================================
// ON CREE UN GROUP POUR CREER NOS DEUX WORKSPACES
$group = new Group("group_for_test");
$this->get("app.twake_doctrine")->persist($group);
$this->get("app.twake_doctrine")->flush();
// ON CREE NOS DEUX WORKSPACES POUR FAIRE NOS TESTS
//creation du premier workspace
$workspace1 = new Workspace("workspace1_for_test");
$workspace1->setGroup($group);
$this->get("app.twake_doctrine")->persist($workspace1);
$this->get("app.twake_doctrine")->flush();
$workspace1_id = $workspace1->getId() . "";
//creation du deuxieme workspace
$workspace2 = new Workspace("workspace2_for_test");
$workspace2->setGroup($group);
$this->get("app.twake_doctrine")->persist($workspace2);
$this->get("app.twake_doctrine")->flush();
$workspace2_id = $workspace2->getId() . "";
//// =================================================================================================================================================
//// =================================================================================================================================================
//ON CREE LES USERS
$this->removeUserByName("usertest003");
$this->newUserByName("usertest003");
$this->doPost("/ajax/users/login", Array(
"_username" => "usertest003",
"_password" => "usertest003"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$user3_id = $result["data"]["id"];
$result = $this->doPost("/ajax/users/logout", Array());
$this->clearClient();
$this->removeUserByName("usertest002");
$this->newUserByName("usertest002");
$this->doPost("/ajax/users/login", Array(
"_username" => "usertest002",
"_password" => "usertest002"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$user2_id = $result["data"]["id"];
$result = $this->doPost("/ajax/users/logout", Array());
$this->clearClient();
$this->removeUserByName("usertest001");
$this->newUserByName("usertest001");
$this->doPost("/ajax/users/login", Array(
"_username" => "usertest001",
"_password" => "usertest001"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$user1_id = $result["data"]["id"];
$user1 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user1_id));
$user2 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user2_id));
$user3 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user3_id));
//// =================================================================================================================================================
//// =================================================================================================================================================
// POUR FAIRE LE LIEN ENTRE LE USER1 ET LE WORKSPACE 1 (RESPECTIVEMENT USER2 WORKSPACE2) -> ON CREE DEUX WORKSPACEUSERS
$workspace1 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace1_id));
$workspace2 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace2_id));
// //creation workspaceUser1
$workspaceUser1 = new WorkspaceUser($workspace1, $user1, null);
$this->get("app.twake_doctrine")->persist($workspaceUser1);
$this->get("app.twake_doctrine")->flush();
//creation workspaceUser2
$workspaceUser2 = new WorkspaceUser($workspace2, $user2, null);
$this->get("app.twake_doctrine")->persist($workspaceUser2);
$this->get("app.twake_doctrine")->flush();
//creation workspaceUser3
$workspaceUser3 = new WorkspaceUser($workspace1, $user3, null);
$this->get("app.twake_doctrine")->persist($workspaceUser3);
$this->get("app.twake_doctrine")->flush();
//// =================================================================================================================================================
//// =================================================================================================================================================
//POUR CHAQUE WORKSPACE, ON CREE DEUX CHANNELS
//pour le workspace1
$channel1 = new Channel();
$channel1->setOriginalWorkspaceId($workspace1_id);
$channel1->setMembers(Array($user1_id)); // pour donner acces a user1 au channel1
$channel1->setExtMembers(Array($user3_id));
$this->get("app.twake_doctrine")->persist($channel1);
$this->get("app.twake_doctrine")->flush();
$channel1_ID = $channel1->getId();
$channel2 = new Channel();
$channel2->setOriginalWorkspaceId($workspace1_id);
$channel2->setMembers(Array($user1_id)); // pour donner acces a user1 au channel2
$this->get("app.twake_doctrine")->persist($channel2);
$this->get("app.twake_doctrine")->flush();
$channel2_ID = $channel2->getId();
//pour le workspace2
$channel3 = new Channel();
$channel3->setOriginalWorkspaceId($workspace2_id);
$channel3->setMembers(Array($user2_id)); // pour donner acces a user2 au channel3
$this->get("app.twake_doctrine")->persist($channel3);
$this->get("app.twake_doctrine")->flush();
$channel3_ID = $channel3->getId();
$channel4 = new Channel();
$channel4->setOriginalWorkspaceId($workspace2_id);
$channel4->setMembers(Array($user2_id)); // pour donner acces a user2 au channel4
$this->get("app.twake_doctrine")->persist($channel4);
$this->get("app.twake_doctrine")->flush();
$channel4_ID = $channel4->getId();
//// =================================================================================================================================================
//// =================================================================================================================================================
// ON CREE DEUX MESSAGES PAR CHANNEL
//pour le channel 1
$message1 = new Message($channel1_ID, "null");
$this->get("app.twake_doctrine")->persist($message1);
$this->get("app.twake_doctrine")->flush();
$message1_ID = $message1->getId();
$message2 = new Message($channel1_ID, "null");
$this->get("app.twake_doctrine")->persist($message2);
$this->get("app.twake_doctrine")->flush();
$message2_ID = $message2->getId();
//pour le channel 2
$message3 = new Message($channel2_ID, "null");
$this->get("app.twake_doctrine")->persist($message3);
$this->get("app.twake_doctrine")->flush();
$message3_ID = $message3->getId();
$message4 = new Message($channel2_ID, "null");
$this->get("app.twake_doctrine")->persist($message4);
$this->get("app.twake_doctrine")->flush();
$message4_ID = $message4->getId();
//pour le channel 3
$message5 = new Message($channel3_ID, "null");
$this->get("app.twake_doctrine")->persist($message5);
$this->get("app.twake_doctrine")->flush();
$message5_ID = $message5->getId();
$message6 = new Message($channel3_ID, "null");
$this->get("app.twake_doctrine")->persist($message6);
$this->get("app.twake_doctrine")->flush();
$message6_ID = $message6->getId();
//pour le channel 4
$message7 = new Message($channel4_ID, "null");
$this->get("app.twake_doctrine")->persist($message7);
$this->get("app.twake_doctrine")->flush();
$message7_ID = $message7->getId();
$message8 = new Message($channel4_ID, "null");
$this->get("app.twake_doctrine")->persist($message8);
$this->get("app.twake_doctrine")->flush();
$message8_ID = $message8->getId();
//// =================================================================================================================================================
//// =================================================================================================================================================
// ON RECUPERE LA RACINE DE CE NOUVEAU WORKSPACE ET ON CREE DEUX FICHIER
$root = $this->get("app.drive")->getRootEntity($workspace1_id);
$root_id = $root->getId() . "";
$object = Array("parent_id" => $root_id, "workspace_id" => $workspace1_id . "", "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "filefortest", "is_directory" => false);
$data = Array("upload_mode" => "chunk", "identifier" => "identifier", "nb_chunk" => 1);
$options = Array("new" => true, "data" => $data, "version" => true);
$result = $this->doPost("/ajax/drive/v2/save", Array(
"object" => $object,
"options" => $options
));
$idtofind_parent = $result["data"]["object"]["id"];
$object = Array("workspace_id" => $workspace1_id, "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "filefortest", "detached" => true, "is_directory" => false);
$options = Array("new" => true, "data" => $data, "version" => true);
$result = $this->doPost("/ajax/drive/v2/save", Array(
"object" => $object,
"options" => $options
));
$idtofind_detached = $result["data"]["object"]["id"];
$object = Array("parent_id" => $root_id, "workspace_id" => $workspace1_id, "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "filefortest", "is_directory" => false);
$data = Array("upload_mode" => "chunk", "identifier" => "identifier", "nb_chunk" => 1);
$options = Array("new" => true, "data" => $data, "version" => true);
$result = $this->doPost("/ajax/drive/v2/save", Array(
"object" => $object,
"options" => $options
));
$idtofind_shared = $result["data"]["object"]["id"];
//error_log(print_r($idtofind_shared,true));
//$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_shared));
// $file->setShared(true);
// $this->get("app.twake_doctrine")->persist($file);
// $this->get("app.twake_doctrine")->flush();
/*
$result = $this->doPost("/ajax/drive/publicaccess", Array(
"file_id" => $idtofind_shared,
"is_editable" => false,
"authorized_members" => Array($user3_id),
"authorized_channels" => Array()
));
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_shared));
$publicdata = $file->getAccesInfo();
// error_log(print_r($publicdata, true));
$this->assertEquals(true, in_array($user3_id, $publicdata["authorized_members"]), "User 3 id is not inside the public data of file shared");
*/
//// =================================================================================================================================================
//// =================================================================================================================================================
$calendar = new Calendar($workspace1_id, "calendarfortest", "red");
$this->get("app.twake_doctrine")->persist($calendar);
$this->get("app.twake_doctrine")->flush();
$id_calendar = $calendar->getId();
//// =================================================================================================================================================
//// =================================================================================================================================================
//ON VERIFIE ...
//test que le user1 a acces au workspace1
$data = Array("type" => "Workspace", "object_id" => $workspace1_id);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 don't have acces to the workspace 1 , he should");
//test que le user1 n'a pas acces au workspace2
$data = Array("type" => "Workspace", "object_id" => $workspace2_id);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 1 have acces to the workspace 2 , he shouldn't");
//test que le user1 a acces au channel 1 et 2 du workspace 1
$data = Array("type" => "Channel", "object_id" => $channel1_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 don't have acces to the channel 1 , he should");
$data = Array("type" => "Channel", "object_id" => $channel2_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 don't have acces to the channel 2 , he should");
// test que le user1 n'a pas acces au channel 2 et 3 du workspace 2
$data = Array("type" => "Channel", "object_id" => $channel3_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 1 have acces to the channel 3 , he shouldn't");
$data = Array("type" => "Channel", "object_id" => $channel4_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 1 have acces to the channel 4 , he shouldn't");
//test que le user1 a acces au message 1 par exemple (doit aussi fonctionner avec les messages 2, 3 et 4)
$data = Array("type" => "Message", "object_id" => $message1_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 don't have acces to the message 1 , he should");
//test que le user 1 n'a pas acces au message 5 par exemple (doit aussi fonctionner aves les messages 6, 7 et 8)
$data = Array("type" => "Message", "object_id" => $message5_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 1 have acces to the message 1 , he shouldn't");
$data = Array("type" => "DriveFile", "object_id" => $idtofind_parent);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 don't have access to filefortest , he should");
$data = Array("type" => "DriveFile", "object_id" => $idtofind_detached);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 doesnt have access to detached file , he should");
$result = $this->doPost("/ajax/core/workspaceaccess", Array(
"workspace_id" => $workspace1_id,
));
$this->assertEquals(true, $result["data"], "User 1 have access to workspace 1 with special function , he shouldn't");
$data = Array("type" => "Calendar", "object_id" => $id_calendar);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 1 don't have access to calendar , he should");
//// =================================================================================================================================================
//// =================================================================================================================================================
//FOR USER 2testSaveFiletestSaveFile
$result = $this->doPost("/ajax/users/logout", Array());
$this->clearClient();
$this->doPost("/ajax/users/login", Array(
"_username" => "usertest002",
"_password" => "usertest002"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$user2_id = $result["data"]["id"];
//test que le user2 a acces au workspace2
$data = Array("type" => "Workspace", "object_id" => $workspace2_id);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 2 don't have acces to the workspace 2 , he should");
//test que le user2 n'a pas acces au workspace1
$data = Array("type" => "Workspace", "object_id" => $workspace1_id);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 2 have acces to the workspace 1 , he shouldn't");
// test que le user2 a acces au channel 3 et 4 du workspace 2
$data = Array("type" => "Channel", "object_id" => $channel3_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 2 don't have acces to the channel 3 , he should");
$data = Array("type" => "Channel", "object_id" => $channel4_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 2 don't have acces to the channel 4 , he should");
// test que le user2 n'a pas acces au channel 1 et 2 du workspace 1
$data = Array("type" => "Channel", "object_id" => $channel1_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 2 have acces to the channel 1 , he shouldn't");
$data = Array("type" => "Channel", "object_id" => $channel2_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 2 have acces to the channel 2 , he shouldn't");
//test que le user2 a acces au message 5 par exemple (doit aussi fonctionner avec les messages 6, 7 et 8)
$data = Array("type" => "Message", "object_id" => $message5_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 2 don't have acces to the message 5 , he should");
//test que le user 2 n'a pas acces au message 1 par exemple (doit aussi fonctionner aves les messages 1, 2 et 3)
$data = Array("type" => "Message", "object_id" => $message1_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 2 have acces to the message 1 , he shouldn't");
$data = Array("type" => "DriveFile", "object_id" => $idtofind_parent);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 2 have access to filefortest , he should not");
$data = Array("type" => "Calendar", "object_id" => $id_calendar);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 2 have access to calendar , he should not");
//// =================================================================================================================================================
//// =================================================================================================================================================
//FOR USER 3
$result = $this->doPost("/ajax/users/logout", Array());
$this->clearClient();
$this->doPost("/ajax/users/login", Array(
"_username" => "usertest003",
"_password" => "usertest003"
));
$result = $this->doPost("/ajax/users/current/get", Array());
$user3_id = $result["data"]["id"];
//test que le user1 a acces au workspace1
$data = Array("type" => "Workspace", "object_id" => $workspace1_id);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 3 don't have acces to the workspace 1 , he should");
//test que le user1 n'a pas acces au workspace2
$data = Array("type" => "Workspace", "object_id" => $workspace2_id);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 3 have acces to the workspace 2 , he shouldn't");
//test que le user1 a acces au channel 1 et 2 du workspace 1
$data = Array("type" => "Channel", "object_id" => $channel1_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 3 don't have acces to the channel 1 , he should");
$data = Array("type" => "Channel", "object_id" => $channel2_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 3 have acces to the channel 2 , he should not");
// test que le user1 n'a pas acces au channel 2 et 3 du workspace 2
$data = Array("type" => "Channel", "object_id" => $channel3_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 3 have acces to the channel 3 , he shouldn't");
$data = Array("type" => "Channel", "object_id" => $channel4_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 3 have acces to the channel 4 , he shouldn't");
//test que le user1 a acces au message 1 par exemple (doit aussi fonctionner avec les messages 2, 3 et 4)
$data = Array("type" => "Message", "object_id" => $message1_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 3 don't have acces to the message 1 , he should");
$data = Array("type" => "Message", "object_id" => $message3_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 3 have acces to the message 3 , he shouldn't");
$data = Array("type" => "Message", "object_id" => $message5_ID);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(false, $result["data"], "User 3 have acces to the message 5 , he shouldn't");
$data = Array("type" => "DriveFile", "object_id" => $idtofind_parent);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 3 don't have access to filefortest , he should");
$data = Array("type" => "DriveFile", "object_id" => $idtofind_detached);
$result = $this->doPost("/ajax/core/access", Array(
"data" => $data
));
$this->assertEquals(true, $result["data"], "User 3 doesnt have access to detached file , he should");
//// =================================================================================================================================================
//// =================================================================================================================================================
// ON SUPPRIME TOUT CE QU ON A CREE ET ON VERIFIE QUE LES ENTITES SUPPRIMEES N EXISTENT PLUS
// pour les messages
$message1 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message1->getId() . ""));
$this->get("app.twake_doctrine")->remove($message1);
$this->get("app.twake_doctrine")->flush();
$message1 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message1->getId() . ""));
$this->assertEquals(null, $message1);
$message2 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message2->getId() . ""));
$this->get("app.twake_doctrine")->remove($message2);
$this->get("app.twake_doctrine")->flush();
$message2 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message2->getId() . ""));
$this->assertEquals(null, $message2);
$message3 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message3->getId() . ""));
$this->get("app.twake_doctrine")->remove($message3);
$this->get("app.twake_doctrine")->flush();
$message3 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message3->getId() . ""));
$this->assertEquals(null, $message3);
$message4 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message4->getId() . ""));
$this->get("app.twake_doctrine")->remove($message4);
$this->get("app.twake_doctrine")->flush();
$message4 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message4->getId() . ""));
$this->assertEquals(null, $message4);
$message5 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message5->getId() . ""));
$this->get("app.twake_doctrine")->remove($message5);
$this->get("app.twake_doctrine")->flush();
$message5 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message5->getId() . ""));
$this->assertEquals(null, $message5);
$message6 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message6->getId() . ""));
$this->get("app.twake_doctrine")->remove($message6);
$this->get("app.twake_doctrine")->flush();
$message6 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message6->getId() . ""));
$this->assertEquals(null, $message6);
$message7 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message7->getId() . ""));
$this->get("app.twake_doctrine")->remove($message7);
$this->get("app.twake_doctrine")->flush();
$message7 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message7->getId() . ""));
$this->assertEquals(null, $message7);
$message8 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message8->getId() . ""));
$this->get("app.twake_doctrine")->remove($message8);
$this->get("app.twake_doctrine")->flush();
$message8 = $this->get("app.twake_doctrine")->getRepository("Twake\Discussion:Message")->findOneBy(Array("id" => $message8->getId() . ""));
$this->assertEquals(null, $message8);
// pour les channels
$channel1 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel1->getId() . ""));
$this->get("app.twake_doctrine")->remove($channel1);
$this->get("app.twake_doctrine")->flush();
$channel1 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel1->getId() . ""));
$this->assertEquals(null, $channel1);
$channel2 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel2->getId() . ""));
$this->get("app.twake_doctrine")->remove($channel2);
$this->get("app.twake_doctrine")->flush();
$channel2 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel2->getId() . ""));
$this->assertEquals(null, $channel2);
$channel3 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel3->getId() . ""));
$this->get("app.twake_doctrine")->remove($channel3);
$this->get("app.twake_doctrine")->flush();
$channel3 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel3->getId() . ""));
$this->assertEquals(null, $channel3);
$channel4 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel4->getId() . ""));
$this->get("app.twake_doctrine")->remove($channel4);
$this->get("app.twake_doctrine")->flush();
$channel4 = $this->get("app.twake_doctrine")->getRepository("Twake\Channels:Channel")->findOneBy(Array("id" => $channel4->getId() . ""));
$this->assertEquals(null, $channel4);
// pour les worskspaceUser
$workspaceUser1 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:WorkspaceUser")->findBy(Array("workspace_id" => $workspace1_id));
foreach ($workspaceUser1 as $wp) {
$this->get("app.twake_doctrine")->remove($wp);
$this->get("app.twake_doctrine")->flush();
}
$workspaceUser1 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:WorkspaceUser")->findOneBy(Array("workspace_id" => $workspace1_id));
$this->assertEquals(null, $workspaceUser1);
$workspaceUser2 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:WorkspaceUser")->findOneBy(Array("workspace_id" => $workspace2_id));
$this->get("app.twake_doctrine")->remove($workspaceUser2);
$this->get("app.twake_doctrine")->flush();
$workspaceUser2 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:WorkspaceUSer")->findOneBy(Array("workspace_id" => $workspace2_id));
$this->assertEquals(null, $workspaceUser2);
//pour les fichiers
$version = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_parent));
foreach ($version as $v) {
$this->get("app.twake_doctrine")->remove($v);
$this->get("app.twake_doctrine")->flush();
}
$version = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_parent));
$this->assertEquals(Array(), $version);
$version = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_shared));
foreach ($version as $v) {
$this->get("app.twake_doctrine")->remove($v);
$this->get("app.twake_doctrine")->flush();
}
$version = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_shared));
$this->assertEquals(Array(), $version);
$version = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_detached));
foreach ($version as $v) {
$this->get("app.twake_doctrine")->remove($v);
$this->get("app.twake_doctrine")->flush();
}
$version = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_detached));
$this->assertEquals(Array(), $version);
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->get("app.twake_doctrine")->remove($file);
$this->get("app.twake_doctrine")->flush();
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals(null, $file);
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->get("app.twake_doctrine")->remove($file);
$this->get("app.twake_doctrine")->flush();
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals(null, $file);
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_shared));
$this->get("app.twake_doctrine")->remove($file);
$this->get("app.twake_doctrine")->flush();
$file = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_shared));
$this->assertEquals(null, $file);
//pour calendar
$calendar = $this->get("app.twake_doctrine")->getRepository("Twake\Calendar:Calendar")->findOneBy(Array("id" => $id_calendar));
$this->get("app.twake_doctrine")->remove($calendar);
$this->get("app.twake_doctrine")->flush();
$calendar = $this->get("app.twake_doctrine")->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $id_calendar));
$this->assertEquals(null, $calendar);
// pour les users
$mail1 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findOneBy(Array("user_id" => $user1_id));
$this->get("app.twake_doctrine")->remove($mail1);
$this->get("app.twake_doctrine")->flush();
$mail2 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findOneBy(Array("user_id" => $user2_id));
$this->get("app.twake_doctrine")->remove($mail2);
$this->get("app.twake_doctrine")->flush();
$mail3 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findOneBy(Array("user_id" => $user3_id));
$this->get("app.twake_doctrine")->remove($mail3);
$this->get("app.twake_doctrine")->flush();
$mail1 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findOneBy(Array("user_id" => $user1_id));
$this->assertEquals(null, $mail1);
$mail2 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findOneBy(Array("user_id" => $user2_id));
$this->assertEquals(null, $mail2);
$mail3 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findOneBy(Array("user_id" => $user3_id));
$this->assertEquals(null, $mail3);
$user1 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user1_id));
$this->get("app.twake_doctrine")->remove($user1);
$this->get("app.twake_doctrine")->flush();
$user1 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user1_id));
$this->assertEquals(null, $user1);
$user2 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user2_id));
$this->get("app.twake_doctrine")->remove($user2);
$this->get("app.twake_doctrine")->flush();
$user2 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user2_id));
$this->assertEquals(null, $user2);
$user3 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user3_id));
$this->get("app.twake_doctrine")->remove($user3);
$this->get("app.twake_doctrine")->flush();
$user3 = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("id" => $user3_id));
$this->assertEquals(null, $user3);
// pour les worskspaces
$workspace1 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace1->getId() . ""));
$this->get("app.twake_doctrine")->remove($workspace1);
$workspace2 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace2->getId() . ""));
$this->get("app.twake_doctrine")->remove($workspace2);
// pour le groupe
$group = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Group")->findOneBy(Array("id" => $group->getId() . ""));
$this->get("app.twake_doctrine")->remove($group);
$this->get("app.twake_doctrine")->flush();
$group = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Group")->findOneBy(Array("id" => $group->getId() . ""));
$this->assertEquals(null, $group);
$workspace1 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace1->getId() . ""));
$this->assertEquals(null, $workspace1);
$workspace2 = $this->get("app.twake_doctrine")->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace2->getId() . ""));
$this->assertEquals(null, $workspace2);
}
}
@@ -0,0 +1,506 @@
<?php
namespace Tests\DriveBundle;
require_once __DIR__ . "/../WebTestCaseExtended.php";
use Tests\WebTestCaseExtended;
use Twake\Workspaces\Entity\Workspace;
use Twake\Workspaces\Entity\Group;
use Twake\Workspaces\Entity\WorkspaceUser;
use Twake\Workspaces\Entity\GroupUser;
class DriveCollectionTest extends WebTestCaseExtended
{
public function testSaveFile()
{
// ON CREE UN GROUP POUR CREER NOTRE WORKSPACE
$group = new Group("group_for_test");
$this->getDoctrine()->persist($group);
// ON CREE UN WORKSPACE POUR FAIRE NOS TESTS SUR LES FICHIERS
$workspace = new Workspace("workspace_for_test");
$workspace->setGroup($group);
$this->getDoctrine()->persist($workspace);
$this->getDoctrine()->persist($group);
$this->getDoctrine()->flush();
$workspace_id = $workspace->getId() . "";
// ON RECUPERE LA RACINE DE CE NOUVEAU WORKSPACE
$root = $this->get("app.drive")->getRootEntity($workspace_id);
$root_id = $root->getId() . "";
//error_log(print_r("root id: " . $root_id,true));
//ON RECUPERE LA CORBEILLE DE CE NOUVEAU WORKSPACE
$trash = $this->get("app.drive")->getTrashEntity($workspace_id);
$trash_id = $trash->getId() . "";
//error_log(print_r("trash id: " .$trash_id,true));
//ON CREEE UN USER POUR FAIRE NOS TEST ET ON LE CONNECTE
$this->removeUserByName("usertest001");
$user1 = $this->newUserByName("usertest001");
$this->login($user1->getUsernameCanonical());
$result = $this->doPost("/ajax/users/current/get", Array());
$user1_id = $result["data"]["id"];
$current_date = new \DateTime();
$current_date = $current_date->getTimestamp();
$workspaceUser1 = new WorkspaceUser($workspace, $user1, null);
$groupUser1 = new GroupUser($group, $user1);
$this->getDoctrine()->persist($workspaceUser1);
$this->getDoctrine()->persist($workspace);
$this->getDoctrine()->persist($user1);
$this->getDoctrine()->persist($groupUser1);
$this->getDoctrine()->persist($group);
$this->getDoctrine()->flush();
// =================================================================================================================================================
// =================================================================================================================================================
//ON CREE UN FICHIER QUI VA SE TROUVER A LA RACINE DU WORKSPACE EN SPECIFIANT UN PARENT
$object = Array("parent_id" => $root_id, "trash" => false, "workspace_id" => $workspace_id, "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "filefortest", "is_directory" => false);
$data = Array("upload_mode" => "chunk", "identifier" => "identifier", "nb_chunk" => 1);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options,
));
$idtofind_parent = $result["data"]["object"]["id"];
$this->assertEquals($workspace_id, $result["data"]["object"]["workspace_id"], "Wrong workspace id for file create with a parent " . json_encode($result));
$this->assertEquals($root_id, $result["data"]["object"]["parent_id"], "Wrong parent id for file create with a parent");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $result["data"]["object"]["front_id"], "Wrong front id for file create with a parent");
$this->assertEquals("filefortest", $result["data"]["object"]["name"], "Wrong name for file create with a parent");
$this->assertEquals(false, $result["data"]["object"]["trash"], "Wrong is in trash attribut for file create with a parent");
$this->assertEquals($user1_id, $result["data"]["object"]["last_user"], "Wrong last user for file create with a parent");
$added_parent = $result["data"]["object"]["added"];
$modified_parent = $result["data"]["object"]["modified"];
$this->assertLessThan(60, $modified_parent - $current_date, "Problem with date modified of filed create with a parent");
$this->assertLessThan(60, $added_parent - $current_date, "Problem with date added of filed create with a parent");
$this->assertEquals($modified_parent, $added_parent, "Added date and modified date should be the same");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals($workspace_id, $fileordirectory->getWorkspaceId() . "", "Wrong workspace id for file create with a parent in database");
$this->assertEquals($root_id, $fileordirectory->getParentId() . "", "Wrong parent id for file create with a parent in database");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $fileordirectory->getFrontId() . "", "Wrong front id for file create with a parent in database");
$this->assertEquals("filefortest", $fileordirectory->getName(), "Wrong name for file create with a parent in database");
$this->assertEquals(false, $fileordirectory->getIsInTrash(), "Wrong is in trash attribut for file create with a parent in database");
// =================================================================================================================================================
// =================================================================================================================================================
// ON CREE UN FICHIER QUI VA SE TROUVER A LA RACINE DU WORKSPACE SANS SPECIFIER UN PARENT
$object = Array("parent_id" => $root_id, "trash" => false, "workspace_id" => $workspace_id, "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "filefortest-randomothername", "is_directory" => false);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$idtofind_root = $result["data"]["object"]["id"];
$this->assertEquals($workspace_id, $result["data"]["object"]["workspace_id"], "Wrong workspace id for file create without a parent");
$this->assertEquals($root_id, $result["data"]["object"]["parent_id"], "Wrong parent id for file create without a parent");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $result["data"]["object"]["front_id"], "Wrong front id for file create without a parent");
$this->assertEquals("filefortest-randomothername", $result["data"]["object"]["name"], "Wrong name for file create without a parent");
$this->assertEquals(false, $result["data"]["object"]["trash"], "Wrong is in trash attribut for file create without a parent");
$this->assertEquals($user1_id, $result["data"]["object"]["last_user"], "Wrong last user for file create without a parent");
$added = $result["data"]["object"]["added"];
$modified = $result["data"]["object"]["modified"];
$this->assertLessThan(60, $modified - $current_date, "Problem with date modified of filed create with a parent");
$this->assertLessThan(60, $added - $current_date, "Problem with date added of filed create with a parent");
$this->assertEquals($modified, $added, "Added date and modified date should be the same");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_root));
$this->assertEquals($workspace_id, $fileordirectory->getWorkspaceId() . "", "Wrong workspace id for file create without a parent in database");
$this->assertEquals($root_id, $fileordirectory->getParentId() . "", "Wrong parent id for file create without a parent in database");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $fileordirectory->getFrontId() . "", "Wrong front id for file create without a parent in database");
$this->assertEquals(false, $fileordirectory->getIsInTrash(), "Wrong is in trash attribut for file create with a parent in database");
// =================================================================================================================================================
// =================================================================================================================================================
// ON CREE UN FICHIER DETACHED
$object = Array("workspace_id" => $workspace_id, "trash" => false, "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "filefortest-randomothername2", "detached" => true, "is_directory" => false);
$options = Array("new" => true, "data" => $data, "version" => true);
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$idtofind_detached = $result["data"]["object"]["id"];
$this->assertEquals($workspace_id, $result["data"]["object"]["workspace_id"], "Wrong workspace id for file create detached");
$this->assertEquals("detached", $result["data"]["object"]["parent_id"], "Wrong parent id for file create detached");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $result["data"]["object"]["front_id"], "Wrong front id for file create detached");
$this->assertEquals(true, $result["data"]["object"]["detached"], "Wrong detached bool for file create without a parent detached");
$this->assertEquals("filefortest-randomothername2", $result["data"]["object"]["name"], "Wrong name for file create detached");
$this->assertEquals(false, $result["data"]["object"]["trash"], "Wrong is in trash attribut for file create detached");
$this->assertEquals($user1_id, $result["data"]["object"]["last_user"], "Wrong last user for file create detached");
/*$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(200000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");
*/
$added = $result["data"]["object"]["added"];
$modified = $result["data"]["object"]["modified"];
$this->assertLessThan(60, $modified - $current_date, "Problem with date modified of filed create with a parent");
$this->assertLessThan(60, $added - $current_date, "Problem with date added of filed create with a parent");
$this->assertEquals($modified, $added, "Added date and modified date should be the same");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals($workspace_id, $fileordirectory->getWorkspaceId() . "", "Wrong workspace id for file create without a parent in database");
$this->assertEquals("detached", $fileordirectory->getParentId() . "", "Wrong parent id for file create without a parent in database");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $fileordirectory->getFrontId() . "", "Wrong front id for file create without a parent in database");
$this->assertEquals(true, $fileordirectory->getDetachedFile(), "Wrong detached bool for file create without a parent detached in database");
$this->assertEquals(false, $fileordirectory->getIsInTrash(), "Wrong is in trash attribut for file create with a parent in database");
// =================================================================================================================================================
// =================================================================================================================================================
//ON VA ATTACHER LE FICHIER DETACHED CREE PRECEDEMENT A LA RACINE
$object = Array("id" => $idtofind_detached, "parent_id" => $root_id);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$this->assertEquals($workspace_id, $result["data"]["object"]["workspace_id"], "Wrong workspace id for file reatached");
$this->assertEquals($root_id, $result["data"]["object"]["parent_id"], "Wrong parent id for file reatached");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $result["data"]["object"]["front_id"], "Wrong front id for file reatached");
$this->assertEquals(false, $result["data"]["object"]["detached"], "Wrong detached bool for file reatached");
$this->assertEquals(false, $result["data"]["object"]["trash"], "Wrong is in trash attribut for file create with a parent");
//error_log(print_r(json_decode($result->getContent(),true),true));
/*$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for file create without a parent");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(300000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");*/
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals($workspace_id, $fileordirectory->getWorkspaceId() . "", "Wrong workspace id for file reatached");
$this->assertEquals($root_id, $fileordirectory->getParentId() . "", "Wrong parent id for file reatached");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $fileordirectory->getFrontId() . "", "Wrong front id for file reatached");
$this->assertEquals(false, $fileordirectory->getDetachedFile(), "Wrong detached bool for file reatached");
$this->assertEquals(false, $fileordirectory->getIsInTrash(), "Wrong is in trash attribut for file create with a parent in database");
// =================================================================================================================================================
// =================================================================================================================================================
//ON VA METTRE LE FICHIER PARENT A LA CORBEILLE ET REGARDER SI LES TAILLES SONT CORRECTES
$object = Array("id" => $idtofind_parent, "trash" => true);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
//error_log(print_r($result->getContent(),true));
$this->assertEquals(true, $result["data"]["object"]["trash"], "File should be in trash he is not");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals($trash_id, $fileordirectory->getParentId(), "File has nottrash as parent");
$this->assertEquals($root_id, $fileordirectory->getOldParent(), "File has nottrash as parent");
/*$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for the file");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in database");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(200000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");*/
// =================================================================================================================================================
// =================================================================================================================================================
//ON VA RESTAURER LE FICHIER DEPLACE SUR SON PARENT ET REGARDER SI LES TAILLES SONT CORRECTES
$object = Array("id" => $idtofind_parent, "trash" => false);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$this->assertEquals(false, $result["data"]["object"]["trash"], "File should not be in trash he is ");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals($root_id, $fileordirectory->getParentId(), "File has notroot as parent");
$this->assertEquals("", $fileordirectory->getOldParent(), "File got old parent he should not");
/*$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for the file");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in database");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(300000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file trash");*/
// =================================================================================================================================================
// =================================================================================================================================================
// ON CREE UN DOSSIER A LA RACINE
$object = Array("workspace_id" => $workspace_id, "front_id" => "14005200-48b1-11e9-a0b4-0242ac120005", "name" => "folderfortest", "is_directory" => true);
$options = Array("new" => true, "data" => $data, "version" => true);
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options,
));
$idtofind_folder = $result["data"]["object"]["id"];
$this->assertEquals($workspace_id, $result["data"]["object"]["workspace_id"], "Wrong workspace id for the folder ");
$this->assertEquals($root_id, $result["data"]["object"]["parent_id"], "Wrong parent id for the folder");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $result["data"]["object"]["front_id"], "Wrong front id for the folder");
$this->assertEquals("folderfortest", $result["data"]["object"]["name"], "Wrong name for the folder");
$this->assertEquals(false, $result["data"]["object"]["trash"], "Wrong is in trash attribut for the folder");
$this->assertEquals($user1_id, $result["data"]["object"]["last_user"], "Wrong last user for the folder");
$this->assertEquals(0, $result["data"]["object"]["size"], "Wrong size for the folder");
/*$this->assertEquals(0,$result["data"]["object"]["size"], "Wrong size for the folder");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in database");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(300000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file trash");*/
// =================================================================================================================================================
// =================================================================================================================================================
//ON VA ATTACHER LE FICHIER DETACHED CREE PRECEDEMENT AU DOSSIER QU ON VIENT DE CREER
$object = Array("id" => $idtofind_detached, "parent_id" => $idtofind_folder);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$this->assertEquals($workspace_id, $result["data"]["object"]["workspace_id"], "Wrong workspace id for file reatached");
$this->assertEquals($idtofind_folder, $result["data"]["object"]["parent_id"], "Wrong parent id for file reatached");
$this->assertEquals("14005200-48b1-11e9-a0b4-0242ac120005", $result["data"]["object"]["front_id"], "Wrong front id for file reatached");
$this->assertEquals(false, $result["data"]["object"]["detached"], "Wrong detached bool for file reatached");
$this->assertEquals(false, $result["data"]["object"]["trash"], "Wrong is in trash attribut for file create with a parent");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals($idtofind_folder, $fileordirectory->getParentId() . "", "Wrong parent for the file which should be in folder");
//error_log(print_r($result,true));
/*$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for file detached");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(300000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_folder));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the folder");*/
// =================================================================================================================================================
// =================================================================================================================================================
//ON MET LE DOSSIER CREE A LA CORBEILLE ET DONC LE FICHIER DETACHED EN MEME TEMPS
$object = Array("id" => $idtofind_folder, "trash" => true);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$this->assertEquals(true, $result["data"]["object"]["trash"], "Folder should be in trash he is not");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_folder));
$this->assertEquals($trash_id, $fileordirectory->getParentId(), "Folder as not trash as parent");
$this->assertEquals($root_id, $fileordirectory->getOldParent(), "Folder as not trash as parent");
$this->assertEquals(true, $fileordirectory->getIsInTrash(), "Folder as not trash as parent");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals($idtofind_folder, $fileordirectory->getParentId(), "Folder as not trash as parent");
$this->assertEquals("", $fileordirectory->getOldParent(), "Folder as not trash as parent");
$this->assertEquals(true, $fileordirectory->getIsInTrash(), "Folder as not trash as parent");
/*$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for the folder");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in database");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(200000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");*/
// =================================================================================================================================================
// =================================================================================================================================================
//ON VA RESTAURER LE FICHIER DETACHED QUI SE TROUVE DANS LE DOSSIER LUI MEME A LA CORBEILLE ET VOIR SI IL SE RESTAURE A LA RACINE
$object = Array("id" => $idtofind_detached, "trash" => false);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$fileson = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findBy(Array("workspace_id" => $workspace_id, "parent_id" => $idtofind_detached));
$this->assertEquals(false, $result["data"]["object"]["trash"], "Detached file should not be in trash he is ");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals($root_id, $fileordirectory->getParentId(), "Detached file as not trash as parent");
$this->assertEquals("", $fileordirectory->getOldParent(), "Detached file as not trash as parent");
$this->assertEquals(false, $fileordirectory->getIsInTrash(), "Detached file as not trash as parent");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_folder));
$this->assertEquals($trash_id, $fileordirectory->getParentId(), "Folder as not trash as parent");
$this->assertEquals($root_id, $fileordirectory->getOldParent(), "Folder as not trash as parent");
$this->assertEquals(true, $fileordirectory->getIsInTrash(), "Folder as not trash as parent");
/*$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for the file");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in database");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(300000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_folder));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");*/
// =================================================================================================================================================
// =================================================================================================================================================
//ON SUPPRIME LE FICHIER DETACHED
$object = Array("id" => $idtofind_detached);
$options = Array();
$result = $this->doPost("/ajax/drive/remove", Array(
"object" => $object,
"options" => $options
));
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_detached));
$this->assertEquals(null, $fileordirectory, "The deleted file still exist");
/*$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(200000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file trash");*/
// =================================================================================================================================================
// =================================================================================================================================================
// ON DEPLACE LE FICHIER PARENT EN LE RATACHANT A UN FICHIER DE LA CORBEILLE
$object = Array("id" => $idtofind_parent, "parent_id" => $idtofind_folder);
$options = Array();
$result = $this->doPost("/ajax/drive/save", Array(
"object" => $object,
"options" => $options
));
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals($idtofind_folder, $fileordirectory->getParentId(), "File has nottrash as parent");
$this->assertEquals($root_id, $fileordirectory->getOldParent(), "File has notroot as old parent");
$this->assertEquals(true, $fileordirectory->getIsInTrash(), "File is not in trash");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_folder));
$this->assertEquals($trash_id, $fileordirectory->getParentId(), "Folder is not trash as parent");
$this->assertEquals(true, $fileordirectory->getIsInTrash(), "Folder is not in trash");
$this->assertEquals(true, $result["data"]["object"]["trash"], "Folder should be in trash he is not");
/*$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_folder));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");
$this->assertEquals(100000,$result["data"]["object"]["size"], "Wrong size for the folder");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in database");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file in trash");*/
//ET ON LE SUPPRIME
$object = Array("id" => $idtofind_parent);
$options = Array();
$result = $this->doPost("/ajax/drive/remove", Array(
"object" => $object,
"options" => $options
));
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $idtofind_parent));
$this->assertEquals(null, $fileordirectory, "The deleted file still exist");
/*$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $trash_id));
$this->assertEquals(0, $fileordirectory->getAsArray()["size"], "Wrong size for the file trash");
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("id" => $root_id));
$this->assertEquals(100000, $fileordirectory->getAsArray()["size"], "Wrong size for the file root");*/
// =================================================================================================================================================
// =================================================================================================================================================
// ON SUPPRIME TOUS LES FICHIERS DU WORKSPACE, LE WORKSPACE EN LUI MEME AINSI QUE LE GROUPE
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findBy(Array("workspace_id" => $workspace_id));
foreach ($fileordirectory as $item) {
$this->getDoctrine()->remove($item);
}
$workspace = $this->getDoctrine()->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace_id));
$this->getDoctrine()->remove($workspace);
$group = $this->getDoctrine()->getRepository("Twake\Workspaces:Group")->findOneBy(Array("id" => $group->getId() . ""));
$this->getDoctrine()->remove($group);
$this->getDoctrine()->flush();
$group = $this->getDoctrine()->getRepository("Twake\Workspaces:Group")->findOneBy(Array("id" => $group->getId() . ""));
$this->assertEquals(null, $group);
$workspace = $this->getDoctrine()->getRepository("Twake\Workspaces:Workspace")->findOneBy(Array("id" => $workspace_id));
$this->assertEquals(null, $workspace);
$fileordirectory = $this->getDoctrine()->getRepository("Twake\Drive:DriveFile")->findOneBy(Array("workspace_id" => $workspace_id));
$this->assertEquals(null, $fileordirectory);
//ON SUPPRIME TOUTE LES VERSIONS QUI ONT ETE CREE
$version = $this->getDoctrine()->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_parent));
foreach ($version as $v) {
$this->getDoctrine()->remove($v);
$this->getDoctrine()->flush();
}
$version = $this->getDoctrine()->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_parent));
$this->assertEquals(Array(), $version);
$version = $this->getDoctrine()->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_root));
foreach ($version as $v) {
$this->getDoctrine()->remove($v);
$this->getDoctrine()->flush();
}
$version = $this->getDoctrine()->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_root));
$this->assertEquals(Array(), $version);
$version = $this->getDoctrine()->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_detached));
foreach ($version as $v) {
$this->getDoctrine()->remove($v);
$this->getDoctrine()->flush();
}
$version = $this->getDoctrine()->getRepository("Twake\Drive:DriveFileVersion")->findBy(Array("file_id" => $idtofind_detached));
$this->assertEquals(Array(), $version);
}
}
+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"
));
}
}
+209
View File
@@ -0,0 +1,209 @@
<?php
namespace Tests;
use App\App;
use Common\Http\Request;
use Twake\Workspaces\Entity\Group;
use Twake\Workspaces\Entity\Workspace;
use Twake\Channels\Entity\Channel;
use Twake\Channels\Entity\ChannelMember;
use Twake\Users\Entity\User;
use Twake\Workspaces\Entity\WorkspaceUser;
use Twake\Workspaces\Entity\WorkspaceLevel;
class WebTestCaseExtended extends \PHPUnit\Framework\TestCase
{
var $client;
/** @var App */
public $app;
public $cookies = [];
public function __construct()
{
error_reporting(E_ERROR | E_PARSE);
# Warning:
\PHPUnit_Framework_Error_Warning::$enabled = FALSE;
# notice, strict:
\PHPUnit_Framework_Error_Notice::$enabled = FALSE;
define("TESTENV", true);
}
protected function getDoctrine()
{
return $this->get("app.twake_doctrine");
}
protected function get($service)
{
return $this->getClient()->getServices()->get($service);
}
protected function clearApp()
{
$this->app = null;
}
protected function clearClient()
{
$this->cookies = [];
}
protected function getClient(): App
{
if (!isset($this->app) || !$this->app) {
$this->app = new App();
}
return $this->app;
}
protected function doPost($route, $data = Array())
{
$this->clearApp();
$request = new Request();
$query_data = $this->getQueryFromUrl($route);
$request->cookies->reset($this->cookies);
$request->request->reset($data);
$request->query->reset($query_data["query"]);
$response = $this->getClient()->getRouting()->execute("post", $query_data["route"], $request);
$this->cookies = array_merge($this->cookies, $response->getCookiesValues());
return json_decode($response->getContent(), 1);
}
protected function doGet($route)
{
$this->clearApp();
$request = new Request();
$request->cookies->reset($this->cookies);
$query_data = $this->getQueryFromUrl($route);
$request->query->reset($query_data["query"]);
$response = $this->getClient()->getRouting()->execute("get", $query_data["route"], $request);
$this->cookies = array_merge($this->cookies, $response->getCookiesValues());
return json_decode($response->getContent(), 1);
}
private function getQueryFromUrl($route)
{
$route = explode("?", $route);
if (count($route) == 1) {
return ["route" => $route[0], "query" => []];
}
$parts = $route[1];
parse_str($parts, $query);
return ["route" => $route[0], "query" => $query];
}
public function newUserByName($name, $mail = null)
{
$user = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => $name));
if ($user) {
$this->removeUserByName($name);
}
if (!$mail) {
$mail = $name . "@twake_phpunit.fr";
}
$userWithMail = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("emailcanonical" => $mail));
if ($userWithMail) {
$this->removeUserByName($userWithMail->getUsername());
}
$mails = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findBy(Array("mail" => $mail));
foreach ($mails as $mail) {
$this->get("app.twake_doctrine")->remove($mail);
$this->get("app.twake_doctrine")->flush();
}
$token = $this->get("app.user")->subscribeMail($mail, $name, $name, "", "", "", "en", false);
$this->get("app.user")->verifyMail($mail, $token, "", true);
$user = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => $name));
return $user;
}
public function removeUserByName($name)
{
$user = $this->get("app.twake_doctrine")->getRepository("Twake\Users:User")->findOneBy(Array("usernamecanonical" => $name));
if (isset($user)) {
$mails = $this->get("app.twake_doctrine")->getRepository("Twake\Users:Mail")->findBy(Array("user_id" => $user));
foreach ($mails as $mail) {
$this->get("app.twake_doctrine")->remove($mail);
}
$this->get("app.twake_doctrine")->remove($user);
$this->get("app.twake_doctrine")->flush();
}
}
public function newGroup($userId, $name)
{
$group = new Group($name);
$this->get("app.twake_doctrine")->persist($group);
$this->get("app.twake_doctrine")->flush();
return $group;
}
public function newWorkspace($name, $group)
{
$work = new Workspace($name);
$work->setGroup($group);
$this->get("app.twake_doctrine")->persist($work);
$this->get("app.twake_doctrine")->flush();
return $work;
}
public function newChannel($group, $workspace, $user)
{
$channel = new Channel();
$channel->setDirect(false);
$channel->setOriginalWorkspaceId($workspace->getId());
$channel->setOriginalGroupId($group->getId());
$this->getDoctrine()->persist($channel);
$this->getDoctrine()->flush();
$linkUserChannel = new ChannelMember($user->getId() . "", $channel);
$this->getDoctrine()->persist($linkUserChannel);
$this->getDoctrine()->flush();
return $channel;
}
public function newSubscription($group, $pricing_plan, $balanceInit, $start_date, $end_date, $autowithdraw, $autorenew)
{
$sub = $this->get("app.subscription_system")->create($group, $pricing_plan, $balanceInit, $start_date, $end_date, $autowithdraw, $autorenew);
return $sub;
}
public function login($username, $password = null)
{
if (!$password) {
$password = $username;
}
$result = $this->doPost("/ajax/users/login", Array(
"_username" => $username,
"_password" => $password
));
return $result;
}
public function logout()
{
$this->clearClient();
$this->doPost("/ajax/users/logout", Array());
}
}
+3
View File
@@ -0,0 +1,3 @@
<?php
include_once __DIR__ . '/../vendor/autoload.php';