3 namespace Drupal\Tests\content_moderation\Unit;
5 use Drupal\content_moderation\ContentPreprocess;
6 use Drupal\Core\Routing\CurrentRouteMatch;
7 use Drupal\node\Entity\Node;
8 use Drupal\Tests\UnitTestCase;
11 * @coversDefaultClass \Drupal\content_moderation\ContentPreprocess
13 * @group content_moderation
15 class ContentPreprocessTest extends UnitTestCase {
18 * @covers ::isLatestVersionPage
19 * @dataProvider routeNodeProvider
21 public function testIsLatestVersionPage($route_name, $route_nid, $check_nid, $result, $message) {
22 $content_preprocess = new ContentPreprocess($this->setupCurrentRouteMatch($route_name, $route_nid));
23 $node = $this->setupNode($check_nid);
24 $this->assertEquals($result, $content_preprocess->isLatestVersionPage($node), $message);
28 * Data provider for self::testIsLatestVersionPage().
30 public function routeNodeProvider() {
32 ['entity.node.canonical', 1, 1, FALSE, 'Not on the latest version tab route.'],
33 ['entity.node.latest_version', 1, 1, TRUE, 'On the latest version tab route, with the route node.'],
34 ['entity.node.latest_version', 1, 2, FALSE, 'On the latest version tab route, with a different node.'],
39 * Mock the current route matching object.
41 * @param string $route_name
44 * The node ID for mocking.
46 * @return \Drupal\Core\Routing\CurrentRouteMatch
47 * The mocked current route match object.
49 protected function setupCurrentRouteMatch($route_name, $nid) {
50 $route_match = $this->prophesize(CurrentRouteMatch::class);
51 $route_match->getRouteName()->willReturn($route_name);
52 $route_match->getParameter('node')->willReturn($this->setupNode($nid));
54 return $route_match->reveal();
61 * The node ID to mock.
63 * @return \Drupal\node\Entity\Node
66 protected function setupNode($nid) {
67 $node = $this->prophesize(Node::class);
68 $node->id()->willReturn($nid);
70 return $node->reveal();