/** * Tests setting and invalidating * * @dataProvider providerTestInvalidCharacters */ public function testCacheCollector($cid, $key, $value) { $collector = new CacheCollectorHelper($cid, $this->container->get('cache.default'), $this->container->get('lock')); $this->assertNull($collector->get($key)); $collector->set($key, $value); $this->assertEquals($value, $collector->get($key)); $collector->destruct(); // @todo Shouldn't this be empty after destruction? $this->assertEquals($value, $collector->get($key)); }
/** * Tests updating the cache after a delete. */ public function testUpdateCacheDelete() { $key = $this->randomMachineName(); $value = $this->randomMachineName(); $cache = (object) array('data' => array($key => $value), 'created' => (int) $_SERVER['REQUEST_TIME']); $this->cacheBackend->expects($this->at(0))->method('get')->with($this->cid)->will($this->returnValue($cache)); $this->collector->delete($key); // Set up mock objects for the expected calls, first a lock acquire, then // cache get to look for conflicting cache entries, then a cache set and // finally the lock is released again. $this->lock->expects($this->once())->method('acquire')->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector')->will($this->returnValue(TRUE)); // The second argument is set to TRUE because we triggered a cache // invalidation. $this->cacheBackend->expects($this->at(0))->method('get')->with($this->cid, TRUE); $this->cacheBackend->expects($this->once())->method('set')->with($this->cid, array(), Cache::PERMANENT, array()); $this->lock->expects($this->once())->method('release')->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector'); // Destruct the object to trigger the update data process. $this->collector->destruct(); }