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); }
/** * @depends testCreateAndGetGameRewardById */ public function testUpdateGameRewardFromForm() { $gameRewards = GameReward::getByName('50 dollar giftcard to somewhere'); $gameReward = $gameRewards[0]; $this->assertEquals($gameReward->name, '50 dollar giftcard to somewhere'); $postData = array('name' => 'New Name'); $gameReward->setAttributes($postData); $this->assertTrue($gameReward->save()); $id = $gameReward->id; unset($gameReward); $gameReward = GameReward::getById($id); $this->assertEquals('New Name', $gameReward->name); }