class WorkbenchPreprocessTest in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/WorkbenchPreprocessTest.php \Drupal\Tests\workbench_moderation\Unit\WorkbenchPreprocessTest
Class WorkbenchPreprocessTest.
@coversDefaultClass \Drupal\workbench_moderation\WorkbenchPreprocess @group workbench_moderation
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\workbench_moderation\Unit\WorkbenchPreprocessTest
Expanded class hierarchy of WorkbenchPreprocessTest
File
- tests/
src/ Unit/ WorkbenchPreprocessTest.php, line 16
Namespace
Drupal\Tests\workbench_moderation\UnitView source
class WorkbenchPreprocessTest extends UnitTestCase {
/**
* @covers ::isLatestVersionPage
* @dataProvider routeNodeProvider
*/
public function testIsLatestVersionPage($route_name, $route_nid, $check_nid, $result, $message) {
$workbench_preprocess = new WorkbenchPreprocess($this
->setupCurrentRouteMatch($route_name, $route_nid));
$node = $this
->setupNode($check_nid);
$this
->assertEquals($result, $workbench_preprocess
->isLatestVersionPage($node), $message);
}
/**
* Route node provider.
*/
public function routeNodeProvider() {
return [
[
'entity.node.cannonical',
1,
1,
FALSE,
'Not on the latest version tab route.',
],
[
'entity.node.latest_version',
1,
1,
TRUE,
'On the latest version tab route, with the route node.',
],
[
'entity.node.latest_version',
1,
2,
FALSE,
'On the latest version tab route, with a different node.',
],
];
}
/**
* Mock the current route matching object.
*
* @param string $routeName
* Route.
* @param int $nid
* Node id.
*
* @return \Drupal\Core\Routing\CurrentRouteMatch
* Returns cuurent route.
*/
protected function setupCurrentRouteMatch($routeName, $nid) {
$route_match = $this
->prophesize(CurrentRouteMatch::class);
$route_match
->getRouteName()
->willReturn($routeName);
$route_match
->getParameter('node')
->willReturn($this
->setupNode($nid));
return $route_match
->reveal();
}
/**
* Mock a node object.
*
* @param int $nid
* Node id.
*
* @return \Drupal\node\Entity\Node
* Returns node.
*/
protected function setupNode($nid) {
$node = $this
->prophesize(Node::class);
$node
->id()
->willReturn($nid);
return $node
->reveal();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
UnitTestCase:: |
protected | function | 340 | |
WorkbenchPreprocessTest:: |
public | function | Route node provider. | |
WorkbenchPreprocessTest:: |
protected | function | Mock the current route matching object. | |
WorkbenchPreprocessTest:: |
protected | function | Mock a node object. | |
WorkbenchPreprocessTest:: |
public | function | @covers ::isLatestVersionPage @dataProvider routeNodeProvider |