You are here

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

@group DMU.Routing

Hierarchy

Expanded class hierarchy of ParameterBindingTest

File

tests/src/Unit/Routing/ParameterBindingTest.php, line 14

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Routing
View source
class ParameterBindingTest extends UnitTestCase {

  /**
   * @var \Pharborist\Functions\ParameterNode
   */
  private $parameter;
  public function setUp() {

    // ParameterNode supports variadic parameters, which use the T_ELLIPSIS
    // token. Which will be undefined on any PHP older than 5.6. So this kludges
    // around that.
    if (!defined('T_ELLIPSIS')) {
      define('T_ELLIPSIS', 0);
    }
    $this->parameter = ParameterNode::create('foo');
  }
  public function testGetParameter() {
    $path = new PathUtility('foo/baz');
    $binding = new ParameterBinding($path, $this->parameter);
    $this
      ->assertSame($this->parameter, $binding
      ->getParameter());
  }
  public function testInPath() {
    $path = new PathUtility('foo/baz');
    $binding = new ParameterBinding($path, $this->parameter);
    $this
      ->assertFalse($binding
      ->inPath());
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 1);
    $this
      ->assertTrue($binding
      ->inPath());
  }
  public function testHasArgument() {
    $path = new PathUtility('foo/baz');
    $binding = new ParameterBinding($path, $this->parameter);
    $this
      ->assertFalse($binding
      ->hasArgument());
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 1);
    $this
      ->assertTrue($binding
      ->hasArgument());
    $path = new PathUtility('foo/%');
    $binding = new ParameterBinding($path, $this->parameter, 'baz');
    $this
      ->assertTrue($binding
      ->hasArgument());
  }
  public function testGetArgument() {
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 1);
    $this
      ->assertSame(1, $binding
      ->getArgument());
    $path = new PathUtility('foo/%');
    $binding = new ParameterBinding($path, $this->parameter, 'baz');
    $this
      ->assertEquals('baz', $binding
      ->getArgument());
  }
  public function testIsPathPosition() {
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 1);
    $this
      ->assertTrue($binding
      ->isPathPosition());
    $path = new PathUtility('foo/%');
    $binding = new ParameterBinding($path, $this->parameter, 'baz');
    $this
      ->assertFalse($binding
      ->isPathPosition());
  }
  public function testGetValuePathPositionInPath() {
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 1);
    $value = $binding
      ->getValue();
    $this
      ->assertInstanceOf('\\Drupal\\drupalmoduleupgrader\\Utility\\Path\\PathComponentInterface', $value);
    $this
      ->assertEquals('%node', $value);
  }
  public function testGetValuePathPositionNotInPath() {
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 2);
    $value = $binding
      ->getValue();
    $this
      ->assertInstanceOf('\\Drupal\\drupalmoduleupgrader\\Utility\\Path\\PathComponentInterface', $value);
    $this
      ->assertEquals('%', $value);
  }
  public function testGetValueStaticArgument() {
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter, 'baz');
    $this
      ->assertEquals('baz', $binding
      ->getValue());
  }
  public function testGetValueNoArgument() {
    $reflection = new \ReflectionClass($this->parameter);
    $property = $reflection
      ->getProperty('value');
    $property
      ->setAccessible(TRUE);
    $property
      ->setValue($this->parameter, StringNode::fromValue('har'));
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter);
    $this
      ->assertEquals('har', $binding
      ->getValue());
  }
  public function testGetValueNoArgumentNoDefaultvalue() {
    $path = new PathUtility('foo/%node');
    $binding = new ParameterBinding($path, $this->parameter);
    $this
      ->assertNull($binding
      ->getValue());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParameterBindingTest::$parameter private property
ParameterBindingTest::setUp public function Overrides UnitTestCase::setUp
ParameterBindingTest::testGetArgument public function
ParameterBindingTest::testGetParameter public function
ParameterBindingTest::testGetValueNoArgument public function
ParameterBindingTest::testGetValueNoArgumentNoDefaultvalue public function
ParameterBindingTest::testGetValuePathPositionInPath public function
ParameterBindingTest::testGetValuePathPositionNotInPath public function
ParameterBindingTest::testGetValueStaticArgument public function
ParameterBindingTest::testHasArgument public function
ParameterBindingTest::testInPath public function
ParameterBindingTest::testIsPathPosition 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.