assertUrlOutboundAlter example

/** * Tests that URL altering works and that it occurs in the correct order. */
  public function testUrlAlter() {
    // 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());
  }

  
// User names can have quotes and plus signs so we should ensure that URL     // altering works with this.     $account = $this->drupalCreateUser(['administer url aliases'], "it's+bar");
    $this->drupalLogin($account);

    $uid = $account->id();
    $name = $account->getAccountName();

    // Test a single altered path.     $this->drupalGet("user/$name");
    $this->assertSession()->statusCodeEquals(200);
    $this->assertUrlOutboundAlter("/user/$uid", "/user/$name");

    // Test that a path always uses its alias.     $this->createPathAlias("/user/$uid/test1", '/alias/test1');
    $this->rebuildContainer();
    $this->assertUrlInboundAlter('/alias/test1', "/user/$uid/test1");
    $this->assertUrlOutboundAlter("/user/$uid/test1", '/alias/test1');

    // Test adding an alias via the UI.     $edit = ['path[0][value]' => "/user/$uid/edit", 'alias[0][value]' => '/alias/test2'];
    $this->drupalGet('admin/config/search/path/add');
    $this->submitForm($edit, 'Save');
    
Home | Imprint | This part of the site doesn't use cookies.