public function testCreateAndGetGameCollectionById() { $user = UserTestHelper::createBasicUser('Steven'); $gameCollection = new GameCollection(); $gameCollection->person = $user; $gameCollection->type = 'Basketball'; $gameCollection->serializedData = serialize(array('something')); $this->assertTrue($gameCollection->save()); $id = $gameCollection->id; unset($gameCollection); $gameCollection = GameCollection::getById($id); $this->assertEquals('Basketball', $gameCollection->type); $this->assertEquals($user, $gameCollection->person); $this->assertEquals(array('something'), unserialize($gameCollection->serializedData)); }
public function actionRedeemCollection($id) { $gameCollection = GameCollection::getById((int) $id); if ($gameCollection->person->getClassId('Item') != Yii::app()->user->userModel->getClassId('Item')) { throw new NotSupportedException(); } if ($gameCollection->redeem()) { $gameCollectionRules = GameCollectionRulesFactory::createByType($gameCollection->type); $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel); $gameCoin->addValue($gameCollectionRules::getCoinRedemptionValue()); $saved = $gameCoin->save(); if (!$saved) { throw new FailedToSaveModelException(); } } echo UserGameDashboardView::renderCollectionContent(Yii::app()->user->userModel, $gameCollection); }
public function testRedeemCollection() { $user = UserTestHelper::createBasicUser('Steven'); $gameCollection = new GameCollection(); $gameCollection->person = $user; $gameCollection->type = 'Basketball'; $itemsData = array('RedemptionItem' => 0, 'Items' => array('Backboard' => 0, 'Player' => 0, 'ScoreBoard' => 0, 'Uniform' => 0, 'Trophy' => 0)); $gameCollection->serializedData = serialize($itemsData); $this->assertTrue($gameCollection->save()); $id = $gameCollection->id; unset($gameCollection); $gameCollection = GameCollection::getById($id); $this->assertEquals('Basketball', $gameCollection->type); $this->assertEquals($user, $gameCollection->person); $this->assertEquals($itemsData, unserialize($gameCollection->serializedData)); $this->setGetArray(array('id' => $gameCollection->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/redeemCollection'); $this->assertContains('Basketball Collection', $content); }