function UrlAlterFunctionalTest::testUrlAlter

Same name in this branch
  1. 10 core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
Same name and namespace in other branches
  1. 7.x modules/simpletest/tests/path.test \UrlAlterFunctionalTest::testUrlAlter()
  2. 9 core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
  3. 8.9.x core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
  4. 11.x core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
  5. 11.x core/modules/forum/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\forum\Functional\UrlAlterFunctionalTest::testUrlAlter()

Tests that URL altering works and that it occurs in the correct order.

File

core/modules/forum/tests/src/Functional/UrlAlterFunctionalTest.php, line 34

Class

UrlAlterFunctionalTest
Tests altering the inbound path and the outbound path.

Namespace

Drupal\Tests\forum\Functional

Code

public function testUrlAlter() : void {
  // Ensure that the path_alias table exists after Drupal installation.
  $this->assertTrue(Database::getConnection()->schema()
    ->tableExists('path_alias'), 'The path_alias table exists after Drupal installation.');
  // Test that 'forum' is altered to 'community' correctly, both at the root
  // level and for a specific existing forum.
  $this->drupalGet('community');
  $this->assertSession()
    ->pageTextContains('General discussion');
  $this->assertUrlOutboundAlter('/forum', '/community');
  $forum_vid = $this->config('forum.settings')
    ->get('vocabulary');
  $term_name = $this->randomMachineName();
  $term = Term::create([
    'name' => $term_name,
    'vid' => $forum_vid,
  ]);
  $term->save();
  $this->drupalGet("community/" . $term->id());
  $this->assertSession()
    ->pageTextContains($term_name);
  $this->assertUrlOutboundAlter("/forum/" . $term->id(), "/community/" . $term->id());
}

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