Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Utility / Path / Drupal8 / PathUtilityTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal8\PathUtilityTest.
6  */
7
8 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal8;
9
10 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\PathComponent;
11 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\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/{bar}');
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\\Drupal8\\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\\Drupal8\\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}/{bar}', $this->path->getWildcards()->__toString());
72   }
73
74   public function testGetNextWildcard() {
75     $wildcard = $this->path->getNextWildcard();
76     $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal8\\PathComponent', $wildcard);
77     $this->assertEquals('{node}', $wildcard->__toString());
78
79     $wildcard = $this->path->getNextWildcard();
80     $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal8\\PathComponent', $wildcard);
81     $this->assertEquals('{bar}', $wildcard->__toString());
82
83     $wildcard = $this->path->getNextWildcard();
84     $this->assertNull($wildcard);
85   }
86
87   public function testDeleteWildcards() {
88     $this->assertEquals('node/foo', $this->path->deleteWildcards()->__toString());
89   }
90
91   public function testGetParent() {
92     $this->assertEquals('node/{node}/foo', $this->path->getParent()->__toString());
93   }
94
95 }