本文整理汇总了PHP中sfGuardUser::setIsValidated方法的典型用法代码示例。如果您正苦于以下问题:PHP sfGuardUser::setIsValidated方法的具体用法?PHP sfGuardUser::setIsValidated怎么用?PHP sfGuardUser::setIsValidated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfGuardUser
的用法示例。
在下文中一共展示了sfGuardUser::setIsValidated方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSavingBlockedUser
/**
* Tests saving a sfGuardUserSubredditMembership that identifies a User as
* "blocked" for a particular Subreddit. When this occurs, all existing
* future EpisodeAssignments should be deleted because blocked users cannot
* participate with the Subreddit.
*/
public function testSavingBlockedUser()
{
// Establish fake Subreddit
$subreddit = new Subreddit();
$subreddit->setName(rand(0, 1000));
$subreddit->setDomain(rand(0, 1000));
$subreddit->save();
// Establish User
$user = new sfGuardUser();
$user->setEmailAddress(rand(0, 100000));
$user->setUsername(rand(0, 10000));
$user->setIsValidated(1);
$user->save();
$user_id = $user->getIncremented();
$this->assertNotEquals(0, $user_id);
// Establish Episode for Subreddit
$episode = new Episode();
$episode->setSubreddit($subreddit);
$episode->setReleaseDate(date('Y-m-d H:i:s', time() + 34000));
$episode->save();
$author_type = AuthorTypeTable::getInstance()->findOneBy('type', 'squid');
$deadline = new Deadline();
$deadline->setSubreddit($subreddit);
$deadline->setAuthorType($author_type);
$deadline->setSeconds(0);
$deadline->save();
$episode_assignment = new EpisodeAssignment();
$episode_assignment->setSfGuardUser($user);
$episode_assignment->setEpisode($episode);
$episode_assignment->setAuthorType($author_type);
$episode_assignment->save();
$number_of_episodes = EpisodeAssignmentTable::getInstance()->createQuery()->select('COUNT(EpisodeAssignment.id)')->leftJoin('Episode')->where('subreddit_id = ?', $subreddit->getIncremented())->andWhere('EpisodeAssignment.sf_guard_user_id = ?', $user_id)->andWhere('Episode.release_date > NOW()')->groupBy('EpisodeAssignment.id')->count();
$this->assertEquals(1, $number_of_episodes);
// Establish User Membership as Blocked
$blocked = MembershipTable::getInstance()->findOneBy('type', 'blocked');
$user_membership = new sfGuardUserSubredditMembership();
$user_membership->setSubreddit($subreddit);
$user_membership->setSfGuardUser($user);
$user_membership->setMembership($blocked);
// Save Membership
$user_membership->save();
// Asert that User has zero Episodes
$number_of_episodes = EpisodeAssignmentTable::getInstance()->createQuery()->select('COUNT(EpisodeAssignment.id)')->leftJoin('Episode')->where('subreddit_id = ?', $subreddit->getIncremented())->andWhere('EpisodeAssignment.sf_guard_user_id = ?', $user_id)->andWhere('Episode.release_date > NOW()')->groupBy('EpisodeAssignment.id');
$sql = $number_of_episodes->getSqlQuery();
$number_of_episodes = $number_of_episodes->count();
$this->assertTrue(0 == $number_of_episodes, $sql . "\n" . $subreddit->getIncremented() . "\n" . $user_id);
// Remove User Membership
$user_membership->delete();
// Delete User
$user->delete();
// Delete Episode
$episode->delete();
// Delete Deadline
$deadline->delete();
// Delete Subreddit
$subreddit->delete();
}
示例2: testDeleteBySubredditIdAndUserId
/**
* This tests whether the
* EpisodeAssignmentTable::deleteBySubredditIdAndUserId() function deletes
* all future (and only future) EpisodeAssignments in a Subreddit attached
* to a particular User.
*/
public function testDeleteBySubredditIdAndUserId()
{
// Create two episode assignments: one for a past Episode, one for a future
$subreddit = new Subreddit();
$subreddit->setName(rand(0, 10000));
$subreddit->setDomain(rand(0, 10000));
$subreddit->save();
$user = new sfGuardUser();
$user->setUsername(rand(0, 10000));
$user->setEmailAddress(rand(0, 10000));
$user->setIsValidated(true);
$user->save();
$first = AuthorTypeTable::getInstance()->findOneBy('type', 'squid');
$this->assertTrue($first instanceof AuthorType);
$this->assertNotEquals(null, $first->getIncremented());
$deadline = new Deadline();
$deadline->setSeconds(0);
$deadline->setAuthorType($first);
$deadline->setSubreddit($subreddit);
$deadline->save();
$future_episode = new Episode();
$future_episode->setReleaseDate(date('Y-m-d H:i:s', time() + 100000));
$future_episode->setSubreddit($subreddit);
$future_episode->save();
$future_assignment = new EpisodeAssignment();
$future_assignment->setEpisode($future_episode);
$future_assignment->setSfGuardUser($user);
$future_assignment->setAuthorType($first);
$future_assignment->save();
/* Now we run the EpisodeAssignmentTable::deleteBySubredditIdAndUserId()
* function, which should leave both past assignments intact but should
* remove the future assignment.
*/
EpisodeAssignmentTable::getInstance()->deleteBySubredditIdAndUserId($subreddit->getIncremented(), $user->getIncremented());
$test_future = EpisodeAssignmentTable::getInstance()->find($future_assignment->getIncremented());
$this->assertFalse($test_future instanceof EpisodeAssignment, 'future ' . $future_assignment->getIncremented());
// Cleanup
if ($future_assignment) {
$future_assignment->delete();
}
$future_episode->delete();
$deadline->delete();
$user->delete();
$subreddit->delete();
}
示例3: testGetFirstByUserSubredditAndMemberships
/**
* Since a User can only have one membership in a Subreddit, this tests that
* the first returned sfGuardUserSubredditMembership is the exact same as
* the only one made. The limitation on sfGuardUserSubredditMemberships is
* in place using Unique indexes in the database, so we depend upon that to
* prevent multiple Subreddit Memberships.
*/
public function testGetFirstByUserSubredditAndMemberships()
{
$user = new sfGuardUser();
$user->setEmailAddress(rand(0, 1000));
$user->setUsername(rand(0, 1000));
$user->setIsValidated(1);
$user->save();
$subreddit = new Subreddit();
$subreddit->setName(rand(0, 1000));
$subreddit->setDomain(rand(0, 1000));
$subreddit->save();
$membership = MembershipTable::getInstance()->findOneByType('user');
$second_membership = MembershipTable::getInstance()->findOneByType('admin');
$user_subreddit_membership = new sfGuardUserSubredditMembership();
$user_subreddit_membership->setSfGuardUserId($user->getIncremented());
$user_subreddit_membership->setSubredditId($subreddit->getIncremented());
$user_subreddit_membership->setMembership($membership);
$user_subreddit_membership->save();
$second_user_subreddit_membership = new sfGuardUserSubredditMembership();
$second_user_subreddit_membership->setSfGuardUserId($user->getIncremented());
$second_user_subreddit_membership->setSubredditId($subreddit->getIncremented());
$second_user_subreddit_membership->setMembership($second_membership);
$exception_thrown = false;
try {
$second_user_subreddit_membership->save();
} catch (Exception $exception) {
unset($exception);
$exception_thrown = true;
}
$retrieved_object = sfGuardUserSubredditMembershipTable::getInstance()->getFirstByUserSubredditAndMemberships($user->getIncremented(), $subreddit->getIncremented(), array($membership->getType()));
$this->assertEquals($retrieved_object->getIncremented(), $user_subreddit_membership->getIncremented());
$user_subreddit_membership->delete();
$subreddit->delete();
$user->delete();
$this->assertTrue($exception_thrown);
}
示例4: testdeleteWithException
/**
* We've combined the process for preventing saving with a specific call for
* deletion to aid in handling errors and dealing with unsaved objects.
* This tests whether the exception is thrown
*/
public function testdeleteWithException()
{
$subreddit = new Subreddit();
$subreddit->setName(rand(0, 10000));
$subreddit->setDomain(rand(0, 10000));
$subreddit->save();
$user = new sfGuardUser();
$user->setUsername(rand(0, 10000));
$user->setEmailAddress(rand(0, 10000));
$user->setIsValidated(1);
$user->save();
$first = AuthorTypeTable::getInstance()->findOneByType('squid');
$episode = new Episode();
$episode->setReleaseDate(date('Y-m-d H:i:s', time() + 100000));
$episode->setSubreddit($subreddit);
$episode->save();
$deadline = new Deadline();
$deadline->setSubreddit($subreddit);
$deadline->setAuthorType($first);
$deadline->setSeconds(0);
$deadline->save();
$assignment = new EpisodeAssignment();
$assignment->setSfGuardUser($user);
$assignment->setEpisode($episode);
$assignment->setAuthorType($first);
$assignment->save();
// Delete with exception
$exception_thrown = false;
$exception_code = 987654321;
try {
$assignment->deleteWithException("Test exception", $exception_code);
} catch (sfException $exception) {
$this->assertEquals($exception_code, $exception->getCode());
unset($exception);
$exception_thrown = true;
}
$this->assertTrue($exception_thrown);
// Delete the rest of the objects
$episode->delete();
$user->delete();
$subreddit->delete();
}