/** * Poll creation in an existing topic */ function testCreatePollInTopic() { // Required values to create the poll with. $question = 'Who is the next best contender for Grudge award?'; $id_member = 0; $poster_name = 'test'; // Create the poll. $id_poll = createPoll($question, $id_member, $poster_name); // Link the poll to the topic. associatedPoll($this->id_topic, $id_poll); // it worked, right? $this->assertEqual($id_poll, associatedPoll($this->id_topic)); // get some values from it $pollinfo = pollInfoForTopic($this->id_topic); $this->assertEqual($pollinfo['id_member_started'], 1); $this->assertEqual($pollinfo['question'], $question); $this->assertEqual($pollinfo['max_votes'], 1); // the default value $this->assertEqual($pollinfo['poll_starter'], 0); // lets use pollStarters() and test its result list($topic_starter, $poll_starter) = pollStarters($this->id_topic); $this->assertEqual($topic_starter, 1); $this->assertEqual($poll_starter, 0); }
/** * Remove a poll from a topic without removing the topic. * Must be called with a topic specified in the URL. * Requires poll_remove_any permission, unless it's the poll starter * with poll_remove_own permission. * Upon successful completion of action will direct user back to topic. * Accessed via ?action=poll;sa=remove. */ public function action_remove() { global $topic, $user_info; // Make sure the topic is not empty. if (empty($topic)) { fatal_lang_error('no_access', false); } // Verify the session. checkSession('get'); // We need to work with them polls. require_once SUBSDIR . '/Poll.subs.php'; // Check permissions. if (!allowedTo('poll_remove_any')) { $pollStarters = pollStarters($topic); if (empty($pollStarters)) { fatal_lang_error('no_access', false); } list($topicStarter, $pollStarter) = $pollStarters; if ($topicStarter == $user_info['id'] || $pollStarter != 0 && $pollStarter == $user_info['id']) { isAllowedTo('poll_remove_own'); } } // Retrieve the poll ID. $pollID = associatedPoll($topic); // Remove the poll! removePoll($pollID); // Finally set the topic poll ID back to 0! associatedPoll($topic, 0); // A mod might have logged this (social network?), so let them remove, it too call_integration_hook('integrate_poll_remove', array($pollID)); // Take the moderator back to the topic. redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); }