Chris@0: entityTypeId = 'taxonomy_term'; Chris@0: $this->bundle = 'tags'; Chris@0: parent::setUp(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function setupBundle() { Chris@0: parent::setupBundle(); Chris@0: Chris@0: // Create a vocabulary. Chris@0: $this->vocabulary = Vocabulary::create([ Chris@0: 'name' => $this->bundle, Chris@0: 'description' => $this->randomMachineName(), Chris@0: 'vid' => $this->bundle, Chris@0: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: 'weight' => mt_rand(0, 10), Chris@0: ]); Chris@0: $this->vocabulary->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function getTranslatorPermissions() { Chris@0: return array_merge(parent::getTranslatorPermissions(), ['administer taxonomy']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function getNewEntityValues($langcode) { Chris@0: return ['name' => $this->randomMachineName()] + parent::getNewEntityValues($langcode); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns an edit array containing the values to be posted. Chris@0: */ Chris@0: protected function getEditValues($values, $langcode, $new = FALSE) { Chris@0: $edit = parent::getEditValues($values, $langcode, $new); Chris@0: Chris@0: // To be able to post values for the configurable base fields (name, Chris@0: // description) have to be suffixed with [0][value]. Chris@0: foreach ($edit as $property => $value) { Chris@0: foreach (['name', 'description'] as $key) { Chris@0: if ($property == $key) { Chris@0: $edit[$key . '[0][value]'] = $value; Chris@0: unset($edit[$property]); Chris@0: } Chris@0: } Chris@0: } Chris@0: return $edit; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function testTranslationUI() { Chris@0: parent::testTranslationUI(); Chris@0: Chris@0: // Make sure that no row was inserted for taxonomy vocabularies which do Chris@0: // not have translations enabled. Chris@0: $rows = db_query('SELECT tid, count(tid) AS count FROM {taxonomy_term_field_data} WHERE vid <> :vid GROUP BY tid', [':vid' => $this->bundle])->fetchAll(); Chris@0: foreach ($rows as $row) { Chris@0: $this->assertTrue($row->count < 2, 'Term does not have translations.'); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests translate link on vocabulary term list. Chris@0: */ Chris@0: public function testTranslateLinkVocabularyAdminPage() { Chris@0: $this->drupalLogin($this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), ['access administration pages', 'administer taxonomy']))); Chris@0: Chris@0: $values = [ Chris@0: 'name' => $this->randomMachineName(), Chris@0: ]; Chris@0: $translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id()); Chris@0: Chris@0: // Create an untranslatable vocabulary. Chris@0: $untranslatable_vocabulary = Vocabulary::create([ Chris@0: 'name' => 'untranslatable_voc', Chris@0: 'description' => $this->randomMachineName(), Chris@0: 'vid' => 'untranslatable_voc', Chris@0: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: 'weight' => mt_rand(0, 10), Chris@0: ]); Chris@0: $untranslatable_vocabulary->save(); Chris@0: Chris@0: $values = [ Chris@0: 'name' => $this->randomMachineName(), Chris@0: ]; Chris@0: $untranslatable_tid = $this->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary->id()); Chris@0: Chris@0: // Verify translation links. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); Chris@0: $this->assertResponse(200, 'The translatable vocabulary page was found.'); Chris@0: $this->assertLinkByHref('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.'); Chris@0: $this->assertLinkByHref('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.'); Chris@0: Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview'); Chris@0: $this->assertResponse(200); Chris@0: $this->assertLinkByHref('term/' . $untranslatable_tid . '/edit'); Chris@0: $this->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function doTestTranslationEdit() { Chris@0: $storage = $this->container->get('entity_type.manager') Chris@0: ->getStorage($this->entityTypeId); Chris@0: $storage->resetCache([$this->entityId]); Chris@0: $entity = $storage->load($this->entityId); Chris@0: $languages = $this->container->get('language_manager')->getLanguages(); Chris@0: Chris@0: foreach ($this->langcodes as $langcode) { Chris@0: // We only want to test the title for non-english translations. Chris@0: if ($langcode != 'en') { Chris@0: $options = ['language' => $languages[$langcode]]; Chris@18: $url = $entity->toUrl('edit-form', $options); Chris@0: $this->drupalGet($url); Chris@0: Chris@0: $title = t('@title [%language translation]', [ Chris@0: '@title' => $entity->getTranslation($langcode)->label(), Chris@0: '%language' => $languages[$langcode]->getName(), Chris@0: ]); Chris@0: $this->assertRaw($title); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }