Newer
Older
Alastair Aitchison
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* @file
* Simpletests for Question Fields 7.x.
*
* Verify Question fields functionality.
*/
/**
* Functionality tests for question module.
*/
class QuestionFieldsTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Question Fields',
'description' => 'Verify functionality of the question fields module.',
'group' => 'Question',
);
}
function setUp() {
// Enable the module.
parent::setUp('question', 'question_fields');
// Create a user that has the privilege to ask questions
$this->question_user = $this->drupalCreateUser(array('ask questions'));
// Create a user that has the privilege to manage questions
$this->question_admin_user = $this->drupalCreateUser(array('view questions', 'answer questions', 'delete questions'));
// Create a site admin user
$this->site_admin_user = $this->drupalCreateUser(array('administer site configuration'));
}
/**
* Verify the functionality of the example module.
*/
function testQuestionCreation() {
// Login as a site admin user
$this->drupalLogin($this->question_user);
// Check that unauthorised users cannot ask questions
$this->drupalGet('question');
$this->assertFieldByName('questioner', '', t("Question submission form contains field for questioner name"));
$this->assertFieldByName('age', '', t("Question submission form contains field for age"));
$this->assertFieldByName('sex', '', t("Question submission form contains field for sex"));
// Ask a question
$this->drupalPost(
'question', // The menu item of the form
array(
'question' => 'This is a test question',
'questioner' => 'Bob',
'age' => '10',
'sex' => 'M',
),
t('Submit Question')
);
// Check that there is one question in the database
$count = db_query('SELECT COUNT(*) FROM {question_queue} q INNER JOIN {question_fields} qf ON q.qid = qf.qid')->fetchField();
$this->assertEqual($count, 1, t("There is one question with additional fields in the question queue table."));
// Login as question admin user
$this->drupalLogout($this->question_user);
$this->drupalLogin($this->question_admin_user);
// Check that the questions appear on the queue page
$this->drupalGet('admin/content/question');
$this->assertPattern("/Bob.*10.*M/s", t("Additional field values found on question queue page"));
// Go to the page to answer the first question
$this->drupalGet('node/add/question/1');
$this->assertFieldByName('question_fields_questioner[und][0][value]', 'Bob', t("The questioner field is correctly pre-populated on node creation form"));
$this->assertFieldByName('question_fields_age[und][0][value]', '10', t("The age field is correctly pre-populated on node creation form"));
$this->assertFieldByName('question_fields_sex[und][0][value]', 'M', t("The questioner field is correctly pre-populated on node creation form"));
}
}