function cacheCommandCase::testCacheSet

8.0.x cacheCommandTest.php cacheCommandCase::testCacheSet()
7.x cacheCommandTest.php cacheCommandCase::testCacheSet()
master cacheCommandTest.php cacheCommandCase::testCacheSet()

File

tests/cacheCommandTest.php, line 34

Namespace

Unish

Class

cacheCommandCase
Cache command testing.

Code

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('%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());
  $return = $this->execute($exec, self::EXIT_SUCCESS, NULL, [], $stdin);
  $this->drush('cache-get', array('my_cache_id'), $options + array('format' => 'json'));
  $data = $this->getOutputFromJSON('data');
  $this->assertEquals((object) $expected, $data);
}