You are here

class PathUtilityTest in Drupal 7 to 8/9 Module Upgrader 8

Same name in this branch
  1. 8 tests/src/Unit/Utility/Path/Drupal7/PathUtilityTest.php \Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal7\PathUtilityTest
  2. 8 tests/src/Unit/Utility/Path/Drupal8/PathUtilityTest.php \Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal8\PathUtilityTest

@group DMU.Utility.Path

Hierarchy

Expanded class hierarchy of PathUtilityTest

File

tests/src/Unit/Utility/Path/Drupal7/PathUtilityTest.php, line 12

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Utility\Path\Drupal7
View source
class PathUtilityTest extends UnitTestCase {

  /**
   * Path variable.
   */
  protected $path;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->path = new PathUtility('node/%node/foo/%');
  }
  public function testCount() {
    $this
      ->assertCount(4, $this->path);
  }
  public function testAdd() {
    $path = clone $this->path;
    $path
      ->add('baz');
    $this
      ->assertCount(5, $path);
    $this
      ->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $path
      ->last());
    $this
      ->assertEquals('baz', $path
      ->last()
      ->__toString());
    $path
      ->add(new PathComponent('wambooli'));
    $this
      ->assertCount(6, $path);
    $this
      ->assertEquals('wambooli', $path
      ->last()
      ->__toString());
  }

  /**
   * @expectedException \InvalidArgumentException
   */
  public function testAddArray() {
    $this->path
      ->add([]);
  }

  /**
   * @expectedException \InvalidArgumentException
   */
  public function testAddObject() {
    $this->path
      ->add(new \StdClass());
  }
  public function testFind() {
    $result = $this->path
      ->find('foo');
    $this
      ->assertCount(1, $result);
    $this
      ->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $result
      ->first());
    $this
      ->assertEquals('foo', $result
      ->first()
      ->__toString());
  }
  public function testContains() {
    $this
      ->assertTrue($this->path
      ->contains('%node'));
    $this
      ->assertFalse($this->path
      ->contains('fruit'));
  }
  public function testHasWildcards() {
    $this
      ->assertTrue($this->path
      ->hasWildcards());
  }
  public function testGetWildcards() {
    $this
      ->assertEquals('%node', $this->path
      ->getWildcards()
      ->__toString());
  }
  public function testGetNextWildcard() {
    $wildcard = $this->path
      ->getNextWildcard();
    $this
      ->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $wildcard);
    $this
      ->assertEquals('%node', $wildcard
      ->__toString());
    $wildcard = $this->path
      ->getNextWildcard();
    $this
      ->assertNull($wildcard);
  }
  public function testDeleteWildcards() {
    $this
      ->assertEquals('node/foo/%', $this->path
      ->deleteWildcards()
      ->__toString());
  }
  public function testGetParent() {
    $this
      ->assertEquals('node/%node/foo', $this->path
      ->getParent()
      ->__toString());
  }
  public function testIsDynamic() {
    $this
      ->assertTrue($this->path
      ->isDynamic());
  }
  public function testHasPlaceholders() {
    $this
      ->assertTrue($this->path
      ->hasPlaceholders());
  }
  public function testGetPlaceholders() {
    $placeholders = $this->path
      ->getPlaceholders();
    $this
      ->assertCount(1, $placeholders);
    $this
      ->assertInstanceOf('Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathComponent', $placeholders
      ->first());
    $this
      ->assertEquals('%', $placeholders
      ->first()
      ->__toString());
  }

  /**
   * @depends testHasPlaceholders
   */
  public function testDeletePlaceholders() {
    $this
      ->assertFalse($this->path
      ->deletePlaceholders()
      ->hasPlaceholders());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathUtilityTest::$path protected property Path variable.
PathUtilityTest::setUp public function Overrides UnitTestCase::setUp
PathUtilityTest::testAdd public function
PathUtilityTest::testAddArray public function @expectedException \InvalidArgumentException
PathUtilityTest::testAddObject public function @expectedException \InvalidArgumentException
PathUtilityTest::testContains public function
PathUtilityTest::testCount public function
PathUtilityTest::testDeletePlaceholders public function @depends testHasPlaceholders
PathUtilityTest::testDeleteWildcards public function
PathUtilityTest::testFind public function
PathUtilityTest::testGetNextWildcard public function
PathUtilityTest::testGetParent public function
PathUtilityTest::testGetPlaceholders public function
PathUtilityTest::testGetWildcards public function
PathUtilityTest::testHasPlaceholders public function
PathUtilityTest::testHasWildcards public function
PathUtilityTest::testIsDynamic public function
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.