public function SchedulerMultilingualTest::testPublishingTranslations in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerMultilingualTest.php \Drupal\Tests\scheduler\Functional\SchedulerMultilingualTest::testPublishingTranslations()
Test creating translations with independent scheduling.
@dataProvider dataPublishingTranslations()
File
- tests/
src/ Functional/ SchedulerMultilingualTest.php, line 117
Class
- SchedulerMultilingualTest
- Tests the scheduling functions for node translations.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testPublishingTranslations($publish_on_translatable, $unpublish_on_translatable, $status_translatable, array $expected_status_values_before, array $expected_status_values_after) {
// Show the languages, this is for info and debug only.
$this
->drupalGet('admin/config/regional/language');
// Set the scheduler fields to be translatable yes/no depending on the
// parameters passed in.
$this
->drupalGet('admin/config/regional/content-language');
$settings = [
'edit-settings-node-' . $this->type . '-settings-language-language-alterable' => TRUE,
'edit-settings-node-' . $this->type . '-fields-publish-on' => $publish_on_translatable,
'edit-settings-node-' . $this->type . '-fields-unpublish-on' => $unpublish_on_translatable,
'edit-settings-node-' . $this->type . '-fields-status' => $status_translatable,
];
// The submit shows the updated values, so no need for second get.
$this
->submitForm($settings, 'Save configuration');
if ($publish_on_translatable != $status_translatable) {
// Check for validation form error on status and publish_on.
$this
->assertSession()
->elementExists('xpath', '//input[@id = "edit-settings-node-' . $this->type . '-fields-publish-on" and contains(@class, "error")]');
$this
->assertSession()
->elementExists('xpath', '//input[@id = "edit-settings-node-' . $this->type . '-fields-status" and contains(@class, "error")]');
}
if ($unpublish_on_translatable != $status_translatable) {
// Check for validation form error on status and unpublish_on.
$this
->assertSession()
->elementExists('xpath', '//input[@id = "edit-settings-node-' . $this->type . '-fields-unpublish-on" and contains(@class, "error")]');
$this
->assertSession()
->elementExists('xpath', '//input[@id = "edit-settings-node-' . $this->type . '-fields-status" and contains(@class, "error")]');
}
if (empty($expected_status_values_before)) {
// The test data on this run was to verify the validation messages above.
// The rest of the test is meaningless so skip it and move to the next.
return;
}
$this
->assertSession()
->pageTextContains('Settings successfully updated.');
// Create a node in the 'original' language, before any translations. It is
// unpublished with no scheduled date.
$create = [
'type' => $this->type,
'title' => $this->languages[0]['name'] . '(0) - Unpublished and not scheduled',
'langcode' => $this->languages[0]['code'],
'status' => FALSE,
];
$node = $this
->drupalCreateNode($create);
$nid = $node
->id();
// Create the first translation, published now with no scheduled dates.
$this
->drupalGet('node/' . $nid . '/translations/add/' . $this->languages[0]['code'] . '/' . $this->languages[1]['code']);
$edit = [
'title[0][value]' => $this->languages[1]['name'] . '(1) - Published now',
'publish_on[0][value][date]' => '',
'publish_on[0][value][time]' => '',
'status[value]' => TRUE,
];
$this
->submitForm($edit, 'Save');
// Create second translation, for publishing and unpublishing in the future.
$this
->drupalGet('node/' . $nid . '/translations/add/' . $this->languages[0]['code'] . '/' . $this->languages[2]['code']);
$edit = [
'title[0][value]' => $this->languages[2]['name'] . '(2) - Publish in the future',
'publish_on[0][value][date]' => date('Y-m-d', strtotime('+2 day', $this->requestTime)),
'publish_on[0][value][time]' => date('H:i:s', strtotime('+2 day', $this->requestTime)),
'unpublish_on[0][value][date]' => date('Y-m-d', strtotime('+3 day', $this->requestTime)),
'unpublish_on[0][value][time]' => date('H:i:s', strtotime('+3 day', $this->requestTime)),
];
$this
->submitForm($edit, 'Save');
// Reset the cache, reload the node, and check if the dates of translation 2
// have been synchronized onto the other translations, or not, as required.
$this->nodeStorage
->resetCache([
$nid,
]);
$node = $this->nodeStorage
->load($nid);
$translation1 = $node
->getTranslation($this->languages[1]['code']);
$translation2 = $node
->getTranslation($this->languages[2]['code']);
if ($publish_on_translatable) {
$this
->assertNotEquals($translation2->publish_on->value, $node->publish_on->value, 'The original translation publish_on should not be synchronized');
$this
->assertNotEquals($translation2->unpublish_on->value, $node->unpublish_on->value, 'The original translation unpublish_on should not be synchronized');
$this
->assertNotEquals($translation2->publish_on->value, $translation1->publish_on->value, 'Translation1 publish_on should not be synchronized');
$this
->assertNotEquals($translation2->unpublish_on->value, $translation1->unpublish_on->value, 'Translation1 unpublish_on should not be synchronized');
}
else {
$this
->assertEquals($translation2->publish_on->value, $node->publish_on->value, 'The original translation publish_on should be synchronized');
$this
->assertEquals($translation2->unpublish_on->value, $node->unpublish_on->value, 'The original translation unpublish_on should be synchronized');
$this
->assertEquals($translation2
->isPublished(), $node
->isPublished(), 'The original translation status should be synchronized');
$this
->assertEquals($translation2->publish_on->value, $translation1->publish_on->value, 'Translation1 publish_on should be synchronized');
$this
->assertEquals($translation2->unpublish_on->value, $translation1->unpublish_on->value, 'Translation1 unpublish_on should be synchronized');
$this
->assertEquals($translation2
->isPublished(), $translation1
->isPublished(), 'Translation1 status should be synchronized');
}
// Create the third translation, to be published in the past.
$this
->drupalGet('node/' . $nid . '/translations/add/' . $this->languages[0]['code'] . '/' . $this->languages[3]['code']);
$edit = [
'title[0][value]' => $this->languages[3]['name'] . '(3) - Publish in the past',
'publish_on[0][value][date]' => date('Y-m-d', strtotime('-2 day', $this->requestTime)),
'publish_on[0][value][time]' => date('H:i:s', strtotime('-2 day', $this->requestTime)),
];
$this
->submitForm($edit, 'Save');
// Reset the cache, reload the node, and check if the dates of translation 3
// have been synchronized onto the other translations, or not, as required.
$this->nodeStorage
->resetCache([
$nid,
]);
$node = $this->nodeStorage
->load($nid);
$translation1 = $node
->getTranslation($this->languages[1]['code']);
$translation2 = $node
->getTranslation($this->languages[2]['code']);
$translation3 = $node
->getTranslation($this->languages[3]['code']);
if ($publish_on_translatable) {
$this
->assertNotEquals($translation3->publish_on->value, $translation2->publish_on->value, 'The original translation publish_on should not be synchronized');
$this
->assertNotEquals($translation3->unpublish_on->value, $translation2->unpublish_on->value, 'The original translation unpublish_on should not be synchronized');
}
else {
// The scheduer dates should be synchronized across all translations.
$this
->assertEquals($translation3->publish_on->value, $node->publish_on->value, 'The original translation publish_on should be synchronized');
$this
->assertEquals($translation3->unpublish_on->value, $node->unpublish_on->value, 'The original translation unpublish_on should be synchronized');
$this
->assertEquals($translation3
->isPublished(), $node
->isPublished(), 'The original translation status should be synchronized');
$this
->assertEquals($translation3->publish_on->value, $translation1->publish_on->value, 'Translation1 publish_on should be synchronized');
$this
->assertEquals($translation3->unpublish_on->value, $translation1->unpublish_on->value, 'Translation1 unpublish_on should be synchronized');
$this
->assertEquals($translation3
->isPublished(), $translation1
->isPublished(), 'Translation1 status should be synchronized');
$this
->assertEquals($translation3->publish_on->value, $translation2->publish_on->value, 'Translation2 publish_on should be synchronized');
$this
->assertEquals($translation3->unpublish_on->value, $translation2->unpublish_on->value, 'Translation2 unpublish_on should be synchronized');
$this
->assertEquals($translation3
->isPublished(), $translation2
->isPublished(), 'Translation2 status should be synchronized');
}
// For info only.
$this
->drupalGet($this->languages[0]['code'] . '/node/' . $nid . '/translations');
$this
->drupalGet('admin/content/scheduled');
// Check that the status of all four pieces of content before running cron
// match the expected values.
$this
->checkStatus($nid, 'Before cron', $expected_status_values_before);
// Check that the status after running cron matches the expected values.
$this
->cronRun();
$this
->checkStatus($nid, 'After cron', $expected_status_values_after);
// For info only.
$this
->drupalGet('admin/content/scheduled');
$this
->drupalGet('admin/content');
$this
->drupalGet('admin/reports/dblog');
$this
->drupalGet($this->languages[0]['code'] . '/node/' . $nid . '/translations');
}