class ContentPreprocessTest

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php \Drupal\Tests\content_moderation\Unit\ContentPreprocessTest
  2. 8.9.x core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php \Drupal\Tests\content_moderation\Unit\ContentPreprocessTest
  3. 11.x core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php \Drupal\Tests\content_moderation\Unit\ContentPreprocessTest

@coversDefaultClass \Drupal\content_moderation\ContentPreprocess

@group content_moderation

Hierarchy

Expanded class hierarchy of ContentPreprocessTest

File

core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php, line 17

Namespace

Drupal\Tests\content_moderation\Unit
View source
class ContentPreprocessTest extends UnitTestCase {
    
    /**
     * @covers ::isLatestVersionPage
     * @dataProvider routeNodeProvider
     */
    public function testIsLatestVersionPage($route_name, $route_nid, $check_nid, $result, $message) : void {
        $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 static 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

Title Sort descending Deprecated Modifiers Object type Summary Overrides
ContentPreprocessTest::routeNodeProvider public static function Data provider for self::testIsLatestVersionPage().
ContentPreprocessTest::setupCurrentRouteMatch protected function Mock the current route matching object.
ContentPreprocessTest::setupNode protected function Mock a node object.
ContentPreprocessTest::testIsLatestVersionPage public function @covers ::isLatestVersionPage
@dataProvider routeNodeProvider
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 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::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUp protected function 358
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.