Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelsCacheTest.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 getDependentTestModelClassNames()
40  {
41  return array('A');
42  }
43 
44  public function testCaching()
45  {
46  $a = new A();
47  $a->a = 1;
48  $a->uniqueRequiredEmail = 'a@zurmoinc.com';
49  $this->assertTrue($a->save());
50  $originalAHash = spl_object_hash($a);
51 
52  $id = $a->id;
53  $modelIdentifier = $a->getModelIdentifier();
54  unset($a);
55 
56  $a = A::getById($id);
57  $fromPhpAHash = spl_object_hash($a);
58  unset($a);
59 
60  $modelFromCache = RedBeanModelsCache::getModel($modelIdentifier);
61  $this->assertEquals(1, $modelFromCache->a);
62  $this->assertEquals('a@zurmoinc.com', $modelFromCache->uniqueRequiredEmail);
63 
65  $a = A::getById($id);
66  $this->assertEquals(1, $a->a);
67  $this->assertEquals('a@zurmoinc.com', $a->uniqueRequiredEmail);
68  $fromMemcacheAHash = spl_object_hash($a);
69 
70  $this->assertEquals ($fromPhpAHash, $originalAHash);
71  $this->assertNotEquals($fromMemcacheAHash, $originalAHash);
72  }
73 
74  public function testForgetModel()
75  {
76  $a = new A();
77  $a->a = 1;
78  $a->uniqueRequiredEmail = 'a2@zurmoinc.com';
79  $this->assertTrue($a->save());
80  $modelIdentifier = $a->getModelIdentifier();
81 
82  $modelFromCache = RedBeanModelsCache::getModel($modelIdentifier);
83  $this->assertEquals(1, $modelFromCache->a);
84  $this->assertEquals('a2@zurmoinc.com', $modelFromCache->uniqueRequiredEmail);
85 
87  try
88  {
89  RedBeanModelsCache::getModel($modelIdentifier);
90  $this->fail('NotFoundException exception is not thrown.');
91  }
92  catch (NotFoundException $e)
93  {
94  $this->assertTrue(true);
95  }
96  }
97 
98  public function testForgetAll()
99  {
100  $a = new A();
101  $a->a = 1;
102  $a->uniqueRequiredEmail = 'a3@zurmoinc.com';
103  $this->assertTrue($a->save());
104  $modelIdentifier = $a->getModelIdentifier();
105 
106  $modelFromCache = RedBeanModelsCache::getModel($modelIdentifier);
107  $this->assertEquals(1, $modelFromCache->a);
108  $this->assertEquals('a3@zurmoinc.com', $modelFromCache->uniqueRequiredEmail);
109 
110  // Set some GeneralCache, which should stay in cache after cleanup
111  GeneralCache::cacheEntry('somethingForTesting', 34);
112  $value = GeneralCache::getEntry('somethingForTesting');
113  $this->assertEquals(34, $value);
114 
116  try
117  {
118  RedBeanModelsCache::getModel($modelIdentifier);
119  $this->fail('NotFoundException exception is not thrown.');
120  }
121  catch (NotFoundException $e)
122  {
123  // Data from generalCache should still be in cache
124  $value = GeneralCache::getEntry('somethingForTesting');
125  $this->assertEquals(34, $value);
126  }
127  }
128 
129  public function testFileContentModelNotBeingCached()
130  {
131  $fileContent = new FileContent();
132  $fileContent->content = str_repeat('a', 1000);
133  $this->assertTrue($fileContent->save());
134  $modelIdentifier = $fileContent->getModelIdentifier();
135  RedBeanModelsCache::cacheModel($fileContent);
136  try
137  {
138  RedBeanModelsCache::getModel($modelIdentifier);
139  }
140  catch (NotFoundException $e)
141  {
142  $this->fail('NotFoundException exception is thrown.');
143  }
144  $prefix = RedBeanModelsCache::getCachePrefix($modelIdentifier, RedBeanModelsCache::$cacheType);
145  $cachedData = false;
146  if (isset(Yii::app()->cache))
147  {
148  $cachedData = Yii::app()->cache->get($prefix . $modelIdentifier);
149  }
150  $this->assertFalse($cachedData);
151  }
152  }
153 ?>
static forgetModel(RedBeanModel $model)
static getModel($modelIdentifier)
static forgetAll($onlyForgetPhpCache=false)
static cacheModel(RedBeanModel $model)
Definition: A.php:37
static getById($id, $modelClassName=null)
static getCachePrefix($identifier)
Definition: ZurmoCache.php:68
Generated on Tue Jul 7 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.