6 * Cache command testing.
10 class cacheCommandCase extends CommandUnishTestCase {
13 if (!$this->getSites()) {
14 $this->setUpDrupal(1, TRUE);
18 function testCacheGet() {
19 $options = $this->getOptions();
20 // Test the cache get command.
22 6 => array('variables', NULL),
23 7 => array('schema', NULL),
24 8 => array('system.date', 'config'),
26 list($key, $bin) = $inputs[UNISH_DRUPAL_MAJOR_VERSION];
27 $this->drush('cache-get', array($key, $bin), $options + array('format' => 'json'));
28 $schema = $this->getOutputFromJSON('data');
29 $this->assertNotEmpty($schema);
31 // Test that get-ing a non-existant cid fails.
32 $this->drush('cache-get', array('test-failure-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
35 function testCacheSet() {
36 $options = $this->getOptions();
37 // Test setting a new cache item.
38 $expected = 'cache test string';
39 $this->drush('cache-set', array('cache-test-cid', $expected), $options);
40 $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'));
41 $data = $this->getOutputFromJSON('data');
42 $this->assertEquals($expected, $data);
44 // Test cache-set using all arguments and many options.
45 $expected = array('key' => 'value');
46 $input = array('data'=> $expected);
47 $stdin = json_encode($input);
48 $bin = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? 'default' : 'cache';
49 $exec = sprintf('%s cache-set %s %s my_cache_id - %s CACHE_PERMANENT --format=json --cache-get 2>%s', UNISH_DRUSH, "--root=" . self::escapeshellarg($options['root']), '--uri=' . $options['uri'], $bin, $this->bit_bucket());
50 $return = $this->execute($exec, self::EXIT_SUCCESS, NULL, [], $stdin);
51 $this->drush('cache-get', array('my_cache_id'), $options + array('format' => 'json'));
52 $data = $this->getOutputFromJSON('data');
53 $this->assertEquals((object)$expected, $data);
56 function testCacheRebuild() {
57 $options = $this->getOptions();
58 // Test cache-clear all and cache-rebuild (D8+).
59 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
60 $this->drush('cache-rebuild', array(), $options);
63 $this->drush('cache-clear', array('all'), $options);
65 $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
68 function getOptions() {
71 'root' => $this->webroot(),
72 'uri' => key($this->getSites()),