NestedMatcherTest.php

Definition of Drupal\system\Tests\Routing\NestedMatcherTest.

Namespace

Drupal\system\Tests\Routing

File

drupal/core/modules/system/lib/Drupal/system/Tests/Routing/NestedMatcherTest.php
View source
<?php

/**
 * @file
 * Definition of Drupal\system\Tests\Routing\NestedMatcherTest.
 */
namespace Drupal\system\Tests\Routing;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Drupal\simpletest\UnitTestBase;
use Drupal\Core\Routing\HttpMethodMatcher;
use Drupal\Core\Routing\NestedMatcher;
use Drupal\Core\Routing\FirstEntryFinalMatcher;
use Exception;

/**
 * Basic tests for the NestedMatcher class.
 */
class NestedMatcherTest extends UnitTestBase {

  /**
   * A collection of shared fixture data for tests.
   *
   * @var RoutingFixtures
   */
  protected $fixtures;
  public static function getInfo() {
    return array(
      'name' => 'NestedMatcher tests',
      'description' => 'Confirm that the NestedMatcher system is working properly.',
      'group' => 'Routing',
    );
  }
  function __construct($test_id = NULL) {
    parent::__construct($test_id);
    $this->fixtures = new RoutingFixtures();
  }

  /**
   * Confirms we can nest multiple partial matchers.
   */
  public function testNestedMatcher() {
    $matcher = new NestedMatcher();
    $matcher
      ->setInitialMatcher(new MockPathMatcher($this->fixtures
      ->sampleRouteCollection()));
    $matcher
      ->addPartialMatcher(new HttpMethodMatcher(), 1);
    $matcher
      ->setFinalMatcher(new FirstEntryFinalMatcher());
    $request = Request::create('/path/one', 'GET');
    $attributes = $matcher
      ->matchRequest($request);
    $this
      ->assertEqual($attributes['_route']
      ->getOption('_name'), 'route_a', 'The correct matching route was found.');
  }

}

Classes

Namesort descending Description
NestedMatcherTest Basic tests for the NestedMatcher class.