class ParameterBindingTest in Drupal 7 to 8/9 Module Upgrader 8
@group DMU.Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\drupalmoduleupgrader\Unit\Routing\ParameterBindingTest
Expanded class hierarchy of ParameterBindingTest
File
- tests/
src/ Unit/ Routing/ ParameterBindingTest.php, line 14
Namespace
Drupal\Tests\drupalmoduleupgrader\Unit\RoutingView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ParameterBindingTest:: |
private | property | ||
ParameterBindingTest:: |
public | function |
Overrides UnitTestCase:: |
|
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
ParameterBindingTest:: |
public | function | ||
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |