TourTest.php

Same filename in this branch
  1. 9 core/modules/jsonapi/tests/src/Functional/TourTest.php
  2. 9 core/modules/tour/tests/src/Functional/TourTest.php
Same filename in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/TourTest.php
  2. 8.9.x core/modules/tour/tests/src/Unit/Entity/TourTest.php
  3. 8.9.x core/modules/tour/tests/src/Functional/TourTest.php
  4. 10 core/modules/tour/tests/src/Unit/Entity/TourTest.php
  5. 10 core/modules/tour/tests/src/Functional/TourTest.php
  6. 10 core/modules/tour/tests/src/Functional/Jsonapi/TourTest.php
  7. 11.x core/modules/tour/tests/src/Unit/Entity/TourTest.php
  8. 11.x core/modules/tour/tests/src/Functional/TourTest.php
  9. 11.x core/modules/tour/tests/src/Functional/Jsonapi/TourTest.php

Namespace

Drupal\Tests\tour\Unit\Entity

File

core/modules/tour/tests/src/Unit/Entity/TourTest.php

View source
<?php

namespace Drupal\Tests\tour\Unit\Entity;

use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\tour\Entity\Tour
 * @group tour
 */
class TourTest extends UnitTestCase {
    
    /**
     * Tests \Drupal\tour\Entity\Tour::hasMatchingRoute().
     *
     * @param array $routes
     *   Array of routes as per the Tour::routes property.
     * @param string $route_name
     *   The route name to match.
     * @param array $route_params
     *   Array of route params.
     * @param bool $result
     *   Expected result.
     *
     * @covers ::hasMatchingRoute
     *
     * @dataProvider routeProvider
     */
    public function testHasMatchingRoute($routes, $route_name, $route_params, $result) {
        $tour = $this->getMockBuilder('\\Drupal\\tour\\Entity\\Tour')
            ->disableOriginalConstructor()
            ->onlyMethods([
            'getRoutes',
        ])
            ->getMock();
        $tour->expects($this->any())
            ->method('getRoutes')
            ->willReturn($routes);
        $this->assertSame($result, $tour->hasMatchingRoute($route_name, $route_params));
        $tour->resetKeyedRoutes();
    }
    
    /**
     * Provides sample routes for testing.
     */
    public function routeProvider() {
        return [
            // Simple match.
[
                [
                    [
                        'route_name' => 'some.route',
                    ],
                ],
                'some.route',
                [],
                TRUE,
            ],
            // Simple non-match.
[
                [
                    [
                        'route_name' => 'another.route',
                    ],
                ],
                'some.route',
                [],
                FALSE,
            ],
            // Empty params.
[
                [
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'foo' => 'bar',
                        ],
                    ],
                ],
                'some.route',
                [],
                FALSE,
            ],
            // Match on params.
[
                [
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'foo' => 'bar',
                        ],
                    ],
                ],
                'some.route',
                [
                    'foo' => 'bar',
                ],
                TRUE,
            ],
            // Non-matching params.
[
                [
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'foo' => 'bar',
                        ],
                    ],
                ],
                'some.route',
                [
                    'bar' => 'foo',
                ],
                FALSE,
            ],
            // One matching, one not.
[
                [
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'foo' => 'bar',
                        ],
                    ],
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'bar' => 'foo',
                        ],
                    ],
                ],
                'some.route',
                [
                    'bar' => 'foo',
                ],
                TRUE,
            ],
            // One matching, one not.
[
                [
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'foo' => 'bar',
                        ],
                    ],
                    [
                        'route_name' => 'some.route',
                        'route_params' => [
                            'foo' => 'baz',
                        ],
                    ],
                ],
                'some.route',
                [
                    'foo' => 'baz',
                ],
                TRUE,
            ],
        ];
    }

}

Classes

Title Deprecated Summary
TourTest @coversDefaultClass \Drupal\tour\Entity\Tour @group tour

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