public function testCreateAndGetGameCoinById() { $user = UserTestHelper::createBasicUser('Steven'); $gameCoin = new GameCoin(); $gameCoin->person = $user; $gameCoin->value = 10; $this->assertTrue($gameCoin->save()); $id = $gameCoin->id; unset($gameCoin); $gameCoin = GameCoin::getById($id); $this->assertEquals(10, $gameCoin->value); $this->assertEquals($user, $gameCoin->person); $gameCoin->addValue(10); $this->assertEquals(20, $gameCoin->value); $this->assertEquals('20 coins', strval($gameCoin)); }
public function testRemoveDuplicatesByModelsNonGameCollection() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $models = array(); $gameCoin = new GameCoin(); $gameCoin->person = $super; $gameCoin->value = 34; $gameCoin->save(); $models[] = $gameCoin; $gameCoin2 = new GameCoin(); $gameCoin2->person = $super; $gameCoin2->value = 56; $gameCoin2->save(); $models[] = $gameCoin2; $messageContent = null; $this->assertEquals(2, count(GameCoin::getAll())); GamificationUtil::removeDuplicatesByModels($models, $messageContent); $gameCoins = GameCoin::getAll(); $this->assertEquals(1, count($gameCoins)); //Ensure it deleted the smaller value (Bank error in your favor) $this->assertEquals(56, $gameCoins[0]->value); $this->assertNotNull($messageContent); }
public function testRedeemReward() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $super->primaryEmail->emailAddress = '*****@*****.**'; $super->save(); Yii::app()->user->userModel = $super; $gameRewards = GameReward::getByName('myNewGameReward'); //not enough coins $this->setGetArray(array('id' => $gameRewards[0]->id)); $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward'); $this->assertContains('You do not have enough coins to redeem this reward', $content); //enough coins $gameCoin = new GameCoin(); $gameCoin->person = $super; $gameCoin->value = 100; $this->assertTrue($gameCoin->save()); $notifications = Notification::getAll(); //check for no notification $this->assertEquals(0, EmailMessage::getCount()); $this->assertEquals(0, count($notifications)); $this->setGetArray(array('id' => $gameRewards[0]->id)); $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward'); $this->assertContains('myNewGameReward has been redeemed.', $content); //check for notification $notifications = Notification::getAll(); $this->assertEquals(1, count($notifications)); //email content $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $notifications[0]->notificationMessage->htmlContent); //check url $this->assertContains('/gameRewards/default/details?id=13', $notifications[0]->notificationMessage->htmlContent); // Not Coding Standard //check for email notification $emailMessages = EmailMessage::getAll(); $this->assertCount(1, $emailMessages); $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->htmlContent); $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->textContent); }