function CollectRoutesTest::testRoutesRequirements

Same name in other branches
  1. 9 core/modules/rest/tests/src/Unit/CollectRoutesTest.php \Drupal\Tests\rest\Unit\CollectRoutesTest::testRoutesRequirements()
  2. 8.9.x core/modules/rest/tests/src/Unit/CollectRoutesTest.php \Drupal\Tests\rest\Unit\CollectRoutesTest::testRoutesRequirements()
  3. 11.x core/modules/rest/tests/src/Unit/CollectRoutesTest.php \Drupal\Tests\rest\Unit\CollectRoutesTest::testRoutesRequirements()

Tests if adding a requirement to a route only modify one route.

File

core/modules/rest/tests/src/Unit/CollectRoutesTest.php, line 146

Class

CollectRoutesTest
Tests the REST export view plugin.

Namespace

Drupal\Tests\rest\Unit

Code

public function testRoutesRequirements() : void {
    $this->restExport
        ->collectRoutes($this->routes);
    $requirements_1 = $this->routes
        ->get('test_1')
        ->getRequirements();
    $requirements_2 = $this->routes
        ->get('view.test_view.page_1')
        ->getRequirements();
    $this->assertCount(0, $requirements_1, 'First route has no requirement.');
    $this->assertCount(1, $requirements_2, 'Views route with rest export had the format requirement added.');
    // Check auth options.
    $auth = $this->routes
        ->get('view.test_view.page_1')
        ->getOption('_auth');
    $this->assertCount(1, $auth, 'View route with rest export has an auth option added');
    $this->assertEquals('basic_auth', $auth[0], 'View route with rest export has the correct auth option added');
}

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