Commit d5702e7b authored by webchick's avatar webchick

Issue #1688144 by Sweetchuck, lazysoundsystem: Fixed tnid does not updated to...

Issue #1688144 by Sweetchuck, lazysoundsystem: Fixed tnid does not updated to zero after node delete.
parent 4a677afc
......@@ -249,6 +249,55 @@ function testLanguageSwitcherBlockIntegration() {
$this->assertLanguageSwitchLinks($node, $node_it, TRUE, $type);
}
/**
* Delete a basic page with a translation.
*/
function testMultilanguageContentDelete() {
// Add Italian to have three items in the translation set.
$this->drupalLogin($this->admin_user);
$this->addLanguage('it');
$this->resetCaches();
$this->drupalLogin($this->translator);
// Create Basic page in English.
$node_title = $this->randomName();
$node_body = $this->randomName();
$nodes = array('en' => $this->createPage($node_title, $node_body, 'en'));
// Add Spanish translation.
$nodes['es'] = $this->createTranslation($nodes['en'], $this->randomName(), $this->randomName(), 'es');
// Reload the English node to get the updated tnid.
$nodes['en'] = node_load($nodes['en']->nid, NULL, TRUE);
// Add Italian translation.
// Use Spanish translation as source, rather than the original English one
// to check correct tnid handling in createTranslation().
$nodes['it'] = $this->createTranslation($nodes['es'], $this->randomName(), $this->randomName(), 'it');
// Delete the original translation source.
node_delete($nodes['en']->nid);
// Reload the remaining nodes.
$nodes['es'] = node_load($nodes['es']->nid, NULL, TRUE);
$nodes['it'] = node_load($nodes['it']->nid, NULL, TRUE);
// The new tnid is selected by the state of {node}.translate.
// As the original source node has been deleted, the new tnid could be
// generated from either remaining node.
$this->assertNotEqual($nodes['es']->tnid, 0, 'ES still in translation set.');
$this->assertNotEqual($nodes['it']->tnid, 0, 'IT still in translation set.');
$this->assertEqual($nodes['es']->tnid, $nodes['it']->tnid, 'ES and IT still in same translation set.');
// Delete the spanish node.
node_delete($nodes['es']->nid);
// Reload the italian node. This is the last one.
$nodes['it'] = node_load($nodes['it']->nid, NULL, TRUE);
// The tnid must be zero.
$this->assertEqual($nodes['it']->tnid, 0, 'Translation set is terminated.');
}
/**
* Resets static caches to make the test code match the client-side behavior.
*/
......@@ -298,7 +347,7 @@ function addLanguage($language_code) {
}
else {
// It's installed. No need to do anything.
$this->assertTrue(true, 'Language [' . $language_code . '] already installed.');
$this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed.');
}
}
......@@ -364,8 +413,11 @@ function createTranslation(Node $node, $title, $body, $langcode) {
// Check to make sure that translation was successful.
$translation = $this->drupalGetNodeByTitle($title);
// Maybe the source node was not in translation set,
// or it is not the base node of the translation set.
$tnid = (empty($node->tnid) ? $node->nid : $node->tnid);
$this->assertTrue($translation, t('Node found in database.'));
$this->assertTrue($translation->tnid == $node->nid, t('Translation set id correctly stored.'));
$this->assertTrue($translation->tnid == $tnid, 'Translation set id correctly stored.');
return $translation;
}
......
......@@ -413,8 +413,10 @@ function translation_remove_from_set($node) {
'tnid' => 0,
'translate' => 0,
));
if (db_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField() == 1) {
// There is only one node left in the set: remove the set altogether.
if (db_query('SELECT COUNT(nid) FROM {node} WHERE nid <> :nid AND tnid = :tnid', array(':nid' => $node->nid, ':tnid' => $node->tnid))->fetchField() == 1) {
// Apart from the node being deleted, only one node remains in the set:
// remove the set altogether
$query
->condition('tnid', $node->tnid)
->execute();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment