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. 7 => array('schema', NULL),
  19. 8 => array('system.date', 'config'),
  20. );
  21. list($key, $bin) = $inputs[UNISH_DRUPAL_MAJOR_VERSION];
  22. $this->drush('cache-get', array($key, $bin), $options + array('format' => 'json'));
  23. $schema = $this->getOutputFromJSON('data');
  24. $this->assertNotEmpty($schema);
  25. // Test that get-ing a non-existant cid fails.
  26. $this->drush('cache-get', array('test-failure-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
  27. }
  28. function testCacheSet() {
  29. $options = $this->getOptions();
  30. // Test setting a new cache item.
  31. $expected = 'cache test string';
  32. $this->drush('cache-set', array('cache-test-cid', $expected), $options);
  33. $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'));
  34. $data = $this->getOutputFromJSON('data');
  35. $this->assertEquals($expected, $data);
  36. // Test cache-set using all arguments and many options.
  37. $expected = array('key' => 'value');
  38. $input = array('data'=> $expected);
  39. $stdin = json_encode($input);
  40. $bin = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? 'default' : 'cache';
  41. $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());
  42. $return = $this->execute($exec, self::EXIT_SUCCESS, NULL, [], $stdin);
  43. $this->drush('cache-get', array('my_cache_id'), $options + array('format' => 'json'));
  44. $data = $this->getOutputFromJSON('data');
  45. $this->assertEquals((object)$expected, $data);
  46. }
  47. function testCacheRebuild() {
  48. $options = $this->getOptions();
  49. // Test cache-clear all and cache-rebuild (D8+).
  50. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  51. $this->drush('cache-rebuild', array(), $options);
  52. }
  53. else {
  54. $this->drush('cache-clear', array('all'), $options);
  55. }
  56. $this->drush('cache-get', array('cache-test-cid'), $options + array('format' => 'json'), NULL, NULL, self::EXIT_ERROR);
  57. }
  58. function getOptions() {
  59. return array(
  60. 'yes' => NULL,
  61. 'root' => $this->webroot(),
  62. 'uri' => key($this->getSites()),
  63. );
  64. }
  65. }