HreflangContentTranslationTest.php in Hreflang 8
File
tests/src/Functional/HreflangContentTranslationTest.php
View source
<?php
namespace Drupal\Tests\hreflang\Functional;
use Drupal\Tests\node\Functional\NodeTestBase;
class HreflangContentTranslationTest extends NodeTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'hreflang',
'content_translation',
];
public function testHreflangTag() {
global $base_url;
$admin_user = $this
->drupalCreateUser([
'administer languages',
'administer site configuration',
'create page content',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/regional/language/add');
$edit = [
'predefined_langcode' => 'fr',
];
$this
->submitForm($edit, 'Add language');
$this
->drupalGet('node/add/page');
$edit = [
'title[0][value]' => 'Test front page',
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/config/system/site-information');
$edit = [
'site_frontpage' => '/node/1',
];
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('');
$this
->assertSession()
->responseContains('<link rel="alternate" hreflang="en" href="' . $base_url . '/" />');
$this
->assertSession()
->responseContains('<link rel="alternate" hreflang="fr" href="' . $base_url . '/fr" />');
$this
->assertSession()
->responseNotContains('<link rel="alternate" hreflang="en" href="' . $base_url . '/node/1" />');
$this
->assertSession()
->responseNotContains('<link rel="alternate" hreflang="fr" href="' . $base_url . '/fr/node/1" />');
$this
->drupalGet('fr');
$this
->assertSession()
->responseContains('<link rel="alternate" hreflang="en" href="' . $base_url . '/" />');
$this
->assertSession()
->responseContains('<link rel="alternate" hreflang="fr" href="' . $base_url . '/fr" />');
$this
->assertSession()
->responseNotContains('<link rel="alternate" hreflang="en" href="' . $base_url . '/node/1" />');
$this
->assertSession()
->responseNotContains('<link rel="alternate" hreflang="fr" href="' . $base_url . '/fr/node/1" />');
}
}