UpcastingTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/ParamConverter/UpcastingTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\ParamConverter;
use Drupal\Tests\BrowserTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
class UpcastingTest extends BrowserTestBase {
protected static $modules = [
'paramconverter_test',
'node',
'language',
];
protected $defaultTheme = 'stark';
public function testUpcasting() {
$node = $this
->drupalCreateNode([
'title' => $this
->randomMachineName(8),
]);
$user = $this
->drupalCreateUser([
'access content',
]);
$foo = 'bar';
$this
->drupalGet("paramconverter_test/test_user_node_foo/" . $user
->id() . '/' . $node
->id() . "/{$foo}");
$this
->assertSession()
->pageTextContains("user: {$user->label()}, node: {$node->label()}, foo: {$foo}");
$this
->drupalGet("paramconverter_test/test_node_user_user/" . $node
->id() . "/" . $user
->id() . "/" . $user
->id());
$this
->assertSession()
->pageTextContains("user: {$user->label()}, node: {$node->label()}, foo: {$user->label()}");
$this
->drupalGet("paramconverter_test/test_node_node_foo/" . $node
->id() . "/" . $node
->id() . "/{$foo}");
$this
->assertSession()
->pageTextContains("user: {$node->label()}, node: {$node->label()}, foo: {$foo}");
}
public function testSameTypes() {
$node = $this
->drupalCreateNode([
'title' => $this
->randomMachineName(8),
]);
$parent = $this
->drupalCreateNode([
'title' => $this
->randomMachineName(8),
]);
$this
->drupalGet("paramconverter_test/node/" . $node
->id() . "/set/parent/" . $parent
->id());
$this
->assertSession()
->pageTextContains("Setting '" . $parent
->getTitle() . "' as parent of '" . $node
->getTitle() . "'.");
}
public function testEntityLanguage() {
$language = ConfigurableLanguage::createFromLangcode('de');
$language
->save();
\Drupal::configFactory()
->getEditable('language.negotiation')
->set('url.prefixes', [
'de' => 'de',
])
->save();
$this
->rebuildContainer();
$node = $this
->drupalCreateNode([
'title' => 'English label',
]);
$translation = $node
->addTranslation('de');
$translation
->setTitle('Deutscher Titel')
->save();
$this
->drupalGet("/paramconverter_test/node/" . $node
->id() . "/test_language");
$this
->assertSession()
->pageTextContains("English label");
$this
->drupalGet("paramconverter_test/node/" . $node
->id() . "/test_language", [
'language' => $language,
]);
$this
->assertSession()
->pageTextContains("Deutscher Titel");
}
}