forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacheCommandTest.php
70 lines (61 loc) · 2.4 KB
/
cacheCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Unish;
/**
* Cache command testing.
*
* @group base
*/
class cacheCommandCase extends CommandUnishTestCase {
function setUp() {
if (!$this->getSites()) {
$this->setUpDrupal(1, TRUE);
}
}
function testCacheGet() {
$options = $this->getOptions();
// Test the cache get command.
$key = UNISH_DRUPAL_MAJOR_VERSION == 6 ? 'variables' : 'schema';
$this->drush('cache-get', array($key), $options + array('format' => 'json'));
$schema = $this->getOutputFromJSON('data');
$this->assertNotEmpty($schema);
// Test that get-ing a non-existant cid fails.
$this->drush('cache-get', array('test-failure-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
}
function testCacheSet() {
$options = $this->getOptions();
// Test setting a new cache item.
$expected = 'cache test string';
$this->drush('cache-set', array('cache-test-cid', $expected), $options);
$this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'));
$data = $this->getOutputFromJSON('data');
$this->assertEquals($expected, $data);
// Test cache-set using all arguments and many options.
$expected = array('key' => 'value');
$input = array('data'=> $expected);
$stdin = json_encode($input);
$bin = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? 'default' : 'cache';
$exec = sprintf('echo %s | %s cache-set %s %s my_cache_id - %s CACHE_PERMANENT --format=json --cache-get 2>/dev/null', self::escapeshellarg($stdin), UNISH_DRUSH, "--root=" . self::escapeshellarg($options['root']), '--uri=' . $options['uri'], $bin);
$return = $this->execute($exec);
$this->drush('cache-get', array('my_cache_id'), $options + array('format' => 'json'));
$data = $this->getOutputFromJSON('data');
$this->assertEquals((object)$expected, $data);
}
function testCacheRebuild() {
$options = $this->getOptions();
// Test cache-clear all and cache-rebuild (D8+).
if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
$this->drush('cache-rebuild', array(), $options);
}
else {
$this->drush('cache-clear', array('all'), $options);
}
$this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
}
function getOptions() {
return array(
'yes' => NULL,
'root' => $this->webroot(),
'uri' => key($this->getSites()),
);
}
}