本文整理汇总了PHP中sfGuardUser::getIncremented方法的典型用法代码示例。如果您正苦于以下问题:PHP sfGuardUser::getIncremented方法的具体用法?PHP sfGuardUser::getIncremented怎么用?PHP sfGuardUser::getIncremented使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfGuardUser
的用法示例。
在下文中一共展示了sfGuardUser::getIncremented方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}