| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License along with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * Verify that CRM_Utils_Cache_ArrayDecorator complies with PSR-16. |
| 29 | * |
| 30 | * @group e2e |
| 31 | */ |
| 32 | class E2E_Cache_ArrayDecoratorTest extends E2E_Cache_CacheTestCase { |
| 33 | |
| 34 | /** |
| 35 | * @var CRM_Utils_Cache_Interface |
| 36 | */ |
| 37 | protected $a; |
| 38 | |
| 39 | public function createSimpleCache() { |
| 40 | return new CRM_Utils_Cache_ArrayDecorator( |
| 41 | $this->a = CRM_Utils_Cache::create([ |
| 42 | 'name' => 'e2e array-dec test', |
| 43 | 'type' => ['ArrayCache'], |
| 44 | ]) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | public function testDoubleLifeWithDelete() { |
| 49 | $this->assertFalse($this->a->has('foo')); |
| 50 | $this->assertEquals('dfl-1', $this->a->get('foo', 'dfl-1')); |
| 51 | |
| 52 | $this->cache->set('foo', 100); |
| 53 | |
| 54 | $this->assertTrue($this->a->has('foo')); |
| 55 | $this->assertEquals(100, $this->a->get('foo', 'dfl-1')[1]); |
| 56 | |
| 57 | $this->cache->set('foo', 200); |
| 58 | |
| 59 | $this->assertTrue($this->a->has('foo')); |
| 60 | $this->assertEquals(200, $this->a->get('foo', 'dfl-1')[1]); |
| 61 | |
| 62 | $this->cache->delete('foo'); |
| 63 | |
| 64 | $this->assertFalse($this->a->has('foo')); |
| 65 | $this->assertEquals('dfl-1', $this->a->get('foo', 'dfl-1')); |
| 66 | } |
| 67 | |
| 68 | public function testDoubleLifeWithClear() { |
| 69 | $this->assertFalse($this->a->has('foo')); |
| 70 | $this->assertEquals('dfl-1', $this->a->get('foo', 'dfl-1')); |
| 71 | |
| 72 | $this->cache->set('foo', 100); |
| 73 | |
| 74 | $this->assertTrue($this->a->has('foo')); |
| 75 | $this->assertEquals(100, $this->a->get('foo', 'dfl-1')[1]); |
| 76 | |
| 77 | $this->cache->clear(); |
| 78 | |
| 79 | $this->assertFalse($this->a->has('foo')); |
| 80 | $this->assertEquals('dfl-1', $this->a->get('foo', 'dfl-1')); |
| 81 | } |
| 82 | |
| 83 | } |