public function QuestionCreationTest::testQuestionCreation in Answers 1.0.x
Same name and namespace in other branches
- 2.0.x modules/core/tests/src/Functional/QuestionCreationTest.php \Drupal\Tests\answers_core\Functional\QuestionCreationTest::testQuestionCreation()
Creates a "Question" node and verifies its consistency in the database.
File
- modules/
core/ tests/ src/ Functional/ QuestionCreationTest.php, line 58
Class
- QuestionCreationTest
- Create a node and test saving it.
Namespace
Drupal\Tests\answers_core\FunctionalCode
public function testQuestionCreation() {
$this
->drupalGet('node/add/answers_question');
$this
->assertNoFieldById('edit-revision', NULL, 'The revision checkbox is not present.');
// Create a question node.
$edit = [];
$edit['title[0][value]'] = 'Woodchucks';
$edit['body[0][value]'] = '<p>How much wood can a woodchuck chuck, if a woodchuck could chuck word.</p>';
$edit['answers_tags[target_id]'] = 'drupal,phpunit';
$this
->drupalPostForm(NULL, $edit, $this
->t('Save'));
// Check that the Basic page has been created.
$this
->assertText($this
->t('@post @title has been created.', [
'@post' => 'Question',
'@title' => $edit['title[0][value]'],
]), 'Question created.');
// Verify that the creation message contains a link to a node.
$view_link = $this
->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [
':href' => 'node/',
]);
$this
->assert(isset($view_link), 'The message area contains a link to a node');
// Verify taxonomy tag links.
$this
->assertLinkByHref('taxonomy/term/1');
$this
->assertLinkByHref('taxonomy/term/2');
// Check that the node exists in the database.
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertNotEmpty($node, 'Node found in database.');
// Verify that pages do not show submitted information by default.
// $this->drupalGet('node/' . $node->id());
$this
->assertNoText($node
->getOwner()
->getAccountName());
$this
->assertNoText($this->container
->get('date.formatter')
->format($node
->getCreatedTime()));
// Answer the question.
$edit = [];
$edit['comment_body[0][value]'] = '<p>Exactly 42 cords of wood.</p>';
$form_id = 'comment-form--2';
$this
->drupalPostForm(NULL, $edit, $this
->t('Save'), [], $form_id);
$this
->assertText('1 Answer');
$edit = [];
$edit['comment_body[0][value]'] = '<p>This comment is for the questions</p>';
$form_id = 'comment-form';
$this
->drupalPostForm(NULL, $edit, $this
->t('Save'), [], $form_id);
$edit['comment_body[0][value]'] = '<p>This comment is for the an answer</p>';
$form_id = 'comment-form--2';
$this
->drupalPostForm(NULL, $edit, $this
->t('Save'), [], $form_id);
$edit = [];
$edit['comment_body[0][value]'] = '<p>The cords of wood are preportional to the density of the wood.</p>';
$form_id = 'comment-form--3';
$this
->drupalPostForm(NULL, $edit, $this
->t('Save'), [], $form_id);
$this
->assertText('2 Answers');
}