All Data Structures Functions Variables Pages
GamificationUtilTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  $super = SecurityTestHelper::createSuperAdmin();
43  $super->primaryEmail->emailAddress = 'super@zurmo.com';
44  $super->save();
45  }
46 
51  {
52  $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
53  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
54  $this->assertEquals(0, Notification::getCount());
56  //It should not send an email because it is non-allowed to send email notification
57  $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
58  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
59  $this->assertEquals(1, Notification::getCount());
60  }
61 
62  public function testFindGameTableRowsThatAreDuplicatedByTypePersonKey()
63  {
64  $this->assertEmpty(GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey('gamecollection'));
65  $this->assertEmpty(GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey('gamelevel'));
66  $this->assertEmpty(GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey('gamepoint'));
67  $this->assertEmpty(GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey('gamescore'));
68  }
69 
70  public function testFindGameTableRowsThatAreDuplicatedByPersonKey()
71  {
72  $this->assertEmpty(GamificationUtil::findGameTableRowsThatAreDuplicatedByPersonKey('gamecoin'));
73  }
74 
75  public function testRemoveDuplicatesByModelsNonGameCollection()
76  {
77  $super = User::getByUsername('super');
78  Yii::app()->user->userModel = $super;
79 
80  $models = array();
81  $gameCoin = new GameCoin();
82  $gameCoin->person = $super;
83  $gameCoin->value = 34;
84  $gameCoin->save();
85  $models[] = $gameCoin;
86  $gameCoin2 = new GameCoin();
87  $gameCoin2->person = $super;
88  $gameCoin2->value = 56;
89  $gameCoin2->save();
90  $models[] = $gameCoin2;
91  $messageContent = null;
92  $this->assertEquals(2, count(GameCoin::getAll()));
93  GamificationUtil::removeDuplicatesByModels($models, $messageContent);
94  $gameCoins = GameCoin::getAll();
95  $this->assertEquals(1, count($gameCoins));
96  //Ensure it deleted the smaller value (Bank error in your favor)
97  $this->assertEquals(56, $gameCoins[0]->value);
98  $this->assertNotNull($messageContent);
99  }
100 
101  public function testRemoveDuplicatesByModelsGameCollection()
102  {
103  $super = User::getByUsername('super');
104  Yii::app()->user->userModel = $super;
105 
106  $models = array();
107  $gameCollection = new GameCollection();
108  $gameCollection->person = $super;
109  $gameCollection->type = 'Basketball';
110  $gameCollection->serializedData = serialize(array('something'));
111  $gameCollection->save();
112  $models[] = $gameCollection;
113  $gameCollection2 = new GameCollection();
114  $gameCollection2->person = $super;
115  $gameCollection2->type = 'Basketball';
116  $gameCollection2->serializedData = serialize(array('something2'));
117  $gameCollection2->save();
118  $models[] = $gameCollection2;
119  $messageContent = null;
120  $this->assertEquals(2, count(GameCollection::getAll()));
121  GamificationUtil::removeDuplicatesByModels($models, $messageContent);
122  $gameCollections = GameCollection::getAll();
123  $this->assertEquals(1, count($gameCollections));
124  $this->assertNotNull($messageContent);
125  }
126  }
127 ?>
static getByUsername($username)
Definition: User.php:49
static logAndNotifyOnDuplicateGameModel($logContent)
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Fri Jun 5 2020 07:10:31