Version 1
[yaffs-website] / vendor / drush / drush / tests / cacheCommandTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6   * Cache command testing.
7   *
8   * @group base
9   */
10 class cacheCommandCase extends CommandUnishTestCase {
11
12   function setUp() {
13     if (!$this->getSites()) {
14       $this->setUpDrupal(1, TRUE);
15     }
16   }
17
18   function testCacheGet() {
19     $options = $this->getOptions();
20     // Test the cache get command.
21     $inputs = array(
22       6 => array('variables', NULL),
23       7 => array('schema', NULL),
24       8 => array('system.date', 'config'),
25     );
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);
30
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);
33   }
34
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);
43
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);
54   }
55
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);
61     }
62     else {
63       $this->drush('cache-clear', array('all'), $options);
64     }
65     $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
66   }
67
68   function getOptions() {
69     return array(
70       'yes' => NULL,
71       'root' => $this->webroot(),
72       'uri' => key($this->getSites()),
73     );
74   }
75 }