protected static function makeModalGameNotificationContainerView() { return new ModalGameNotificationContainerView(GameNotification::getAllByUser(Yii::app()->user->userModel)); }
/** * Tests the global configuration to enable/disable modalNotifications */ public function testGamificationModalNotificationsGlobalConfiguration() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $scot = UserTestHelper::createBasicUser('Scot'); Yii::app()->user->userModel = $scot; $this->assertEquals(0, count(GameNotification::getAllByUser($scot))); //test user at general level 0 where they do have enough points to move up (Game notification created) $gamePoint = new GamePoint(); $gamePoint->type = GamePoint::TYPE_USER_ADOPTION; $gamePoint->person = $scot; $gamePoint->value = 300; $this->assertTrue($gamePoint->save()); Yii::app()->gameHelper->resolveLevelChange(); $this->assertEquals(1, count(GameNotification::getAllByUser($scot))); $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, $scot); $this->assertEquals(300, $gamePoint->value); $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, $scot); $this->assertTrue($gameLevel->id > 0); $this->assertEquals(1, $gameLevel->value); //test user at general level 1 where they do have enough points to move up (No game notification created) ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'gamificationModalNotificationsEnabled', false); $gamePoint = new GamePoint(); $gamePoint->type = GamePoint::TYPE_USER_ADOPTION; $gamePoint->person = $scot; $gamePoint->value = 300; $this->assertTrue($gamePoint->save()); Yii::app()->gameHelper->resolveLevelChange(); $this->assertEquals(1, count(GameNotification::getAllByUser($scot))); $this->assertEquals(300, $gamePoint->value); $this->assertTrue($gameLevel->id > 0); $this->assertEquals(2, $gameLevel->value); //test user at general level 2 where they do have enough points to move up (Game notification created) ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'gamificationModalNotificationsEnabled', true); $gamePoint = new GamePoint(); $gamePoint->type = GamePoint::TYPE_USER_ADOPTION; $gamePoint->person = $scot; $gamePoint->value = 500; $this->assertTrue($gamePoint->save()); Yii::app()->gameHelper->resolveLevelChange(); $this->assertEquals(2, count(GameNotification::getAllByUser($scot))); $this->assertEquals(500, $gamePoint->value); $this->assertTrue($gameLevel->id > 0); $this->assertEquals(3, $gameLevel->value); }
public function testGameNotificationsComingUpCorrectly() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->assertEquals(0, count(GameNotification::getAll())); $this->assertEquals(0, count(GameNotification::getAllByUser($super))); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertTrue(strpos($content, 'ModalGameNotification0') === false); //Level up notification $gameNotification = new GameNotification(); $gameNotification->user = $super; $gameNotification->setLevelChangeByNextLevelValue(2); $saved = $gameNotification->save(); $this->assertTrue($saved); $this->assertEquals(1, count(GameNotification::getAll())); $this->assertEquals(1, count(GameNotification::getAllByUser($super))); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertFalse(strpos($content, 'ModalGameNotification0') === false); $this->assertTrue(strpos($content, 'ModalGameNotification1') === false); $this->assertEquals(0, count(GameNotification::getAll())); $this->assertEquals(0, count(GameNotification::getAllByUser($super))); Yii::app()->clientScript->reset(); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertTrue(strpos($content, 'ModalGameNotification0') === false); //New badge notification $gameNotification = new GameNotification(); $gameNotification->user = $super; $gameNotification->setNewBadgeByType('LoginUser'); $saved = $gameNotification->save(); $this->assertTrue($saved); //Badge grade up notification $gameNotification = new GameNotification(); $gameNotification->user = $super; $gameNotification->setBadgeGradeChangeByTypeAndNewGrade('LoginUser', 5); $saved = $gameNotification->save(); $this->assertTrue($saved); Yii::app()->clientScript->reset(); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertFalse(strpos($content, 'ModalGameNotification0') === false); $this->assertFalse(strpos($content, 'ModalGameNotification1') === false); }
/** * @depends testGetAllByUser */ public function testGameNotificationToModalContentAdapter() { Yii::app()->user->userModel = User::getByUsername('steven'); $notifications = GameNotification::getAllByUser(Yii::app()->user->userModel); $this->assertEquals(3, count($notifications)); $adapter1 = new GameNotificationToModalContentAdapter($notifications[0]); $adapter2 = new GameNotificationToModalContentAdapter($notifications[1]); $adapter3 = new GameNotificationToModalContentAdapter($notifications[2]); $this->assertEquals('game-level-change', $adapter1->getIconCssName()); $this->assertEquals('game-badge-LoginUser', $adapter2->getIconCssName()); $this->assertEquals('game-badge-LoginUser', $adapter3->getIconCssName()); $this->assertEquals('<h2>Congratulations!</h2><h3>You have reached level 2</h3><h3> You have received 5 coins</h3>', $adapter1->getMessageContent()); $this->assertEquals('<h2>New Badge</h2><h3>1 Zurmo login</h3>', $adapter2->getMessageContent()); $this->assertEquals('<h2>New Badge</h2><h3>75 Zurmo logins</h3>', $adapter3->getMessageContent()); }