class ContentPreprocessTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php \Drupal\Tests\content_moderation\Unit\ContentPreprocessTest
- 10 core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php \Drupal\Tests\content_moderation\Unit\ContentPreprocessTest
@coversDefaultClass \Drupal\content_moderation\ContentPreprocess
@group content_moderation
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\content_moderation\Unit\ContentPreprocessTest
Expanded class hierarchy of ContentPreprocessTest
File
- core/
modules/ content_moderation/ tests/ src/ Unit/ ContentPreprocessTest.php, line 15
Namespace
Drupal\Tests\content_moderation\UnitView source
class ContentPreprocessTest extends UnitTestCase {
/**
* @covers ::isLatestVersionPage
* @dataProvider routeNodeProvider
*/
public function testIsLatestVersionPage($route_name, $route_nid, $check_nid, $result, $message) {
$content_preprocess = new ContentPreprocess($this
->setupCurrentRouteMatch($route_name, $route_nid));
$node = $this
->setupNode($check_nid);
$this
->assertEquals($result, $content_preprocess
->isLatestVersionPage($node), $message);
}
/**
* Data provider for self::testIsLatestVersionPage().
*/
public function routeNodeProvider() {
return [
[
'entity.node.canonical',
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 $route_name
* The route to mock.
* @param int $nid
* The node ID for mocking.
*
* @return \Drupal\Core\Routing\CurrentRouteMatch
* The mocked current route match object.
*/
protected function setupCurrentRouteMatch($route_name, $nid) {
$route_match = $this
->prophesize(CurrentRouteMatch::class);
$route_match
->getRouteName()
->willReturn($route_name);
$route_match
->getParameter('node')
->willReturn($this
->setupNode($nid));
return $route_match
->reveal();
}
/**
* Mock a node object.
*
* @param int $nid
* The node ID to mock.
*
* @return \Drupal\node\Entity\Node
* The mocked node.
*/
protected function setupNode($nid) {
$node = $this
->prophesize(Node::class);
$node
->id()
->willReturn($nid);
return $node
->reveal();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentPreprocessTest:: |
public | function | Data provider for self::testIsLatestVersionPage(). | |
ContentPreprocessTest:: |
protected | function | Mock the current route matching object. | |
ContentPreprocessTest:: |
protected | function | Mock a node object. | |
ContentPreprocessTest:: |
public | function | @covers ::isLatestVersionPage @dataProvider routeNodeProvider | |
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 |