watchdogTest.php

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

Namespace

Unish

Classes

Namesort descending Description
WatchdogCase @group commands

File

tests/watchdogTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * @group commands
  5. */
  6. class WatchdogCase extends CommandUnishTestCase {
  7. function testWatchdog() {
  8. $sites = $this->setUpDrupal(1, TRUE);
  9. $options = array(
  10. 'yes' => NULL,
  11. 'root' => $this->webroot(),
  12. 'uri' => key($sites),
  13. );
  14. if (UNISH_DRUPAL_MAJOR_VERSION >= 7) {
  15. $this->drush('pm-enable', array('dblog'), $options);
  16. }
  17. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  18. $eval1 = "\\Drupal::logger('drush')->notice('Unish rocks.');";
  19. }
  20. else {
  21. $eval1 = "watchdog('drush', 'Unish rocks.');";
  22. }
  23. $this->drush('php-eval', array($eval1), $options);
  24. $this->drush('watchdog-show', array(), $options + array('count' => 50));
  25. $output = $this->getOutput();
  26. $this->assertContains('Unish rocks.', $output);
  27. // Add a new entry with a long message with the letter 'd' and verify that watchdog-show does
  28. // not print it completely in the listing unless --full is given.
  29. // As the output is formatted so lines may be splitted, assertContains does not work
  30. // in this scenario. Therefore, we will count the number of times a character is present.
  31. $message_chars = 300;
  32. $char = '*';
  33. $message = str_repeat($char, $message_chars);
  34. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  35. $eval2 = "\\Drupal::logger('drush')->notice('$message');";
  36. }
  37. else {
  38. $eval2 = "watchdog('drush', '$message');";
  39. }
  40. $this->drush('php-eval', array($eval2), $options);
  41. $this->drush('watchdog-show', array(), $options);
  42. $output = $this->getOutput();
  43. $this->assertGreaterThan(substr_count($output, $char), $message_chars);
  44. $this->drush('watchdog-show', array(), $options + array('extended' => NULL));
  45. $output = $this->getOutput();
  46. $this->assertGreaterThanOrEqual($message_chars, substr_count($output, $char));
  47. // Tests message deletion
  48. $this->drush('watchdog-delete', array('all'), $options);
  49. $output = $this->getOutput();
  50. $this->drush('watchdog-show', array(), $options);
  51. $output = $this->getOutput();
  52. $this->assertEmpty($output);
  53. }
  54. }