diff --git a/CHANGELOG.md b/CHANGELOG.md index 88948e4d..992a8303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Changelog ## +### 0.11.2 ### +Fix many answers on many steps + +* Was stuck on 2nd step + + ### 0.11.1 ### Improve steps generating (for sections addon) diff --git a/README.md b/README.md index 3f47bbf9..cf397ea3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ **Tags:** psychological, testing, test, quiz **Requires at least:** 3.2 **Tested up to:** 4.1.1 -**Stable tag:** 0.11.1 +**Stable tag:** 0.11.2 **License:** GPLv3 **License URI:** http://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/Component/StepStrategy.php b/src/Component/StepStrategy.php index 599e7aa4..bf0d2ff7 100644 --- a/src/Component/StepStrategy.php +++ b/src/Component/StepStrategy.php @@ -39,10 +39,10 @@ abstract class WpTesting_Component_StepStrategy */ private $isShowStepsCounter = false; - public function __construct(WpTesting_Model_Test $test = null, fRecordSet $answeredQuestions = null) + public function __construct(WpTesting_Model_Test $test = null, fRecordSet $answeredAnswers = null) { is_null($test) || $this->setTest($test); - $this->answeredQuestions = $answeredQuestions; + $this->answeredQuestions = $this->extractQuestionsFromAnswers($answeredAnswers); } /** @@ -174,4 +174,16 @@ private function setupTotalsAndNumbers() return $this; } + /** + * @param fRecordSet $answers + * @return fRecordSet + */ + private function extractQuestionsFromAnswers(fRecordSet $answers) + { + $questions = array(); + foreach ($answers as $answer) { /* @var $answer WpTesting_Model_Answer */ + $questions[$answer->getQuestionId()] = $answer->createQuestion(); + } + return fRecordSet::buildFromArray('WpTesting_Model_Question', $questions); + } } \ No newline at end of file diff --git a/src/Doer/TestPasser/FillForm.php b/src/Doer/TestPasser/FillForm.php index 7b3a8592..9a80f894 100644 --- a/src/Doer/TestPasser/FillForm.php +++ b/src/Doer/TestPasser/FillForm.php @@ -62,10 +62,16 @@ public function renderContent($content, $template) if (!$step->isLast()) { $submitButtonCaption = __('Next', 'wp-testing'); } + $answerIdName = fOrm::tablize('WpTesting_Model_Answer') . '::answer_id'; + $answerIndex = 0; + if (isset($_POST[$answerIdName]) && is_array($_POST[$answerIdName])) { + $answerIndex = max(array_keys($_POST[$answerIdName])) + 1; + } $params = array( 'wp' => $this->wp, 'hiddens' => $this->generateHiddens($step), - 'answerIdName' => fOrm::tablize('WpTesting_Model_Answer') . '::answer_id', + 'answerIdName' => $answerIdName, + 'answerIndex' => $answerIndex, 'content' => $content, 'test' => $this->test, 'questions' => $step->getQuestions(), diff --git a/src/Model/Answer.php b/src/Model/Answer.php index b6417a33..eb1be932 100644 --- a/src/Model/Answer.php +++ b/src/Model/Answer.php @@ -92,6 +92,14 @@ public function createGlobalAnswer() return $this->createWpTesting_Model_GlobalAnswer(); } + /** + * @return WpTesting_Model_Question + */ + public function createQuestion() + { + return $this->createWpTesting_Model_Question(); + } + /** * Abbreviration of title * diff --git a/src/Template/Test/Passer/fill-form.php b/src/Template/Test/Passer/fill-form.php index 48b6c6c2..95abd5f8 100644 --- a/src/Template/Test/Passer/fill-form.php +++ b/src/Template/Test/Passer/fill-form.php @@ -2,6 +2,7 @@ // Can be overriden in your theme as entry-content-wpt-test-fill-form.php /* @var $answerIdName string */ +/* @var $answerIndex integer */ /* @var $isShowContent boolean */ /* @var $content string */ /* @var $subTitle string */ @@ -26,7 +27,6 @@

doAction('wp_testing_template_fill_form_questions_before') ?> $question): /* @var $question WpTesting_Model_Question */ ?> - doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>
@@ -49,11 +49,12 @@
- + doAction('wp_testing_template_fill_form_question_after', $question, $q) ?> + doAction('wp_testing_template_fill_form_questions_after') ?> diff --git a/tests/mocha/test/steps.js b/tests/mocha/test/steps.js index 9fe2ca11..327cad70 100644 --- a/tests/mocha/test/steps.js +++ b/tests/mocha/test/steps.js @@ -43,6 +43,7 @@ describe('Steps', function() { '#wpt_question_title_3': 'How many steps are there in accident prevention?' }) this.click('.misc-pub-wpt-test-page-one-question-per-step input[type=checkbox]') + this.click('.misc-pub-wpt-test-page-multiple-answers input[type=checkbox]') this.clickLabel(' Yes', 'label') this.clickLabel(' No', 'label') this.clickLabel(' Lie', 'label') @@ -119,6 +120,7 @@ describe('Steps', function() { it('should have 33% answered and next non-disabled after answer', function() { casper.then(function() { this.clickLabel('Yes', '*[@id="wpt-test-form"]/*[1]/*//label') + this.clickLabel('No', '*[@id="wpt-test-form"]/*[1]/*//label') this.getTitle().should.match(/^33% ans/) '#wpt-test-form input[type=submit]'.should.not.have.attr('disabled') }) @@ -158,6 +160,7 @@ describe('Steps', function() { isOpened = false casper.then(function() { this.clickLabel('Yes', '*[@id="wpt-test-form"]/*[1]/*//label') + this.clickLabel('No', '*[@id="wpt-test-form"]/*[1]/*//label') this.fill('form#wpt-test-form', {}, true) }).waitForUrl(/three-steps/, function() { 'Fatal'.should.not.be.textInDOM @@ -183,12 +186,13 @@ describe('Steps', function() { isOpened = false casper.then(function() { this.clickLabel('Yes', '*[@id="wpt-test-form"]/*[1]/*//label') + this.clickLabel('No', '*[@id="wpt-test-form"]/*[1]/*//label') this.fill('form#wpt-test-form', {}, true) }).waitForUrl(/three-steps/, function() { 'Fatal'.should.not.be.textInDOM 'Results'.should.be.textInDOM 'Lie'.should.be.textInDOM - '3 out of 3'.should.be.textInDOM + '6 out of 6'.should.be.textInDOM isOpened = true }) }) diff --git a/wp-testing.php b/wp-testing.php index 1a0cd333..e5353aa7 100644 --- a/wp-testing.php +++ b/wp-testing.php @@ -3,7 +3,7 @@ * Plugin Name: Wp-testing * Plugin URI: http://wordpress.org/extend/plugins/wp-testing/ * Description: Helps to create psychological tests. - * Version: 0.11.1 + * Version: 0.11.2 * Author: Alexander Ustimenko * Author URI: http://ustimen.co * License: GPL3