You are here

function SimplenewsSendTest::testUpdateNewsletter in Simplenews 8

File

src/Tests/SimplenewsSendTest.php, line 405
Simplenews send test functions.

Class

SimplenewsSendTest
Test cases for creating and sending newsletters.

Namespace

Drupal\simplenews\Tests

Code

function testUpdateNewsletter() {

  // Create a second newsletter.
  $this
    ->drupalGet('admin/config/services/simplenews');
  $this
    ->clickLink(t('Add newsletter'));
  $edit = array(
    'name' => $this
      ->randomString(10),
    'id' => strtolower($this
      ->randomMachineName(10)),
    'description' => $this
      ->randomString(20),
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertText(t('Newsletter @name has been added', array(
    '@name' => $edit['name'],
  )));
  $this
    ->drupalGet('node/add/simplenews_issue');
  $this
    ->assertText(t('Create Newsletter Issue'));
  $first_newsletter_id = $this
    ->getRandomNewsletter();
  $edit = array(
    'title[0][value]' => $this
      ->randomString(10),
    'simplenews_issue' => $first_newsletter_id,
  );
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertTrue(preg_match('|node/(\\d+)$|', $this
    ->getUrl(), $matches), 'Node created.');

  // Verify newsletter.
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  $node = Node::load($matches[1]);
  $this
    ->assertEqual(SIMPLENEWS_STATUS_SEND_NOT, $node->simplenews_issue->status, t('Newsletter sending not started.'));
  $this
    ->assertEqual($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 = array(
    'simplenews_issue' => $second_newsletter_id,
  );
  $this
    ->drupalPostForm(NULL, $update, t('Save'));

  // Verify newsletter.
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  $node = Node::load($node
    ->id());
  $this
    ->assertEqual(SIMPLENEWS_STATUS_SEND_NOT, $node->simplenews_issue->status, t('Newsletter sending not started.'));
  $this
    ->assertEqual($second_newsletter_id, $node->simplenews_issue->target_id, t('Newsletter has newsletter_id ' . $second_newsletter_id . '.'));
}