Skip to content

Commit

Permalink
Merge branch 'hotfix/0.11.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
garex committed Apr 20, 2015
2 parents 76df1a7 + c3baf41 commit 9ba5846
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions src/Component/StepStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}
8 changes: 7 additions & 1 deletion src/Doer/TestPasser/FillForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 3 additions & 2 deletions src/Template/Test/Passer/fill-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -26,7 +27,6 @@
<?php if ($subTitle): ?><h2 class="subtitle"><?php echo $subTitle ?></h2><?php endif ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?>
<?php foreach($questions as $q => $question): /* @var $question WpTesting_Model_Question */ ?>
<?php $answerIndex = ($isMultipleAnswers) ? '' : $q ?>
<?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>
<div class="question">

Expand All @@ -49,11 +49,12 @@
</label>

</div>

<?php if ($isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>

</div>
<?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?>
<?php if (!$isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?>

Expand Down
6 changes: 5 additions & 1 deletion tests/mocha/test/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
})
Expand Down Expand Up @@ -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
Expand All @@ -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
})
})
Expand Down
2 changes: 1 addition & 1 deletion wp-testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ba5846

Please sign in to comment.