コード例 #1
0
ファイル: UserTest.php プロジェクト: cobase/cobase
 /**
  * @test
  *
  * @group user-entity
  */
 public function likesPost()
 {
     $user = new User();
     $post = new Post();
     $post2 = new Post();
     $book = new Book();
     $like = new Like($post);
     $like2 = new Like($post2);
     $like3 = new Like($book);
     $user->addLike($like)->addLike($like2)->addLike($like3);
     $this->assertTrue($user->likesPost($post));
 }
コード例 #2
0
ファイル: Notification.php プロジェクト: cobase/cobase
 /**
  * @param User $user
  *
  * @return Notification
  */
 public function setUser(User $user)
 {
     if ($this->user !== $user) {
         $this->user = $user;
         $this->user->addNotification($this);
     }
     return $this;
 }
コード例 #3
0
ファイル: NotificationService.php プロジェクト: cobase/cobase
 /**
  * @param EmailTemplate $emailTemplate
  * @param User $userToNotify
  * @param array $data
  */
 protected function sendNotificationEmail(EmailTemplate $emailTemplate, User $userToNotify, array $data)
 {
     $message = Swift_Message::newInstance()->setSubject($emailTemplate->getSubject())->setFrom($this->appInfo->getSiteAdmin()->getAddress())->setTo($userToNotify->getEmail())->setBody($emailTemplate->renderPlainText($data));
     $this->mailer->send($message);
 }
コード例 #4
0
ファイル: UserFixtures.php プロジェクト: cobase/cobase
 public function load(\Doctrine\Common\Persistence\ObjectManager $manager)
 {
     $user1 = new User();
     $user1->setUsername('demo1');
     $user1->setUsernameCanonical('demo1');
     $user1->setPlainPassword('demo1');
     $user1->setName('Morgan Freeman');
     $user1->setGravatar('*****@*****.**');
     $user1->setEmail('*****@*****.**');
     $user1->setEmailCanonical('*****@*****.**');
     $user1->setEnabled(true);
     $user1->setLocked(false);
     $user1->setExpired(false);
     $user1->setCredentialsExpired(false);
     $user2 = new User();
     $user2->setUsername('demo2');
     $user2->setUsernameCanonical('demo2');
     $user2->setPlainPassword('demo2');
     $user2->setName('Ray Charles');
     $user2->setGravatar('*****@*****.**');
     $user2->setEmail('*****@*****.**');
     $user2->setEmailCanonical('*****@*****.**');
     $user2->setEnabled(true);
     $user2->setLocked(false);
     $user2->setExpired(false);
     $user2->setCredentialsExpired(false);
     $user3 = new User();
     $user3->setUsername('demo3');
     $user3->setUsernameCanonical('demo3');
     $user3->setPlainPassword('demo3');
     $user3->setName('Dave Gahan');
     $user3->setGravatar('*****@*****.**');
     $user3->setEmail('*****@*****.**');
     $user3->setEmailCanonical('*****@*****.**');
     $user3->setEnabled(true);
     $user3->setLocked(false);
     $user3->setExpired(false);
     $user3->setCredentialsExpired(false);
     $manager->persist($user1);
     $manager->persist($user2);
     $manager->persist($user3);
     $manager->flush();
     $this->addReference('user-1', $user1);
     $this->addReference('user-2', $user2);
     $this->addReference('user-3', $user3);
 }
コード例 #5
0
ファイル: PostService.php プロジェクト: cobase/cobase
 /**
  * @param Post $post
  * @param User $user
  * @throws \Exception
  */
 public function unlikePost(Post $post, User $user)
 {
     if (!$user->likesPost($post)) {
         throw new Exception("You don't like this post");
     }
     $like = $this->likeService->getPostSpecificLikeByUser($post, $user);
     if (null === $like) {
         throw new ResourceNotFoundException('No like found for this post');
     }
     $this->em->getConnection()->beginTransaction();
     $this->em->remove($like);
     $this->em->flush();
     $this->em->getConnection()->commit();
 }
コード例 #6
0
ファイル: PostTest.php プロジェクト: cobase/cobase
 /**
  * @test
  *
  * @group entity
  * @group post-entity
  */
 public function assertFeedTitleIsShortenedProperlyWhenLastCharIsSpace()
 {
     $user = new User();
     $user->setName("John");
     $post = new Post();
     $post->setUser($user);
     $post->setMaxFeedTitleLength(21);
     $post->setContent('The hyperactive horse walked into a saloon');
     $expectedTitle = 'The hyperactive horse... (John)';
     $this->assertEquals($expectedTitle, $post->getFeedItemTitle());
 }
コード例 #7
0
ファイル: Like.php プロジェクト: cobase/cobase
 /**
  * @param User $user
  *
  * @return Like
  */
 public function setUser(User $user)
 {
     if ($this->user !== $user) {
         $this->user = $user;
         $user->addLike($this);
     }
     return $this;
 }