X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FTests%2FCommentTranslationUITest.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FTests%2FCommentTranslationUITest.php;h=0000000000000000000000000000000000000000;hp=4613d66ecc707e07a18f1363ea88016d6a1d0db2;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/comment/src/Tests/CommentTranslationUITest.php b/web/core/modules/comment/src/Tests/CommentTranslationUITest.php deleted file mode 100644 index 4613d66ec..000000000 --- a/web/core/modules/comment/src/Tests/CommentTranslationUITest.php +++ /dev/null @@ -1,225 +0,0 @@ -entityTypeId = 'comment'; - $this->nodeBundle = 'article'; - $this->bundle = 'comment_article'; - $this->testLanguageSelector = FALSE; - $this->subject = $this->randomMachineName(); - parent::setUp(); - } - - /** - * {@inheritdoc} - */ - public function setupBundle() { - parent::setupBundle(); - $this->drupalCreateContentType(['type' => $this->nodeBundle, 'name' => $this->nodeBundle]); - // Add a comment field to the article content type. - $this->addDefaultCommentField('node', 'article', 'comment_article', CommentItemInterface::OPEN, 'comment_article'); - // Create a page content type. - $this->drupalCreateContentType(['type' => 'page', 'name' => 'page']); - // Add a comment field to the page content type - this one won't be - // translatable. - $this->addDefaultCommentField('node', 'page', 'comment'); - // Mark this bundle as translatable. - $this->container->get('content_translation.manager')->setEnabled('comment', 'comment_article', TRUE); - } - - /** - * {@inheritdoc} - */ - protected function getTranslatorPermissions() { - return array_merge(parent::getTranslatorPermissions(), ['post comments', 'administer comments', 'access comments']); - } - - /** - * {@inheritdoc} - */ - protected function createEntity($values, $langcode, $comment_type = 'comment_article') { - if ($comment_type == 'comment_article') { - // This is the article node type, with the 'comment_article' field. - $node_type = 'article'; - $field_name = 'comment_article'; - } - else { - // This is the page node type with the non-translatable 'comment' field. - $node_type = 'page'; - $field_name = 'comment'; - } - $node = $this->drupalCreateNode([ - 'type' => $node_type, - $field_name => [ - ['status' => CommentItemInterface::OPEN] - ], - ]); - $values['entity_id'] = $node->id(); - $values['entity_type'] = 'node'; - $values['field_name'] = $field_name; - $values['uid'] = $node->getOwnerId(); - return parent::createEntity($values, $langcode, $comment_type); - } - - /** - * {@inheritdoc} - */ - protected function getNewEntityValues($langcode) { - // Comment subject is not translatable hence we use a fixed value. - return [ - 'subject' => [['value' => $this->subject]], - 'comment_body' => [['value' => $this->randomMachineName(16)]], - ] + parent::getNewEntityValues($langcode); - } - - /** - * {@inheritdoc} - */ - protected function doTestPublishedStatus() { - $entity_manager = \Drupal::entityManager(); - $storage = $entity_manager->getStorage($this->entityTypeId); - - $storage->resetCache(); - $entity = $storage->load($this->entityId); - - // Unpublish translations. - foreach ($this->langcodes as $index => $langcode) { - if ($index > 0) { - $edit = ['status' => 0]; - $url = $entity->urlInfo('edit-form', ['language' => ConfigurableLanguage::load($langcode)]); - $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode)); - $storage->resetCache(); - $entity = $storage->load($this->entityId); - $this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($langcode))->isPublished(), 'The translation has been correctly unpublished.'); - } - } - } - - /** - * {@inheritdoc} - */ - protected function doTestAuthoringInfo() { - $storage = $this->container->get('entity_type.manager') - ->getStorage($this->entityTypeId); - $storage->resetCache([$this->entityId]); - $entity = $storage->load($this->entityId); - $languages = $this->container->get('language_manager')->getLanguages(); - $values = []; - - // Post different authoring information for each translation. - foreach ($this->langcodes as $langcode) { - $url = $entity->urlInfo('edit-form', ['language' => $languages[$langcode]]); - $user = $this->drupalCreateUser(); - $values[$langcode] = [ - 'uid' => $user->id(), - 'created' => REQUEST_TIME - mt_rand(0, 1000), - ]; - $edit = [ - 'uid' => $user->getUsername() . ' (' . $user->id() . ')', - 'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), - 'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), - ]; - $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode)); - } - - $storage->resetCache([$this->entityId]); - $entity = $storage->load($this->entityId); - foreach ($this->langcodes as $langcode) { - $metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode)); - $this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.'); - $this->assertEqual($metadata->getCreatedTime(), $values[$langcode]['created'], 'Translation date correctly stored.'); - } - } - - /** - * Tests translate link on comment content admin page. - */ - public function testTranslateLinkCommentAdminPage() { - $this->adminUser = $this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), ['access administration pages', 'administer comments', 'skip comment approval'])); - $this->drupalLogin($this->adminUser); - - $cid_translatable = $this->createEntity([], $this->langcodes[0]); - $cid_untranslatable = $this->createEntity([], $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 doTestTranslationEdit() { - $storage = $this->container->get('entity_type.manager') - ->getStorage($this->entityTypeId); - $storage->resetCache([$this->entityId]); - $entity = $storage->load($this->entityId); - $languages = $this->container->get('language_manager')->getLanguages(); - - foreach ($this->langcodes as $langcode) { - // We only want to test the title for non-english translations. - if ($langcode != 'en') { - $options = ['language' => $languages[$langcode]]; - $url = $entity->urlInfo('edit-form', $options); - $this->drupalGet($url); - - $title = t('Edit @type @title [%language translation]', [ - '@type' => $this->entityTypeId, - '@title' => $entity->getTranslation($langcode)->label(), - '%language' => $languages[$langcode]->getName(), - ]); - $this->assertRaw($title); - } - } - } - -}