View source
<?php
namespace Drupal\forward\Tests;
class ForwardFormTest extends ForwardTestBase {
public function testForwardForm() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/user-interface/forward');
$edit = [
'forward_node_types[article]' => 'article',
'forward_view_modes[full]' => 'full',
'forward_personal_message' => 2,
];
$this
->drupalPostForm(NULL, $edit, t('Save configuration'));
$article = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalLogin($this->forwardUser);
$this
->drupalGet('node/' . $article
->id());
$this
->assertText(t('Email this article'), t('The article has a Forward link.'));
$this
->drupalGet('/forward/node/' . $article
->id());
$this
->assertText(t('Forward this article to a friend'), 'The Forward form displays for an article.');
$edit = [
'email' => 'test@test.com',
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
'message' => 'This is a test personal message.',
];
$this
->drupalPostForm(NULL, $edit, t('Send Message'));
$this
->assertText(t('Thank you for spreading the word about Drupal.'), 'The Forward form displays a thank you message after submit.');
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'email' => 'test@test.com',
'name' => 'Test Forwarder',
'message' => 'This is a test personal message.',
];
$this
->drupalPostForm(NULL, $edit, t('Send Message'));
$this
->assertText(t('Send to field is required.'), 'The Forward form displays an error message when the recipient is blank.');
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'email' => 'test@test.com',
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
];
$this
->drupalPostForm(NULL, $edit, t('Send Message'));
$this
->assertText(t('Your personal message field is required.'), 'The Forward form displays an error message when the message is blank and one is required.');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/user-interface/forward');
$edit = [
'forward_personal_message' => 1,
];
$this
->drupalPostForm(NULL, $edit, t('Save configuration'));
$this
->drupalLogin($this->forwardUser);
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'email' => 'test@test.com',
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
];
$this
->drupalPostForm(NULL, $edit, t('Send Message'));
$this
->assertNoText(t('Your personal message field is required.'), 'The Forward form does not display an error message when the message is blank and optional.');
}
}