You are here

class WorkbenchPreprocessTest in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/WorkbenchPreprocessTest.php \Drupal\Tests\workbench_moderation\Unit\WorkbenchPreprocessTest

Class WorkbenchPreprocessTest.

@coversDefaultClass \Drupal\workbench_moderation\WorkbenchPreprocess @group workbench_moderation

Hierarchy

Expanded class hierarchy of WorkbenchPreprocessTest

File

tests/src/Unit/WorkbenchPreprocessTest.php, line 16

Namespace

Drupal\Tests\workbench_moderation\Unit
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340
WorkbenchPreprocessTest::routeNodeProvider public function Route node provider.
WorkbenchPreprocessTest::setupCurrentRouteMatch protected function Mock the current route matching object.
WorkbenchPreprocessTest::setupNode protected function Mock a node object.
WorkbenchPreprocessTest::testIsLatestVersionPage public function @covers ::isLatestVersionPage @dataProvider routeNodeProvider