View source
<?php
namespace Drupal\Tests\answers_core\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class QuestionCreationTest extends AnswersTestBase {
use StringTranslationTrait;
public static $modules = [
'answers_core',
'dblog',
];
protected $profile = 'standard';
protected function setUp() : void {
parent::setUp();
$web_user = $this
->drupalCreateUser([
'create answers_question content',
'edit own answers_question content',
'edit own comments',
'access comments',
'post comments',
]);
$this
->drupalLogin($web_user);
$this->accessHandler = \Drupal::entityTypeManager()
->getAccessControlHandler('node');
}
public function testQuestionCreation() {
$this
->drupalGet('node/add/answers_question');
$this
->assertNoFieldById('edit-revision', NULL, 'The revision checkbox is not present.');
$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'));
$this
->assertText($this
->t('@post @title has been created.', [
'@post' => 'Question',
'@title' => $edit['title[0][value]'],
]), 'Question created.');
$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');
$this
->assertLinkByHref('taxonomy/term/1');
$this
->assertLinkByHref('taxonomy/term/2');
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertNotEmpty($node, 'Node found in database.');
$this
->assertNoText($node
->getOwner()
->getAccountName());
$this
->assertNoText($this->container
->get('date.formatter')
->format($node
->getCreatedTime()));
$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');
}
}