cacheCommandTest.php

  1. 8.0.x tests/cacheCommandTest.php
  2. 6.x tests/cacheCommandTest.php
  3. 7.x tests/cacheCommandTest.php
  4. 5.x tests/cacheCommandTest.php
  5. master tests/cacheCommandTest.php

Classes

Namesort descending Description
cacheCommandCase cache command testing.

File

tests/cacheCommandTest.php
View source
  1. <?php
  2. /**
  3. * cache command testing.
  4. *
  5. * @group base
  6. */
  7. class cacheCommandCase extends Drush_CommandTestCase {
  8. public function testCacheGetSetClear() {
  9. $this->setUpDrupal(1, TRUE);
  10. $options = array(
  11. 'yes' => NULL,
  12. 'root' => $this->webroot(),
  13. 'uri' => key($this->sites),
  14. );
  15. // Test the cache get command.
  16. $key = UNISH_DRUPAL_MAJOR_VERSION == 6 ? 'variables' : 'schema';
  17. $this->drush('cache-get', array($key), $options + array('format' => 'json'));
  18. $schema = $this->getOutputFromJSON('data');
  19. $this->assertNotEmpty($schema);
  20. // Test that get-ing a non-existant cid fails.
  21. $this->drush('cache-get', array('test-failure-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
  22. // Test setting a new cache item.
  23. $expected = 'cache test string';
  24. $this->drush('cache-set', array('cache-test-cid', $expected), $options);
  25. $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'));
  26. $data = $this->getOutputFromJSON('data');
  27. $this->assertEquals($expected, $data);
  28. // Test cache-set using all arguments and many options.
  29. $expected = array('key' => 'value');
  30. $input = array('data'=> $expected);
  31. $stdin = json_encode($input);
  32. $exec = sprintf('echo %s | %s cache-set %s %s my_cache_id - cache CACHE_PERMANENT --format=json --cache-get 2>/dev/null', self::escapeshellarg($stdin), UNISH_DRUSH, "--root=" . self::escapeshellarg($options['root']), '--uri=' . $options['uri']);
  33. $return = $this->execute($exec);
  34. $this->drush('cache-get', array('my_cache_id', 'cache'), $options + array('format' => 'json'));
  35. $data = $this->getOutputFromJSON('data');
  36. $this->assertEquals((object)$expected, $data);
  37. // Test cache-clear all.
  38. $this->drush('cache-clear', array('all'), $options);
  39. $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
  40. }
  41. }