/** * {@inheritdoc} */ protected function createEntity($values, $langcode, $bundle_name = NULL) { $values['menu_name'] = 'tools'; $values['link']['uri'] = 'internal:/admin/structure/menu'; $values['title'] = 'Test title'; return parent::createEntity($values, $langcode, $bundle_name); }
protected function doTestBasicTranslation() { parent::doTestBasicTranslation(); $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); foreach ($this->langcodes as $langcode) { if ($entity->hasTranslation($langcode)) { $language = new Language(array('id' => $langcode)); // Request the front page in this language and assert that the right // translation shows up in the shortcut list with the right path. $this->drupalGet('<front>', array('language' => $language)); $expected_path = \Drupal::urlGenerator()->generateFromRoute('user.page', array(), array('language' => $language)); $label = $entity->getTranslation($langcode)->label(); $elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="toolbar-menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', array(':href' => $expected_path, ':label' => $label)); $this->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', array('@label' => $label, '@language' => $language->getName()))); } } }
/** * Tests translate link on comment content admin page. */ function testTranslateLinkCommentAdminPage() { $this->adminUser = $this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), array('access administration pages', 'administer comments', 'skip comment approval'))); $this->drupalLogin($this->adminUser); $cid_translatable = $this->createEntity(array(), $this->langcodes[0]); $cid_untranslatable = $this->createEntity(array(), $this->langcodes[0], 'comment'); // Verify translation links. $this->drupalGet('admin/content/comment'); $this->assertResponse(200); $this->assertLinkByHref('comment/' . $cid_translatable . '/translations'); $this->assertNoLinkByHref('comment/' . $cid_untranslatable . '/translations'); }
/** * {@inheritdoc} */ protected function doTestBasicTranslation() { parent::doTestBasicTranslation(); // Ensure that a block translation can be created using the same description // as in the original language. $default_langcode = $this->langcodes[0]; $values = $this->getNewEntityValues($default_langcode); $storage = \Drupal::entityManager()->getStorage($this->entityTypeId); /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $storage->create(array('type' => 'basic') + $values); $entity->save(); $entity->addTranslation('it', $values); try { $message = 'Blocks can have translations with the same "info" value.'; $entity->save(); $this->pass($message); } catch (\Exception $e) { $this->fail($message); } // Check that the translate operation link is shown. $this->drupalGet('admin/structure/block/block-content'); $this->assertLinkByHref('block/' . $entity->id() . '/translations'); }
/** * Overrides \Drupal\content_translation\Tests\ContentTranslationUITestBase::getNewEntityValues(). */ protected function getNewEntityValues($langcode) { // User name is not translatable hence we use a fixed value. return array('name' => $this->name) + parent::getNewEntityValues($langcode); }
/** * Tests translate link on vocabulary term list. */ function testTranslateLinkVocabularyAdminPage() { $this->drupalLogin($this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), ['access administration pages', 'administer taxonomy']))); $values = array('name' => $this->randomMachineName()); $translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id()); // Create an untranslatable vocabulary. $untranslatable_vocabulary = Vocabulary::create(['name' => 'untranslatable_voc', 'description' => $this->randomMachineName(), 'vid' => 'untranslatable_voc', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10)]); $untranslatable_vocabulary->save(); $values = array('name' => $this->randomMachineName()); $untranslatable_tid = $this->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary->id()); // Verify translation links. $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); $this->assertResponse(200, 'The translatable vocabulary page was found.'); $this->assertLinkByHref('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.'); $this->assertLinkByHref('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.'); $this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview'); $this->assertResponse(200); $this->assertLinkByHref('term/' . $untranslatable_tid . '/edit'); $this->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations'); }
/** * {@inheritdoc} */ protected function getNewEntityValues($langcode) { return array('title' => array(array('value' => $this->randomMachineName()))) + parent::getNewEntityValues($langcode); }