5 * Contains \Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal8\PathUtilityTest.
8 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal8;
10 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\PathComponent;
11 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\PathUtility;
12 use Drupal\Tests\UnitTestCase;
15 * @group DMU.Utility.Path
17 class PathUtilityTest extends UnitTestCase {
19 public function __construct() {
20 $this->path = new PathUtility('node/{node}/foo/{bar}');
23 public function testCount() {
24 $this->assertCount(4, $this->path);
27 public function testAdd() {
28 $path = clone $this->path;
31 $this->assertCount(5, $path);
32 $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal8\\PathComponent', $path->last());
33 $this->assertEquals('baz', $path->last()->__toString());
35 $path->add(new PathComponent('wambooli'));
36 $this->assertCount(6, $path);
37 $this->assertEquals('wambooli', $path->last()->__toString());
41 * @expectedException \InvalidArgumentException
43 public function testAddArray() {
48 * @expectedException \InvalidArgumentException
50 public function testAddObject() {
51 $this->path->add(new \StdClass());
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());
61 public function testContains() {
62 $this->assertTrue($this->path->contains('{node}'));
63 $this->assertFalse($this->path->contains('fruit'));
66 public function testHasWildcards() {
67 $this->assertTrue($this->path->hasWildcards());
70 public function testGetWildcards() {
71 $this->assertEquals('{node}/{bar}', $this->path->getWildcards()->__toString());
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());
79 $wildcard = $this->path->getNextWildcard();
80 $this->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal8\\PathComponent', $wildcard);
81 $this->assertEquals('{bar}', $wildcard->__toString());
83 $wildcard = $this->path->getNextWildcard();
84 $this->assertNull($wildcard);
87 public function testDeleteWildcards() {
88 $this->assertEquals('node/foo', $this->path->deleteWildcards()->__toString());
91 public function testGetParent() {
92 $this->assertEquals('node/{node}/foo', $this->path->getParent()->__toString());