Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / content_moderation / tests / src / Unit / ContentPreprocessTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Unit;
4
5 use Drupal\content_moderation\ContentPreprocess;
6 use Drupal\Core\Routing\CurrentRouteMatch;
7 use Drupal\node\Entity\Node;
8 use Drupal\Tests\UnitTestCase;
9
10 /**
11  * @coversDefaultClass \Drupal\content_moderation\ContentPreprocess
12  *
13  * @group content_moderation
14  */
15 class ContentPreprocessTest extends UnitTestCase {
16
17   /**
18    * @covers ::isLatestVersionPage
19    * @dataProvider routeNodeProvider
20    */
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);
25   }
26
27   /**
28    * Data provider for self::testIsLatestVersionPage().
29    */
30   public function routeNodeProvider() {
31     return [
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.'],
35     ];
36   }
37
38   /**
39    * Mock the current route matching object.
40    *
41    * @param string $route_name
42    *   The route to mock.
43    * @param int $nid
44    *   The node ID for mocking.
45    *
46    * @return \Drupal\Core\Routing\CurrentRouteMatch
47    *   The mocked current route match object.
48    */
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));
53
54     return $route_match->reveal();
55   }
56
57   /**
58    * Mock a node object.
59    *
60    * @param int $nid
61    *   The node ID to mock.
62    *
63    * @return \Drupal\node\Entity\Node
64    *   The mocked node.
65    */
66   protected function setupNode($nid) {
67     $node = $this->prophesize(Node::class);
68     $node->id()->willReturn($nid);
69
70     return $node->reveal();
71   }
72
73 }