Ejemplo n.º 1
0
 public function test_noleaderFindByGroupId()
 {
     $this->db->query("INSERT INTO usvn_users (users_id, users_login, users_password, users_is_admin) VALUES (1,'noplay', 'xxx', 0);");
     $this->db->query("INSERT INTO usvn_users (users_id, users_login, users_password, users_is_admin) VALUES (2,'stem', 'xxx', 0);");
     $this->db->query("INSERT INTO usvn_users (users_id, users_login, users_password, users_is_admin) VALUES (3,'eozine', 'xxx', 0);");
     $this->db->query("INSERT INTO usvn_groups (groups_id, groups_name) VALUES (1,'epitech');");
     $this->db->query("INSERT INTO usvn_groups (groups_id, groups_name) VALUES (2,'etna');");
     $table = new USVN_Db_Table_UsersToGroups();
     $table->insert(array('users_id' => 1, 'groups_id' => 1, 'is_leader' => false));
     $table->insert(array('users_id' => 2, 'groups_id' => 1, 'is_leader' => ''));
     $table->insert(array('users_id' => 2, 'groups_id' => 2, 'is_leader' => true));
     $table->insert(array('users_id' => 3, 'groups_id' => 1, 'is_leader' => true));
     $this->assertEquals(2, count($table->noleaderFindByGroupId(1)));
 }
Ejemplo n.º 2
0
 /**
  * Add an user to a group
  *
  * @param mixed User
  * @param boolean leader
  */
 public function addUser($user, $leader = false)
 {
     if (is_object($user)) {
         $user_id = $user->id;
     } elseif (is_numeric($user)) {
         $user_id = intval($user);
     }
     if ($this->id && $user_id) {
         $user_groups = new USVN_Db_Table_UsersToGroups();
         $user_groups->insert(array("groups_id" => $this->id, "users_id" => $user_id, "is_leader" => $leader === true ? 1 : 0));
     }
 }
Ejemplo n.º 3
0
 public function testFindUserInGroup()
 {
     $test = $this->createUser("test");
     $babar = $this->createUser("babar");
     $john = $this->createUser("john");
     $group = $this->createGroup("toto");
     $user_groups = new USVN_Db_Table_UsersToGroups();
     $user_groups->insert(array("groups_id" => $group->id, "users_id" => $test->id, "is_leader" => false));
     $user_groups->insert(array("groups_id" => $group->id, "users_id" => $babar->id, "is_leader" => false));
     $group_table = new USVN_Db_Table_Groups();
     $group = $group_table->find($test->id)->current();
     $users = $group->findManyToManyRowset('USVN_Db_Table_Users', 'USVN_Db_Table_UsersToGroups');
     $res = array();
     foreach ($users as $user) {
         array_push($res, $user->users_login);
     }
     $this->assertContains("test", $res);
     $this->assertContains("babar", $res);
     $this->assertNotContains("john", $res);
 }
Ejemplo n.º 4
0
 public function testUserIsGroupLeader()
 {
     $user2 = $this->users["test"];
     $user3 = $this->users["babar"];
     $user4 = $this->users["john"];
     $user_groups = new USVN_Db_Table_UsersToGroups();
     $user_groups->insert(array("groups_id" => $this->group1->id, "users_id" => $user3->id, "is_leader" => 0));
     $user_groups->insert(array("groups_id" => $this->group1->id, "users_id" => $user4->id, "is_leader" => 1));
     $this->assertFalse($this->group1->userIsGroupLeader($user2));
     $this->assertFalse($this->group1->userIsGroupLeader($user3));
     $this->assertTrue($this->group1->userIsGroupLeader($user4));
 }