Commit | Line | Data |
---|---|---|
808c05a9 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
808c05a9 | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
808c05a9 | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * Class CRM_Core_BAO_PrevNextCacheTest | |
14 | * @group headless | |
15 | */ | |
16 | class CRM_Core_BAO_PrevNextCacheTest extends CiviUnitTestCase { | |
17 | ||
18 | public function testFlipData() { | |
19 | $dao = new CRM_Core_BAO_PrevNextCache(); | |
20 | $dao->entity_id1 = 1; | |
21 | $dao->entity_id2 = 2; | |
9099cab3 | 22 | $dao->data = serialize([ |
808c05a9 | 23 | 'srcID' => 1, |
24 | 'srcName' => 'Ms. Meliissa Mouse II', | |
25 | 'dstID' => 2, | |
26 | 'dstName' => 'Mr. Maurice Mouse II', | |
27 | 'weight' => 20, | |
28 | 'canMerge' => TRUE, | |
9099cab3 | 29 | ]); |
808c05a9 | 30 | $dao->save(); |
31 | $dao = new CRM_Core_BAO_PrevNextCache(); | |
32 | $dao->id = 1; | |
9099cab3 | 33 | CRM_Core_BAO_PrevNextCache::flipPair([1], 0); |
808c05a9 | 34 | $dao->find(TRUE); |
08cde01f | 35 | $this->assertEquals(1, $dao->entity_id1); |
36 | $this->assertEquals(2, $dao->entity_id2); | |
9099cab3 | 37 | $this->assertEquals(serialize([ |
808c05a9 | 38 | 'srcName' => 'Mr. Maurice Mouse II', |
39 | 'dstID' => 1, | |
40 | 'dstName' => 'Ms. Meliissa Mouse II', | |
41 | 'weight' => 20, | |
42 | 'canMerge' => TRUE, | |
43 | 'srcID' => 2, | |
9099cab3 | 44 | ]), $dao->data); |
808c05a9 | 45 | |
9099cab3 | 46 | $this->quickCleanup(['civicrm_prevnext_cache']); |
808c05a9 | 47 | } |
48 | ||
e1c519d7 SL |
49 | public function testSetItem() { |
50 | $cacheKeyString = 'TestCacheKeyString'; | |
51 | $data = '1234afgbghh'; | |
52 | $values = []; | |
53 | $values[] = " ( 'civicrm_contact', 0, 0, '{$cacheKeyString}_stats', '$data' ) "; | |
54 | $valueArray = CRM_Core_BAO_PrevNextCache::convertSetItemValues($values[0]); | |
55 | // verify as SetItem would do that it converts the original values style into a sensible array format | |
56 | $this->assertEquals(['civicrm_contact', 0, 0, 'TestCacheKeyString_stats', '1234afgbghh'], $valueArray); | |
57 | CRM_Core_BAO_PrevNextCache::setItem($valueArray[0], $valueArray[1], $valueArray[2], $valueArray[3], $valueArray[4]); | |
58 | $dao = new CRM_Core_BAO_PrevNextCache(); | |
59 | $dao->cacheKey = 'TestCacheKeyString_stats'; | |
60 | $dao->find(TRUE); | |
61 | $this->assertEquals('1234afgbghh', $dao->data); | |
62 | $this->assertEquals(0, $dao->entity_id1); | |
63 | $this->assertEquals(0, $dao->entity_id2); | |
64 | $this->assertEquals('civicrm_contact', $dao->entity_table); | |
65 | } | |
66 | ||
808c05a9 | 67 | } |