Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Utility / Path / Drupal7 / PathUtilityTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal7\PathUtilityTest.
6  */
7
8 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal7;
9
10 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal7\PathComponent;
11 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal7\PathUtility;
12 use Drupal\Tests\UnitTestCase;
13
14 /**
15  * @group DMU.Utility.Path
16  */
17 class PathUtilityTest extends UnitTestCase {
18
19   public function __construct() {
20     $this->path = new PathUtility('node/%node/foo/%');
21   }
22
23   public function testCount() {
24     $this->assertCount(4, $this->path);
25   }
26
27   public function testAdd() {
28     $path = clone $this->path;
29
30     $path->add('baz');
31     $this->assertCount(5, $path);
32     $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $path->last());
33     $this->assertEquals('baz', $path->last()->__toString());
34
35     $path->add(new PathComponent('wambooli'));
36     $this->assertCount(6, $path);
37     $this->assertEquals('wambooli', $path->last()->__toString());
38   }
39
40   /**
41    * @expectedException \InvalidArgumentException
42    */
43   public function testAddArray() {
44     $this->path->add([]);
45   }
46
47   /**
48    * @expectedException \InvalidArgumentException
49    */
50   public function testAddObject() {
51     $this->path->add(new \StdClass());
52   }
53
54   public function testFind() {
55     $result = $this->path->find('foo');
56     $this->assertCount(1, $result);
57     $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $result->first());
58     $this->assertEquals('foo', $result->first()->__toString());
59   }
60
61   public function testContains() {
62     $this->assertTrue($this->path->contains('%node'));
63     $this->assertFalse($this->path->contains('fruit'));
64   }
65
66   public function testHasWildcards() {
67     $this->assertTrue($this->path->hasWildcards());
68   }
69
70   public function testGetWildcards() {
71     $this->assertEquals('%node', $this->path->getWildcards()->__toString());
72   }
73
74   public function testGetNextWildcard() {
75     $wildcard = $this->path->getNextWildcard();
76     $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $wildcard);
77     $this->assertEquals('%node', $wildcard->__toString());
78
79     $wildcard = $this->path->getNextWildcard();
80     $this->assertNull($wildcard);
81   }
82
83   public function testDeleteWildcards() {
84     $this->assertEquals('node/foo/%', $this->path->deleteWildcards()->__toString());
85   }
86
87   public function testGetParent() {
88     $this->assertEquals('node/%node/foo', $this->path->getParent()->__toString());
89   }
90
91   public function testIsDynamic() {
92     $this->assertTrue($this->path->isDynamic());
93   }
94
95   public function testHasPlaceholders() {
96     $this->assertTrue($this->path->hasPlaceholders());
97   }
98
99   public function testGetPlaceholders() {
100     $placeholders = $this->path->getPlaceholders();
101     $this->assertCount(1, $placeholders);
102     $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $placeholders->first());
103     $this->assertEquals('%', $placeholders->first()->__toString());
104   }
105
106   /**
107    * @depends testHasPlaceholders
108    */
109   public function testDeletePlaceholders() {
110     $this->assertFalse($this->path->deletePlaceholders()->hasPlaceholders());
111   }
112
113 }