Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Routing / ParameterBindingTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Routing;
4
5 use Drupal\drupalmoduleupgrader\Routing\ParameterBinding;
6 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal7\PathUtility;
7 use Drupal\Tests\UnitTestCase;
8 use Pharborist\Functions\ParameterNode;
9 use Pharborist\Types\StringNode;
10
11 /**
12  * @group DMU.Routing
13  */
14 class ParameterBindingTest extends UnitTestCase {
15
16   /**
17    * @var ParameterNode
18    */
19   private $parameter;
20
21   public function setUp() {
22     // ParameterNode supports variadic parameters, which use the T_ELLIPSIS
23     // token. Which will be undefined on any PHP older than 5.6. So this kludges
24     // around that.
25     if (! defined('T_ELLIPSIS')) {
26       define('T_ELLIPSIS', 0);
27     }
28
29     $this->parameter = ParameterNode::create('foo');
30   }
31
32   public function testGetParameter() {
33     $path = new PathUtility('foo/baz');
34     $binding = new ParameterBinding($path, $this->parameter);
35     $this->assertSame($this->parameter, $binding->getParameter());
36   }
37
38   public function testInPath() {
39     $path = new PathUtility('foo/baz');
40     $binding = new ParameterBinding($path, $this->parameter);
41     $this->assertFalse($binding->inPath());
42
43     $path = new PathUtility('foo/%node');
44     $binding = new ParameterBinding($path, $this->parameter, 1);
45     $this->assertTrue($binding->inPath());
46   }
47
48   public function testHasArgument() {
49     $path = new PathUtility('foo/baz');
50     $binding = new ParameterBinding($path, $this->parameter);
51     $this->assertFalse($binding->hasArgument());
52
53     $path = new PathUtility('foo/%node');
54     $binding = new ParameterBinding($path, $this->parameter, 1);
55     $this->assertTrue($binding->hasArgument());
56
57     $path = new PathUtility('foo/%');
58     $binding = new ParameterBinding($path, $this->parameter, 'baz');
59     $this->assertTrue($binding->hasArgument());
60   }
61
62   public function testGetArgument() {
63     $path = new PathUtility('foo/%node');
64     $binding = new ParameterBinding($path, $this->parameter, 1);
65     $this->assertSame(1, $binding->getArgument());
66
67     $path = new PathUtility('foo/%');
68     $binding = new ParameterBinding($path, $this->parameter, 'baz');
69     $this->assertEquals('baz', $binding->getArgument());
70   }
71
72   public function testIsPathPosition() {
73     $path = new PathUtility('foo/%node');
74     $binding = new ParameterBinding($path, $this->parameter, 1);
75     $this->assertTrue($binding->isPathPosition());
76
77     $path = new PathUtility('foo/%');
78     $binding = new ParameterBinding($path, $this->parameter, 'baz');
79     $this->assertFalse($binding->isPathPosition());
80   }
81
82   public function testGetValuePathPositionInPath() {
83     $path = new PathUtility('foo/%node');
84     $binding = new ParameterBinding($path, $this->parameter, 1);
85     $value = $binding->getValue();
86     $this->assertInstanceOf('\Drupal\drupalmoduleupgrader\Utility\Path\PathComponentInterface', $value);
87     $this->assertEquals('%node', $value);
88   }
89
90   public function testGetValuePathPositionNotInPath() {
91     $path = new PathUtility('foo/%node');
92     $binding = new ParameterBinding($path, $this->parameter, 2);
93     $value = $binding->getValue();
94     $this->assertInstanceOf('\Drupal\drupalmoduleupgrader\Utility\Path\PathComponentInterface', $value);
95     $this->assertEquals('%', $value);
96   }
97
98   public function testGetValueStaticArgument() {
99     $path = new PathUtility('foo/%node');
100     $binding = new ParameterBinding($path, $this->parameter, 'baz');
101     $this->assertEquals('baz', $binding->getValue());
102   }
103
104   public function testGetValueNoArgument() {
105     $this->parameter->setValue(StringNode::fromValue('har'));
106     $path = new PathUtility('foo/%node');
107     $binding = new ParameterBinding($path, $this->parameter);
108     $this->assertEquals('har', $binding->getValue());
109   }
110
111   public function testGetValueNoArgumentNoDefaultvalue() {
112     $path = new PathUtility('foo/%node');
113     $binding = new ParameterBinding($path, $this->parameter);
114     $this->assertNull($binding->getValue());
115   }
116
117 }