6 * Cache command testing.
10 class CacheCommandCase extends CommandUnishTestCase
13 public function setUp()
15 if (!$this->getSites()) {
16 $this->setUpDrupal(1, true);
20 public function testCacheGet()
22 // Test the cache get command.
23 $this->drush('cache-get', ['system.date', 'config'], ['format' => 'json']);
24 $schema = $this->getOutputFromJSON('data');
25 $this->assertNotEmpty($schema);
27 // Test that get-ing a non-existant cid fails.
28 $this->drush('cache-get', ['test-failure-cid'], ['format' => 'json'], null, null, self::EXIT_ERROR);
31 public function testCacheSet()
33 // Test setting a new cache item.
34 $expected = 'cache test string';
35 $this->drush('cache-set', ['cache-test-cid', $expected]);
36 $this->drush('cache-get', ['cache-test-cid'], ['format' => 'json']);
37 $data = $this->getOutputFromJSON('data');
38 $this->assertEquals($expected, $data);
40 // Test cache-set using all arguments and many options.
41 $expected = ['key' => 'value'];
42 $input = ['data'=> $expected];
43 $stdin = json_encode($input);
45 $exec = sprintf('%s cache-set %s %s my_cache_id - %s CACHE_PERMANENT --input-format=json --cache-get 2>%s', self::getDrush(), "--root=" . self::escapeshellarg($this->webroot()), '--uri=' . $this->getUri(), $bin, $this->bitBucket());
46 $return = $this->execute($exec, self::EXIT_SUCCESS, null, [], $stdin);
47 $this->drush('cache-get', ['my_cache_id'], ['format' => 'json']);
48 $data = $this->getOutputFromJSON('data');
49 $this->assertEquals((object)$expected, $data);
52 public function testCacheRebuild()
54 // Test cache-clear all and cache-rebuild (D8+).
55 $this->drush('cache-rebuild');
56 $this->drush('cache-get', ['cache-test-cid'], ['format' => 'json'], null, null, self::EXIT_ERROR);