I would like to test creating a node of a specific type, translating the node and then checking if the page contains specific text. Here is the code I’m using but I’m getting an error ‘testReadTimeTranslation DrupalCoreEntityEntityStorageException: Creating default object from empty value’
<?php namespace DrupalTestsabc_readtimeFunctional; use DrupalTestsBrowserTestBase; /** * Tests Readtime String Translation. * */ class AbcReadTimeLiveTest extends BrowserTestBase { /** * A test user with administrative privileges. * * @var DrupaluserUserInterface */ protected $adminUser; // phpcs:disable /** * Disabled config schema checking temporarily until all errors are resolved. */ protected $strictConfigSchema = FALSE; // phpcs:enable /** * Modules to enable. * * @var array */ public static $modules = ['block', 'filter', 'node', 'language', 'abc_language', 'lingotek']; /** * {@inheritdoc} */ protected $defaultTheme = 'classy'; /** * {@inheritdoc} */ protected function setUp() :void { parent::setUp(); $this->drupalLogin($this->rootUser); // Create and log in an administrative user. $this->adminUser = $this->drupalCreateUser([ 'administer site configuration', 'access administration pages', ]); } /** * Tests translate block . */ public function testReadTimeTranslation() { // Add file to node. $node = $this->drupalCreateNode([ 'type' => 'article_research', 'title' => 'Test Readtime', 'body' => [['value' => 'Then she picked out two somebodies,<br />Sally and me', 'format' => 'basic_html']], ]); $node->save(); $translation_node = $node->addTranslation('es'); $translation_node->setTitle('Spanish'); $translation_node->setPublished(TRUE); $translation_node->save(); // Get node. $this->drupalGet('node/' . $node->id()); $this->assertSession()->pageTextContains('Hora de leer: Sobre'); // Delete the translated node. $translation_node->delete(); // Get node. $this->drupalGet('node/' . $node->id()); $this->assertSession()->pageTextContains('Time to Read: About'); } }