本文整理汇总了PHP中Utils::CreateRandomString方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::CreateRandomString方法的具体用法?PHP Utils::CreateRandomString怎么用?PHP Utils::CreateRandomString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils
的用法示例。
在下文中一共展示了Utils::CreateRandomString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequest
/**
* Returns a Request object with valid info to create a problem and the
* author of the problem
*
* @param string $title
* @param string $zipName
* @return Array
*/
public static function getRequest($zipName = null, $title = null, $public = 1, Users $author = null, $languages = null)
{
if (is_null($author)) {
$author = UserFactory::createUser();
}
if (is_null($title)) {
$title = Utils::CreateRandomString();
}
if (is_null($zipName)) {
$zipName = OMEGAUP_RESOURCES_ROOT . 'testproblem.zip';
}
$r = new Request();
$r["title"] = $title;
$r['alias'] = substr(preg_replace('/[^a-zA-Z0-9_-]/', '', str_replace(' ', '-', $r['title'])), 0, 32);
$r["author_username"] = $author->getUsername();
$r["validator"] = "token";
$r["time_limit"] = 5000;
$r["overall_wall_time_limit"] = 60000;
$r["validator_time_limit"] = 30000;
$r["extra_wall_time"] = 0;
$r["memory_limit"] = 32000;
$r["source"] = "yo";
$r["order"] = "normal";
$r["public"] = $public;
$r["output_limit"] = 10240;
if ($languages == null) {
$r["languages"] = 'c,cpp,py';
} else {
$r["languages"] = $languages;
}
$r["stack_limit"] = 10000;
// Set file upload context
$_FILES['problem_contents']['tmp_name'] = $zipName;
return array("request" => $r, "author" => $author, "zip_path" => $zipName);
}
示例2: getRequest
/**
* Returns a Request object with complete context to create a contest
*
* @param string $title
* @param string $public
* @param Users $contestDirector
* @return Request
*/
public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null)
{
if (is_null($contestDirector)) {
$contestDirector = UserFactory::createUser();
}
if (is_null($title)) {
$title = Utils::CreateRandomString();
}
// Set context
$r = new Request();
$r["title"] = $title;
$r["description"] = "description";
$r["start_time"] = Utils::GetPhpUnixTimestamp() - 60 * 60;
$r["finish_time"] = Utils::GetPhpUnixTimestamp() + 60 * 60;
$r["window_length"] = null;
$r["public"] = $public;
$r["alias"] = substr($title, 0, 20);
$r["points_decay_factor"] = ".02";
$r["partial_score"] = "0";
$r["submissions_gap"] = "0";
$r["feedback"] = "yes";
$r["penalty"] = 100;
$r["scoreboard"] = 100;
$r["penalty_type"] = "contest_start";
$r["penalty_calc_policy"] = "sum";
$r['languages'] = $languages;
return array("request" => $r, "director" => $contestDirector);
}
示例3: testShouldRefuseNotRegisteredEmailAddresses
public function testShouldRefuseNotRegisteredEmailAddresses()
{
$this->setExpectedException('InvalidParameterException');
$email = Utils::CreateRandomString() . '@mail.com';
$r = new Request();
$response = ResetController::apiCreate($r);
}
示例4: testIsContestAdminCheck
public function testIsContestAdminCheck()
{
// Get a contest
$contestData = ContestsFactory::createContest();
// Get a user
$user = UserFactory::createUser();
// Prepare request
$r = new Request();
$r["auth_token"] = $this->login($contestData["director"]);
$r["usernameOrEmail"] = $user->getUsername();
$r["contest_alias"] = $contestData["request"]["alias"];
// Call api
ContestController::apiAddAdmin($r);
// Prepare request for an update
$r = new Request();
$r["contest_alias"] = $contestData["request"]["alias"];
// Log in with contest director
$r["auth_token"] = $this->login($user);
// Update title
$r["title"] = Utils::CreateRandomString();
// Call API
$response = ContestController::apiUpdate($r);
// To validate, we update the title to the original request and send
// the entire original request to assertContest. Any other parameter
// should not be modified by Update api
$contestData["request"]["title"] = $r["title"];
$this->assertContest($contestData["request"]);
}
示例5: testUserUpdate
/**
* Basic update test
*/
public function testUserUpdate()
{
// Create the user to edit
$user = UserFactory::createUser();
$r = new Request();
// Login
$r["auth_token"] = $this->login($user);
// Change values
$r["name"] = Utils::CreateRandomString();
$r["country_id"] = 'MX';
$r["state_id"] = 3;
$r["scholar_degree"] = 'Maestría';
$r["birth_date"] = strtotime('1988-01-01');
$r["graduation_date"] = strtotime('2016-02-02');
// Call api
$response = UserController::apiUpdate($r);
// Check user from db
$user_db = AuthTokensDAO::getUserByToken($r["auth_token"]);
$this->assertEquals($user_db->getName(), $r["name"]);
$this->assertEquals($user_db->getCountryId(), $r["country_id"]);
$this->assertEquals($user_db->getStateId(), $r["state_id"]);
$this->assertEquals($user_db->getScholarDegree(), $r["scholar_degree"]);
$this->assertEquals($user_db->getBirthDate(), gmdate('Y-m-d', $r["birth_date"]));
$this->assertEquals($user_db->getGraduationDate(), gmdate('Y-m-d', $r["graduation_date"]));
}
示例6: getRequest
/**
* Returns a Request object with complete context to create a contest
*
* @param string $title
* @param string $public
* @param Users $contestDirector
* @return Request
*/
public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null, $finish_time = null)
{
if (is_null($contestDirector)) {
$contestDirector = UserFactory::createUser();
}
if (is_null($title)) {
$title = Utils::CreateRandomString();
}
// Set context
$r = new Request();
$r['title'] = $title;
$r['description'] = 'description';
$r['start_time'] = Utils::GetPhpUnixTimestamp() - 60 * 60;
$r['finish_time'] = $finish_time == null ? Utils::GetPhpUnixTimestamp() + 60 * 60 : $finish_time;
$r['window_length'] = null;
$r['public'] = $public;
$r['alias'] = substr($title, 0, 20);
$r['points_decay_factor'] = '.02';
$r['partial_score'] = '0';
$r['submissions_gap'] = '0';
$r['feedback'] = 'yes';
$r['penalty'] = 100;
$r['scoreboard'] = 100;
$r['penalty_type'] = 'contest_start';
$r['penalty_calc_policy'] = 'sum';
$r['languages'] = $languages;
$r['recommended'] = 0;
// This is just a default value, it is not honored by apiCreate.
return array('request' => $r, 'director' => $contestDirector);
}
示例7: generateUser
/**
* Creates a native user in Omegaup and returns an array with the data used
* to create the user.
* @param $verify
* @return array
*/
public static function generateUser($verify = true)
{
$username = Utils::CreateRandomString();
$password = Utils::CreateRandomString();
$email = Utils::CreateRandomString() . "@mail.com";
self::createUser($username, $password, $email, $verify);
return array("username" => $username, "password" => $password, "email" => $email);
}
示例8: testNativeLoginByEmailInvalidPassword
/**
* Test user login with invalid credentials, email and password
*
* @expectedException InvalidCredentialsException
*/
public function testNativeLoginByEmailInvalidPassword()
{
// Create an user in omegaup
$email = Utils::CreateRandomString() . '@mail.com';
$user = UserFactory::createUser(null, null, $email);
// Inflate request with user data
$r = new Request(array('usernameOrEmail' => $email, 'password' => 'badpasswordD:'));
// Call the API
$response = UserController::apiLogin($r);
}
示例9: testBadUserUpdate
/**
* @expectedException InvalidDatabaseOperationException
*/
public function testBadUserUpdate()
{
$user = UserFactory::createUser();
$r = new Request();
$r['auth_token'] = $this->login($user);
$r['name'] = Utils::CreateRandomString();
// Invalid state_id
$r['state_id'] = -1;
UserController::apiUpdate($r);
}
示例10: testResetMyPasswordBadOldPassword
/**
* Reset my password
*
* @expectedException InvalidParameterException
*/
public function testResetMyPasswordBadOldPassword()
{
// Create an user in omegaup
$user = UserFactory::createUser();
$r = new Request();
$r["auth_token"] = $this->login($user);
$r["username"] = $user->getUsername();
$r["password"] = Utils::CreateRandomString();
$r["old_password"] = "bad old password";
// Call api
UserController::apiChangePassword($r);
}
示例11: testCreateSchoolDuplicatedName
/**
*
*/
public function testCreateSchoolDuplicatedName()
{
$user = UserFactory::createUser();
$r = new Request(array('auth_token' => $this->login($user), 'name' => Utils::CreateRandomString()));
// Call api
$response = SchoolController::apiCreate($r);
$this->assertEquals('ok', $response['status']);
$this->assertEquals(1, count(SchoolsDAO::findByName($r['name'])));
// Call api again
$response = SchoolController::apiCreate($r);
$this->assertEquals('ok', $response['status']);
$this->assertEquals(1, count(SchoolsDAO::findByName($r['name'])));
}
示例12: testUpdateContestNonDirector
/**
*
* @expectedException ForbiddenAccessException
*/
public function testUpdateContestNonDirector()
{
// Get a contest
$contestData = ContestsFactory::createContest();
// Prepare request
$r = new Request();
$r["contest_alias"] = $contestData["request"]["alias"];
// Log in with contest director
$r["auth_token"] = $this->login(UserFactory::createUser());
// Update title
$r["title"] = Utils::CreateRandomString();
// Call API
ContestController::apiUpdate($r);
}
示例13: createGroupScoreboard
/**
* Creates a scoreboard in a group
*
* @param array $groupData
* @param type $name
* @param type $description
* @param type $alias
*/
public static function createGroupScoreboard(array $groupData, $name = null, $description = null, $alias = null)
{
if (is_null($name)) {
$name = Utils::CreateRandomString();
}
if (is_null($description)) {
$description = Utils::CreateRandomString();
}
if (is_null($alias)) {
$alias = Utils::CreateRandomString();
}
$request = new Request(array('auth_token' => OmegaupTestCase::login($groupData['owner']), 'group_alias' => $groupData['group']->alias, 'name' => $name, 'alias' => $alias, 'description' => $description));
$response = GroupController::apiCreateScoreboard($request);
$scoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array('alias' => $alias)));
return array('request' => $request, 'response' => $response, 'scoreboard' => $scoreboards[0]);
}
示例14: createGroupScoreboard
/**
* Creates a scoreboard in a group
*
* @param array $groupData
* @param type $name
* @param type $description
* @param type $alias
*/
public static function createGroupScoreboard(array $groupData, $name = null, $description = null, $alias = null)
{
if (is_null($name)) {
$name = Utils::CreateRandomString();
}
if (is_null($description)) {
$description = Utils::CreateRandomString();
}
if (is_null($alias)) {
$alias = Utils::CreateRandomString();
}
$request = new Request(array("auth_token" => OmegaupTestCase::login($groupData["owner"]), "group_alias" => $groupData["group"]->alias, "name" => $name, "alias" => $alias, "description" => $description));
$response = GroupController::apiCreateScoreboard($request);
$scoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array("alias" => $alias)));
return array("request" => $request, "response" => $response, "scoreboard" => $scoreboards[0]);
}
示例15: createClarification
/**
* Creates a clarification in a problem inside a contest
*
* @param type $problemData
* @param type $contestData
* @param type $contestant
*/
public static function createClarification($problemData, $contestData, $contestant)
{
// Our contestant has to open the contest before sending a clarification
ContestsFactory::openContest($contestData, $contestant);
// Then we need to open the problem
ContestsFactory::openProblemInContest($contestData, $problemData, $contestant);
// Create the request for our api
$r = new Request();
$r["message"] = Utils::CreateRandomString();
$r["contest_alias"] = $contestData["request"]["alias"];
$r["problem_alias"] = $problemData["request"]["alias"];
$r["public"] = '0';
// Log in our user and set the auth_token properly
$r["auth_token"] = OmegaupTestCase::login($contestant);
// Call the API
$response = ClarificationController::apiCreate($r);
// Clean up stuff
unset($_REQUEST);
return array("request" => $r, "response" => $response);
}