public function SimplenewsSendTest::testUpdateNewsletter in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsSendTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSendTest::testUpdateNewsletter()
Test newsletter update.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- tests/
src/ Functional/ SimplenewsSendTest.php, line 405
Class
- SimplenewsSendTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\Tests\simplenews\FunctionalCode
public function testUpdateNewsletter() {
// Create a second newsletter.
$this
->drupalGet('admin/config/services/simplenews');
$this
->clickLink(t('Add newsletter'));
$edit = [
'name' => $this
->randomString(10),
'id' => strtolower($this
->randomMachineName(10)),
'description' => $this
->randomString(20),
];
$this
->submitForm($edit, 'Save');
$this
->assertText(t('Newsletter @name has been added', [
'@name' => $edit['name'],
]));
$this
->drupalGet('node/add/simplenews_issue');
$this
->assertText(t('Create Newsletter Issue'));
$first_newsletter_id = $this
->getRandomNewsletter();
$edit = [
'title[0][value]' => $this
->randomString(10),
'simplenews_issue[target_id]' => $first_newsletter_id,
];
$this
->submitForm($edit, 'Save');
$this
->assertEquals(1, preg_match('|node/(\\d+)$|', $this
->getUrl(), $matches), 'Node created.');
// Verify newsletter.
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache();
$node = Node::load($matches[1]);
$this
->assertEquals(SIMPLENEWS_STATUS_SEND_NOT, $node->simplenews_issue->status, t('Newsletter sending not started.'));
$this
->assertEquals($first_newsletter_id, $node->simplenews_issue->target_id);
do {
$second_newsletter_id = $this
->getRandomNewsletter();
} while ($first_newsletter_id == $second_newsletter_id);
$this
->clickLink(t('Edit'));
$update = [
'simplenews_issue[target_id]' => $second_newsletter_id,
];
$this
->submitForm($update, 'Save');
// Verify newsletter.
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache();
$node = Node::load($node
->id());
$this
->assertEquals(SIMPLENEWS_STATUS_SEND_NOT, $node->simplenews_issue->status, t('Newsletter sending not started.'));
$this
->assertEquals($second_newsletter_id, $node->simplenews_issue->target_id, t('Newsletter has newsletter_id @id.', [
'@id' => $second_newsletter_id,
]));
}