UpcastingTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/ParamConverter/UpcastingTest.php
View source
<?php
namespace Drupal\system\Tests\ParamConverter;
use Drupal\simpletest\WebTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
class UpcastingTest extends WebTestBase {
public static $modules = array(
'paramconverter_test',
'node',
'language',
);
public function testUpcasting() {
$node = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
));
$user = $this
->drupalCreateUser(array(
'access content',
));
$foo = 'bar';
$this
->drupalGet("paramconverter_test/test_user_node_foo/" . $user
->id() . '/' . $node
->id() . "/{$foo}");
$this
->assertRaw("user: {$user->label()}, node: {$node->label()}, foo: {$foo}", 'user and node upcast by entity name');
$this
->drupalGet("paramconverter_test/test_node_user_user/" . $node
->id() . "/" . $user
->id() . "/" . $user
->id());
$this
->assertRaw("user: {$user->label()}, node: {$node->label()}, foo: {$user->label()}", 'foo converted to user as well');
$this
->drupalGet("paramconverter_test/test_node_node_foo/" . $node
->id() . "/" . $node
->id() . "/{$foo}");
$this
->assertRaw("user: {$node->label()}, node: {$node->label()}, foo: {$foo}", 'user is upcast to node (rather than to user)');
}
public function testSameTypes() {
$node = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
));
$parent = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
));
$this
->drupalGet("paramconverter_test/node/" . $node
->id() . "/set/parent/" . $parent
->id());
$this
->assertRaw("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', array(
'de' => 'de',
))
->save();
$this
->rebuildContainer();
$node = $this
->drupalCreateNode(array(
'title' => 'English label',
));
$translation = $node
->addTranslation('de');
$translation
->setTitle('Deutscher Titel')
->save();
$this
->drupalGet("/paramconverter_test/node/" . $node
->id() . "/test_language");
$this
->assertRaw("English label");
$this
->drupalGet("paramconverter_test/node/" . $node
->id() . "/test_language", array(
'language' => $language,
));
$this
->assertRaw("Deutscher Titel");
}
}