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

Classes

Namesort ascending Description
WatchdogCase

File

tests/watchdogTest.php
View source
  1. <?php
  2. /*
  3. * @file
  4. * Tests watchdog-show and watchdog-delete commands
  5. */
  6. class WatchdogCase extends Drush_TestCase {
  7. function testWatchdog() {
  8. $env = 'dev';
  9. $sites = $this->setUpDrupal($env, TRUE);
  10. $root = $this->sites[$env]['root'];
  11. $options = array(
  12. 'yes' => NULL,
  13. 'root' => $root,
  14. 'uri' => $env,
  15. );
  16. // Enable dblog module and verify that the watchdog messages are listed
  17. $this->drush('pm-enable', array('dblog'), $options);
  18. $this->drush('watchdog-show', array(), $options);
  19. $output = $this->getOutput();
  20. $this->assertContains('dblog module installed.', $output);
  21. $this->assertContains('dblog module enabled.', $output);
  22. // Add a new entry with a long message with the letter 'd' and verify that watchdog-show does
  23. // not print it completely in the listing unless --full is given.
  24. // As the output is formatted so lines may be splitted, assertContains does not work
  25. // in this scenario. Therefore, we will count the number of times a character is present.
  26. $message_chars = 300;
  27. $char = '*';
  28. $message = str_repeat($char, $message_chars);
  29. $this->drush('php-eval', array("watchdog('drush', '" . $message . "')"), $options);
  30. $this->drush('watchdog-show', array(), $options);
  31. $output = $this->getOutput();
  32. $this->assertGreaterThan(substr_count($output, $char), $message_chars);
  33. $this->drush('watchdog-show', array(), $options + array('full' => NULL));
  34. $output = $this->getOutput();
  35. $this->assertGreaterThanOrEqual($message_chars, substr_count($output, $char));
  36. // Tests message deletion
  37. $this->drush('watchdog-delete', array('all'), $options);
  38. $output = $this->getOutput();
  39. $this->drush('watchdog-show', array(), $options);
  40. $output = $this->getOutput();
  41. $this->assertEmpty($output);
  42. }
  43. }