public function testGetCountByUser() { Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals(0, Notification::getCountByUser(Yii::app()->user->userModel)); $notification = new Notification(); $notification->type = 'Simple'; $notification->owner = Yii::app()->user->userModel; $this->assertTrue($notification->save()); $this->assertEquals(1, Notification::getCountByUser(Yii::app()->user->userModel)); $this->assertTrue($notification->save()); $notificationId = $notification->id; $notification->forget(); //Retrieve again. $notification = Notification::getById($notificationId); $this->assertEquals('Simple', $notification->type); $this->assertEquals(1, Notification::getCountByUser(Yii::app()->user->userModel)); $notification->delete(); $this->assertEquals(0, Notification::getCountByUser(Yii::app()->user->userModel)); }
/** * Test mission notifications * @depends testCreateAndGetMissionById */ public function testMissionNotifications() { $super = User::getByUsername('super'); $steven = User::getByUsername('steven'); $this->assertEquals(0, Notification::getCountByUser($super)); $this->assertEquals(0, Notification::getCountByUser($steven)); $missions = Mission::getAll(); $mission = $missions[0]; $mission->status = Mission::STATUS_TAKEN; $this->assertTrue($mission->save()); $this->assertEquals(1, Notification::getCountByUser($super)); $this->assertEquals(0, Notification::getCountByUser($steven)); $mission->status = Mission::STATUS_COMPLETED; $this->assertTrue($mission->save()); $this->assertEquals(2, Notification::getCountByUser($super)); $this->assertEquals(0, Notification::getCountByUser($steven)); $mission->status = Mission::STATUS_REJECTED; $this->assertTrue($mission->save()); $this->assertEquals(2, Notification::getCountByUser($super)); $this->assertEquals(1, Notification::getCountByUser($steven)); $mission->status = Mission::STATUS_ACCEPTED; $this->assertTrue($mission->save()); $this->assertEquals(2, Notification::getCountByUser($super)); $this->assertEquals(2, Notification::getCountByUser($steven)); }
/** * Test mission notifications * @depends testCreateAndGetMissionById */ public function testMissionNotifications() { $super = User::getByUsername('super'); $super->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($super->save()); $steven = User::getByUsername('steven'); //A new mission notification was already created for steven $this->assertEquals(0, Notification::getCountByUser($super)); $this->assertEquals(1, Notification::getCountByUser($steven)); $this->assertEquals(1, EmailMessage::getCount()); $missions = Mission::getAll(); $mission = $missions[0]; $mission->status = Mission::STATUS_TAKEN; $this->assertTrue($mission->save()); $this->assertEquals(1, Notification::getCountByUser($super)); $this->assertEquals(1, Notification::getCountByUser($steven)); $this->assertEquals(2, EmailMessage::getCount()); $mission->status = Mission::STATUS_COMPLETED; $this->assertTrue($mission->save()); $this->assertEquals(2, Notification::getCountByUser($super)); $this->assertEquals(1, Notification::getCountByUser($steven)); $this->assertEquals(3, EmailMessage::getCount()); $mission->status = Mission::STATUS_REJECTED; $this->assertTrue($mission->save()); $this->assertEquals(2, Notification::getCountByUser($super)); $this->assertEquals(2, Notification::getCountByUser($steven)); $this->assertEquals(4, EmailMessage::getCount()); $mission->status = Mission::STATUS_ACCEPTED; $this->assertTrue($mission->save()); $this->assertEquals(2, Notification::getCountByUser($super)); $this->assertEquals(3, Notification::getCountByUser($steven)); $this->assertEquals(5, EmailMessage::getCount()); }