12c92bdee822ced5d646aeaf110363752346e2ec
[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
13     public function setUp()
14     {
15         if (!$this->getSites()) {
16             $this->setUpDrupal(1, true);
17         }
18     }
19
20     public function testCacheGet()
21     {
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);
26
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);
29     }
30
31     public function testCacheSet()
32     {
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);
39
40         // Test cache-set using all arguments and many options.
41         $expected = ['key' => 'value'];
42         $input = ['data'=> $expected];
43         $stdin = json_encode($input);
44         $bin = 'default';
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);
50     }
51
52     public function testCacheRebuild()
53     {
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);
57     }
58 }