Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Plugin / DMU / Converter / Functions / WatchdogTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Converter\Functions;
4
5 use Pharborist\Parser;
6
7 /**
8  * @group DMU.Converter.Functions
9  * @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions\Watchdog
10  */
11 class WatchdogTest extends FunctionCallModifierTestBase {
12
13   public function testRewriteNoVariablesDefaultSeverity() {
14     $function_call = Parser::parseExpression('watchdog("foo", "Hi!")');
15     $rewritten = $this->plugin->rewrite($function_call, $this->target);
16     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
17     $this->assertEquals('\Drupal::logger("foo")->notice("Hi!", [])', $rewritten->getText());
18   }
19
20   public function testRewriteVariablesDefaultSeverity() {
21     $function_call = Parser::parseExpression('watchdog("foo", "Hej", array("baz"))');
22     $rewritten = $this->plugin->rewrite($function_call, $this->target);
23     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
24     $this->assertEquals('\Drupal::logger("foo")->notice("Hej", array("baz"))', $rewritten->getText());
25   }
26
27   public function testRewriteNoVariablesSeverity() {
28     $function_call = Parser::parseExpression('watchdog("foo", "Harrr", NULL, WATCHDOG_WARNING)');
29     $rewritten = $this->plugin->rewrite($function_call, $this->target);
30     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
31     $this->assertEquals('\Drupal::logger("foo")->warning("Harrr", [])', $rewritten->getText());
32   }
33
34   public function testRewriteVariablesSeverity() {
35     $function_call = Parser::parseExpression('watchdog("foo", "Hurrr", array("baz"), WATCHDOG_ERROR)');
36     $rewritten = $this->plugin->rewrite($function_call, $this->target);
37     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
38     $this->assertEquals('\Drupal::logger("foo")->error("Hurrr", array("baz"))', $rewritten->getText());
39   }
40
41   public function testRewriteNoVariablesDynamicSeverity() {
42     $function_call = Parser::parseExpression('watchdog("foo", "Barrr", NULL, get_severity())');
43     $rewritten = $this->plugin->rewrite($function_call, $this->target);
44     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
45     $this->assertEquals('\Drupal::logger("foo")->notice("Barrr", [])', $rewritten->getText());
46   }
47
48   public function testRewriteVariablesTernarySeverity() {
49     $function_call = Parser::parseExpression('watchdog("foo", "Yarrr", array(0), $bipolar ? WATCHDOG_NOTICE : WATCHDOG_CRITICAL)');
50     $rewritten = $this->plugin->rewrite($function_call, $this->target);
51     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
52     $this->assertEquals('\Drupal::logger("foo")->notice("Yarrr", array(0))', $rewritten->getText());
53   }
54
55   public function testRewriteNoVariablesUnknownSeverity() {
56     $function_call = Parser::parseExpression('watchdog("foo", "Ba-zing!", NULL, WATCHDOG_FOO)');
57     $rewritten = $this->plugin->rewrite($function_call, $this->target);
58     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
59     $this->assertEquals('\Drupal::logger("foo")->notice("Ba-zing!", [])', $rewritten->getText());
60   }
61
62 }