You are here

public function DecoupledRouterFunctionalTest::testNegotiationNoMultilingual in Decoupled Router 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/DecoupledRouterFunctionalTest.php \Drupal\Tests\decoupled_router\Functional\DecoupledRouterFunctionalTest::testNegotiationNoMultilingual()

Tests reading multilingual content.

File

tests/src/Functional/DecoupledRouterFunctionalTest.php, line 125

Class

DecoupledRouterFunctionalTest
Test class.

Namespace

Drupal\Tests\decoupled_router\Functional

Code

public function testNegotiationNoMultilingual() {

  // This is not build with data providers to avoid rebuilding the environment
  // each test.
  $make_assertions = function ($path, DecoupledRouterFunctionalTest $test) {
    $res = $test
      ->drupalGet(Url::fromRoute('decoupled_router.path_translation'), [
      'query' => [
        'path' => $path,
        '_format' => 'json',
      ],
    ]);
    $test
      ->assertSession()
      ->statusCodeEquals(200);
    $output = Json::decode($res);
    $test
      ->assertStringEndsWith('/node--0', $output['resolved']);
    $test
      ->assertSame($test->nodes[0]
      ->id(), $output['entity']['id']);
    $test
      ->assertSame('node--article', $output['jsonapi']['resourceName']);
    $test
      ->assertStringEndsWith('/jsonapi/node/article/' . $test->nodes[0]
      ->uuid(), $output['jsonapi']['individual']);
  };
  $base_path = $this
    ->getBasePath();

  // Test cases:
  $test_cases = [
    // 1. Test negotiation by system path for /node/1 -> /node--0.
    $base_path . '/node/1',
    // 2. Test negotiation by alias for /node--0.
    $base_path . '/node--0',
    // 3. Test negotiation by multiple redirects for /bar -> /foo -> /node--0.
    $base_path . '/bar',
  ];
  array_walk($test_cases, function ($test_case) use ($make_assertions) {
    $make_assertions($test_case, $this);
  });
}