You are here

private function ForumAccessTestCase::testForumAccessUpdateTopic in Forum Access 6

This function test if the user can update a topic Three steps: is there a edit link, does the edit page opens and can the edited topic be saved

1 call to ForumAccessTestCase::testForumAccessUpdateTopic()
ForumAccessTestCase::testForumAccessRun in ./forum_access.test
The main function which is used to start testing a specific forum configuration.

File

./forum_access.test, line 665
Test file for forum_access.module.

Class

ForumAccessTestCase
This is the base class for forum access testing.

Code

private function testForumAccessUpdateTopic($topic_id = 0) {
  if (intval($topic_id) > 0) {
    $allowed = $this
      ->testForumAccessAllowed('topic_update', $topic_id);

    // Check to see if there is an edit link on the page
    $this
      ->drupalGet('node/' . $topic_id);
    if ($allowed) {
      if (!$this
        ->assertPattern("/node\\/{$topic_id}\\/edit/", t('For @user there should be an edit-this-topic-link on the page: @page', array(
        '@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('topic', $topic_id);
      }
    }
    else {
      if (!$this
        ->assertNoPattern("/node\\/{$topic_id}\\/edit/", t('For @user there should NOT be an edit-this-topic-link on the page: @page', array(
        '@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('topic', $topic_id);
      }
    }

    // Check to see if the user/anonymous is allowed to open the reply page
    $page_opened = FALSE;
    $this
      ->drupalGet('node/' . $topic_id . '/edit/');
    if ($allowed) {
      if (!$this
        ->assertNoText("not authorized", t('@user should be allowed to open the edit page for this topic: @page', array(
        '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('topic', $topic_id);
      }
      else {
        $page_opened = TRUE;
      }
    }
    else {
      if (!$this
        ->assertText("not authorized", t('@user should NOT be allowed to open the edit page for this topic: @page', array(
        '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('topic', $topic_id);
        $page_opened = TRUE;
      }
    }
    if ($page_opened) {

      // Check to see if the user/anonymous is allowed to edit the topic
      $topic_options = array(
        'title' => 'Topic title: ' . $this
          ->randomName(32),
        'body' => 'Topic body: ' . $this
          ->randomName(64),
      );
      $this
        ->drupalPost('node/' . $topic_id . '/edit', $topic_options, t('Save'));
      if ($allowed) {
        if (!$this
          ->assertNoText("not authorized", t('@user should be allowed to edit this topic: @page', array(
          '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
          '@page' => $this
            ->getUrl(),
        )))) {
          $this
            ->testForumAccessDumpDebugInfo('topic', $topic_id);
        }
      }
      else {
        if (!$this
          ->assertText("not authorized", t('@user should NOT be allowed to edit this topic: @page', array(
          '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
          '@page' => $this
            ->getUrl(),
        )))) {
          $this
            ->testForumAccessDumpDebugInfo('topic', $topic_id);
        }
      }
    }
  }
}