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

Namespace

Unish

Classes

Namesort descending Description
cacheCommandCase Cache command testing.

File

tests/cacheCommandTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Cache command testing.
  5. *
  6. * @group base
  7. */
  8. class cacheCommandCase extends CommandUnishTestCase {
  9. function setUp() {
  10. if (!$this->getSites()) {
  11. $this->setUpDrupal(1, TRUE);
  12. }
  13. }
  14. function testCacheGet() {
  15. $options = $this->getOptions();
  16. // Test the cache get command.
  17. $inputs = array(
  18. 6 => array('variables', NULL),
  19. 7 => array('schema', NULL),
  20. 8 => array('system.date', 'config'),
  21. );
  22. list($key, $bin) = $inputs[UNISH_DRUPAL_MAJOR_VERSION];
  23. $this->drush('cache-get', array($key, $bin), $options + array('format' => 'json'));
  24. $schema = $this->getOutputFromJSON('data');
  25. $this->assertNotEmpty($schema);
  26. // Test that get-ing a non-existant cid fails.
  27. $this->drush('cache-get', array('test-failure-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
  28. }
  29. function testCacheSet() {
  30. $options = $this->getOptions();
  31. // Test setting a new cache item.
  32. $expected = 'cache test string';
  33. $this->drush('cache-set', array('cache-test-cid', $expected), $options);
  34. $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'));
  35. $data = $this->getOutputFromJSON('data');
  36. $this->assertEquals($expected, $data);
  37. // Test cache-set using all arguments and many options.
  38. $expected = array('key' => 'value');
  39. $input = array('data'=> $expected);
  40. $stdin = json_encode($input);
  41. $bin = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? 'default' : 'cache';
  42. $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);
  43. $return = $this->execute($exec);
  44. $this->drush('cache-get', array('my_cache_id'), $options + array('format' => 'json'));
  45. $data = $this->getOutputFromJSON('data');
  46. $this->assertEquals((object)$expected, $data);
  47. }
  48. function testCacheRebuild() {
  49. $options = $this->getOptions();
  50. // Test cache-clear all and cache-rebuild (D8+).
  51. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  52. $this->drush('cache-rebuild', array(), $options);
  53. }
  54. else {
  55. $this->drush('cache-clear', array('all'), $options);
  56. }
  57. $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
  58. }
  59. function getOptions() {
  60. return array(
  61. 'yes' => NULL,
  62. 'root' => $this->webroot(),
  63. 'uri' => key($this->getSites()),
  64. );
  65. }
  66. }