Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Definition of Drupal\node\Tests\NodeTranslationUITest.
*/
namespace Drupal\node\Tests;
Angie Byron
committed
use Drupal\Core\Entity\EntityInterface;
Alex Pott
committed
use Drupal\content_translation\Tests\ContentTranslationUITest;
Angie Byron
committed
/**
* Tests the Node Translation UI.
*/
Alex Pott
committed
class NodeTranslationUITest extends ContentTranslationUITest {
Angie Byron
committed
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'language', 'content_translation', 'node', 'datetime', 'field_ui');
Angie Byron
committed
public static function getInfo() {
return array(
'name' => 'Node translation UI',
'description' => 'Tests the node translation UI.',
'group' => 'Node',
);
}
function setUp() {
$this->entityType = 'node';
$this->bundle = 'article';
parent::setUp();
$this->drupalPlaceBlock('system_help_block', array('region' => 'content'));
Angie Byron
committed
}
/**
Alex Pott
committed
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::setupBundle().
Angie Byron
committed
*/
protected function setupBundle() {
parent::setupBundle();
$this->drupalCreateContentType(array('type' => $this->bundle, 'name' => $this->bundle));
}
/**
Alex Pott
committed
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getTranslatorPermission().
Angie Byron
committed
*/
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array('administer nodes', "edit any $this->bundle content"));
}
/**
Alex Pott
committed
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getNewEntityValues().
*/
protected function getNewEntityValues($langcode) {
return array('title' => $this->randomName()) + parent::getNewEntityValues($langcode);
}
/**
Alex Pott
committed
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getFormSubmitAction().
Angie Byron
committed
protected function getFormSubmitAction(EntityInterface $entity) {
catch
committed
if ($entity->isPublished()) {
Angie Byron
committed
return t('Save and unpublish');
}
return t('Save and keep unpublished');
}
/**
Alex Pott
committed
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::assertPublishedStatus().
*/
protected function assertPublishedStatus() {
$entity = entity_load($this->entityType, $this->entityId, TRUE);
$path = $this->controller->getEditPath($entity);
$languages = language_list();
$actions = array(
array(t('Save and publish'), t('Save and keep published')),
array(t('Save and unpublish'), t('Save and keep unpublished')),
);
foreach ($actions as $index => $status_actions) {
// (Un)publish the node translations and check that the translation
// statuses are (un)published accordingly.
foreach ($this->langcodes as $langcode) {
if (!empty($status_actions)) {
$action = array_shift($status_actions);
}
$this->drupalPostForm($path, array(), $action, array('language' => $languages[$langcode]));
}
$entity = entity_load($this->entityType, $this->entityId, TRUE);
foreach ($this->langcodes as $langcode) {
// The node is created as unpulished thus we switch to the published
// status first.
$status = !$index;
$this->assertEqual($status, $entity->translation[$langcode]['status'], 'The translation has been correctly unpublished.');
}
}
}
/**
Alex Pott
committed
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::assertAuthoringInfo().
*/
protected function assertAuthoringInfo() {
$entity = entity_load($this->entityType, $this->entityId, TRUE);
$path = $this->controller->getEditPath($entity);
$languages = language_list();
$values = array();
// Post different authoring information for each translation.
foreach ($this->langcodes as $index => $langcode) {
$user = $this->drupalCreateUser();
$values[$langcode] = array(
Dries Buytaert
committed
'uid' => $user->id(),
'created' => REQUEST_TIME - mt_rand(0, 1000),
);
$edit = array(
'name' => $user->getUsername(),
Dries Buytaert
committed
'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
);
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity), array('language' => $languages[$langcode]));
}
$entity = entity_load($this->entityType, $this->entityId, TRUE);
foreach ($this->langcodes as $langcode) {
$this->assertEqual($entity->translation[$langcode]['uid'] == $values[$langcode]['uid'], 'Translation author correctly stored.');
$this->assertEqual($entity->translation[$langcode]['created'] == $values[$langcode]['created'], 'Translation date correctly stored.');
}
Angie Byron
committed
}
Dries Buytaert
committed
/**
* Tests translate link on content admin page.
*/
function testTranslateLinkContentAdminPage() {
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
$this->drupalLogin($this->admin_user);
$page = $this->drupalCreateNode(array('type' => 'page'));
$article = $this->drupalCreateNode(array('type' => 'article'));
// Verify translation links.
$this->drupalGet('admin/content');
$this->assertResponse(200);
$this->assertLinkByHref('node/' . $article->id() . '/translations');
$this->assertNoLinkByHref('node/' . $page->id() . '/translations');
Dries Buytaert
committed
}
Angie Byron
committed
/**
* Tests field translation form.
*/
function testFieldTranslationForm() {
Angie Byron
committed
$admin_user = $this->drupalCreateUser(array_merge($this->getTranslatorPermissions(), array('access administration pages', 'bypass node access', 'administer node fields')));
Angie Byron
committed
$this->drupalLogin($admin_user);
$article = $this->drupalCreateNode(array('type' => 'article', 'langcode' => 'en'));
// Visit translation page.
$this->drupalGet('node/' . $article->id() . '/translations');
Angie Byron
committed
$this->assertRaw('Not translated');
// Delete the only translatable field.
field_info_field($this->entityType, 'field_test_et_ui_test')->delete();
Angie Byron
committed
// Visit translation page.
$this->drupalGet('node/' . $article->id() . '/translations');
Dries Buytaert
committed
$this->assertRaw('No translatable fields');
Angie Byron
committed
}
Angie Byron
committed
/**
Jennifer Hodgdon
committed
* Tests that no metadata is stored for a disabled bundle.
Angie Byron
committed
*/
public function testDisabledBundle() {
// Create a bundle that does not have translation enabled.
$disabledBundle = $this->randomName();
$this->drupalCreateContentType(array('type' => $disabledBundle, 'name' => $disabledBundle));
// Create a node for each bundle.
$enabledNode = $this->drupalCreateNode(array('type' => $this->bundle));
$disabledNode = $this->drupalCreateNode(array('type' => $disabledBundle));
// Make sure that only a single row was inserted into the
Alex Pott
committed
// {content_translation} table.
$rows = db_query('SELECT * FROM {content_translation}')->fetchAll();
Angie Byron
committed
$this->assertEqual(1, count($rows));
$this->assertEqual($enabledNode->id(), reset($rows)->entity_id);
}