Version 1
[yaffs-website] / vendor / drush / drush / tests / watchdogTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6  * @group commands
7  */
8 class WatchdogCase extends CommandUnishTestCase {
9
10   function  testWatchdog() {
11     $sites = $this->setUpDrupal(1, TRUE);
12     $options = array(
13       'yes' => NULL,
14       'root' => $this->webroot(),
15       'uri' => key($sites),
16     );
17
18     if (UNISH_DRUPAL_MAJOR_VERSION >= 7) {
19       $this->drush('pm-enable', array('dblog'), $options);
20     }
21     if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
22       $eval1 = "\\Drupal::logger('drush')->notice('Unish rocks.');";
23     }
24     else {
25       $eval1 = "watchdog('drush', 'Unish rocks.');";
26     }
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);
31
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.
36     $message_chars = 300;
37     $char = '*';
38     $message = str_repeat($char, $message_chars);
39     if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
40       $eval2 = "\\Drupal::logger('drush')->notice('$message');";
41     }
42     else {
43       $eval2 = "watchdog('drush', '$message');";
44     }
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));
52
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);
59   }
60 }