private function ForumAccessTestCase::testForumAccessCreateTopic in Forum Access 6
This function test if the user can create a topic Three steps: is there a create link, does the create topic page opens and can the new topic be saved
1 call to ForumAccessTestCase::testForumAccessCreateTopic()
- ForumAccessTestCase::testForumAccessRun in ./
forum_access.test - The main function which is used to start testing a specific forum configuration.
File
- ./
forum_access.test, line 592 - Test file for forum_access.module.
Class
- ForumAccessTestCase
- This is the base class for forum access testing.
Code
private function testForumAccessCreateTopic() {
if (intval($this->testForumAccessCurrentForumId) > 0) {
$allowed = $this
->testForumAccessAllowed('topic_create');
// Check to see if the reply link is on the view page
$this
->drupalGet('forum/' . $this->testForumAccessCurrentForumId);
if ($allowed) {
if (!$this
->assertPattern("/node\\/add\\/forum\\/{$this->testForumAccessCurrentForumId}/", t('For @user there should be an post-new-topic-link on this page: @page', array(
'@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo();
}
}
else {
if (!$this
->assertNoPattern("/node\\/add\\/forum\\/{$this->testForumAccessCurrentForumId}/", t('For @user there should NOT be any post-new-topic-link on this page: @page', array(
'@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo();
}
}
// Check to see if the user/anonymous is allowed to open the reply page
$page_opened = FALSE;
$this
->drupalGet('node/add/forum/' . $this->testForumAccessCurrentForumId);
// Can the user select a forum from the selectbox
$selectbox_has_forum = (bool) preg_match('/<option value="">.*<\\/option><option value="\\d+"(>| selected="selected">).*<\\/option><\\/select>/', $this
->drupalGetContent(), $matches);
// Does the text "not authorized" exists on the page
$not_authorized_exists = strpos(filter_xss($this
->drupalGetContent(), array()), "not authorized") !== FALSE;
if ($allowed) {
if (!$this
->assert($selectbox_has_forum && !$not_authorized_exists, t('@user should be allowed to open the post new topic page for this forum: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
// if (!$this->assertNoText("not authorized", t('@user should be allowed to open the post new topic page for this forum: @page', array('@user' => ($this->loggedInUser ? t('The user') : t('Anonymous')), '@page' => $this->getUrl())))) {
$this
->testForumAccessDumpDebugInfo();
}
else {
$page_opened = TRUE;
}
}
else {
if (!$this
->assert(!$selectbox_has_forum || $not_authorized_exists, t('@user should NOT be allowed to open the post new topic page for this forum: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
// if (!$this->assertText("not authorized", t('@user should NOT be allowed to open the post new topic page for this forum: @page', array('@user' => ($this->loggedInUser ? t('The user') : t('Anonymous')), '@page' => $this->getUrl())))) {
$this
->testForumAccessDumpDebugInfo();
$page_opened = TRUE;
}
}
if ($page_opened) {
// Check to see if the user/anonymous is allowed to create a new topic
$topic_options = array(
'title' => 'Topic title: ' . $this
->randomName(32),
'body' => 'Topic body: ' . $this
->randomName(64),
);
$this
->drupalPost('node/add/forum/' . $this->testForumAccessCurrentForumId, $topic_options, t('Save'));
if ($allowed) {
if ($this
->assertNoText("not authorized", t('@user should be allowed to create a new topic on this forum: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
$topic = node_load(array(
'title' => $topic_options['title'],
));
return $topic ? $topic->nid : 0;
}
else {
$this
->testForumAccessDumpDebugInfo();
}
}
else {
if (!$this
->assertText("not authorized", t('@user should NOT be allowed to create a new topic on this forum: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo();
$topic = node_load(array(
'title' => $topic_options['title'],
));
return $topic ? $topic->nid : 0;
}
}
}
}
return 0;
}