8 class WatchdogCase extends CommandUnishTestCase {
10 function testWatchdog() {
11 $sites = $this->setUpDrupal(1, TRUE);
14 'root' => $this->webroot(),
18 if (UNISH_DRUPAL_MAJOR_VERSION >= 7) {
19 $this->drush('pm-enable', array('dblog'), $options);
21 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
22 $eval1 = "\\Drupal::logger('drush')->notice('Unish rocks.');";
25 $eval1 = "watchdog('drush', 'Unish rocks.');";
27 $this->drush('php-eval', array($eval1), $options);
28 $this->drush('watchdog-show', array(), $options + array('count' => 50));
29 $output = $this->getOutput();
30 $this->assertContains('Unish rocks.', $output);
32 // Add a new entry with a long message with the letter 'd' and verify that watchdog-show does
33 // not print it completely in the listing unless --full is given.
34 // As the output is formatted so lines may be splitted, assertContains does not work
35 // in this scenario. Therefore, we will count the number of times a character is present.
38 $message = str_repeat($char, $message_chars);
39 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
40 $eval2 = "\\Drupal::logger('drush')->notice('$message');";
43 $eval2 = "watchdog('drush', '$message');";
45 $this->drush('php-eval', array($eval2), $options);
46 $this->drush('watchdog-show', array(), $options);
47 $output = $this->getOutput();
48 $this->assertGreaterThan(substr_count($output, $char), $message_chars);
49 $this->drush('watchdog-show', array(), $options + array('extended' => NULL));
50 $output = $this->getOutput();
51 $this->assertGreaterThanOrEqual($message_chars, substr_count($output, $char));
53 // Tests message deletion
54 $this->drush('watchdog-delete', array('all'), $options);
55 $output = $this->getOutput();
56 $this->drush('watchdog-show', array(), $options);
57 $output = $this->getOutput();
58 $this->assertEmpty($output);