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;
10 * @coversDefaultClass \Drupal\content_moderation\ContentPreprocess
12 * @group content_moderation
14 class ContentPreprocessTest extends \PHPUnit_Framework_TestCase {
17 * @covers ::isLatestVersionPage
18 * @dataProvider routeNodeProvider
20 public function testIsLatestVersionPage($route_name, $route_nid, $check_nid, $result, $message) {
21 $content_preprocess = new ContentPreprocess($this->setupCurrentRouteMatch($route_name, $route_nid));
22 $node = $this->setupNode($check_nid);
23 $this->assertEquals($result, $content_preprocess->isLatestVersionPage($node), $message);
27 * Data provider for self::testIsLatestVersionPage().
29 public function routeNodeProvider() {
31 ['entity.node.canonical', 1, 1, FALSE, 'Not on the latest version tab route.'],
32 ['entity.node.latest_version', 1, 1, TRUE, 'On the latest version tab route, with the route node.'],
33 ['entity.node.latest_version', 1, 2, FALSE, 'On the latest version tab route, with a different node.'],
38 * Mock the current route matching object.
40 * @param string $route_name
43 * The node ID for mocking.
45 * @return \Drupal\Core\Routing\CurrentRouteMatch
46 * The mocked current route match object.
48 protected function setupCurrentRouteMatch($route_name, $nid) {
49 $route_match = $this->prophesize(CurrentRouteMatch::class);
50 $route_match->getRouteName()->willReturn($route_name);
51 $route_match->getParameter('node')->willReturn($this->setupNode($nid));
53 return $route_match->reveal();
60 * The node ID to mock.
62 * @return \Drupal\node\Entity\Node
65 protected function setupNode($nid) {
66 $node = $this->prophesize(Node::class);
67 $node->id()->willReturn($nid);
69 return $node->reveal();