/** * Basic create group test */ public function testCreateGroup() { $owner = UserFactory::createUser(); $name = Utils::CreateRandomString(); $description = Utils::CreateRandomString(); $alias = Utils::CreateRandomString(); $response = GroupController::apiCreate(new Request(array('auth_token' => self::login($owner), 'name' => $name, 'alias' => $alias, 'description' => $description))); $this->assertEquals('ok', $response['status']); $groups = GroupsDAO::search(new Groups(array('name' => $name))); $group = $groups[0]; $this->assertNotNull($group); $this->assertEquals($description, $group->getDescription()); $this->assertEquals($owner->getUserId(), $group->getOwnerId()); }
/** * Create group * * @param type $owner * @param type $name * @param type $description */ public static function createGroup($owner = null, $name = null, $description = null, $alias = null) { if (is_null($owner)) { $owner = UserFactory::createUser(); } if (is_null($name)) { $name = Utils::CreateRandomString(); } if (is_null($description)) { $description = Utils::CreateRandomString(); } if (is_null($alias)) { $alias = Utils::CreateRandomString(); } $r = new Request(array("auth_token" => OmegaupTestCase::login($owner), "name" => $name, "description" => $description, "alias" => $alias)); $response = GroupController::apiCreate($r); $groups = GroupsDAO::search(new Groups(array("alias" => $alias))); return array("request" => $r, "response" => $response, "owner" => $owner, "group" => $groups[0]); }
/** * Returns a list of groups by owner * * @param Request $r */ public static function apiList(Request $r) { self::authenticateRequest($r); $response = array(); $response["groups"] = array(); try { $groups = GroupsDAO::search(new Groups(array("owner_id" => $r["current_user_id"]))); foreach ($groups as $group) { $response["groups"][] = $group->asArray(); } } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $response["status"] = "ok"; return $response; }
/** * Returns a list of groups by owner * * @param Request $r */ public static function apiMyList(Request $r) { self::authenticateRequest($r); $response = array(); $response['groups'] = array(); try { $groups = GroupsDAO::search(new Groups(array('owner_id' => $r['current_user_id']))); foreach ($groups as $group) { $response['groups'][] = $group->asArray(); } } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $response['status'] = 'ok'; return $response; }