Skip to content

Commit 3ae4cdd

Browse files
committed
Merge branch 'release/0.21.12'
2 parents 89a188b + 281832e commit 3ae4cdd

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
## Changelog ##
33

44

5+
### 0.21.12 ###
6+
7+
Fix bug with scale sorting.
8+
9+
Negative values was sorted after zero value, but with reverse order: 10, 9, 8, 7, 1, 0, -10, -9, -8, -1. Now it fixed and order is correct: 10, 9, 8, 7, 1, 0, -1, -8, -9, -10.
10+
11+
Bug was hiding from us for almost 3 and half years and was reported by @justtoask2.
12+
13+
514
### 0.21.11 ###
615

716
Allow to use socket and IPv6 in database connection

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
**Tested up to:** 4.9
1010

11-
**Stable tag:** 0.21.11
11+
**Stable tag:** 0.21.12
1212

1313
**License:** GPLv3
1414

src/Model/Passing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function buildScalesWithRange()
257257

258258
$records = fRecordSet::buildFromArray('WpTesting_Model_Scale', array_values($result));
259259
if ($this->createTest()->isSortScalesByScore()) {
260-
$records = $records->sort('getValue', 'desc');
260+
$records = $records->sortByCallback(array('WpTesting_Model_Scale', 'compareDescending'));
261261
}
262262
return $records;
263263
}

src/Model/Scale.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public function getValue()
6767
return $this->value;
6868
}
6969

70+
public static function compareDescending(WpTesting_Model_Scale $a, WpTesting_Model_Scale $b)
71+
{
72+
if ($a->getValue() == $b->getValue()) {
73+
return 0;
74+
}
75+
76+
return ($a->getValue() > $b->getValue()) ? -1 : 1;
77+
}
78+
7079
/**
7180
* @return number
7281
*/

tests/phpunit/Model/ScaleTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,38 @@ public function testScaleValueAndMaximumAlwaysAvailable()
114114
$this->assertEquals( 23, $this->scale->getValue());
115115
$this->assertEquals(100, $this->scale->getMaximum());
116116
}
117+
118+
public function testScalesSortedByValueFromMaxToMinIncludingNegative()
119+
{
120+
$records = fRecordSet::buildFromArray('WpTesting_Model_Scale', array(
121+
$this->createScale(0),
122+
$this->createScale(-10),
123+
$this->createScale(50),
124+
$this->createScale(100),
125+
$this->createScale(-1000),
126+
));
127+
128+
$sorted = $records->sortByCallback(array('WpTesting_Model_Scale', 'compareDescending'));
129+
130+
$values = array();
131+
foreach ($sorted as $scale) {
132+
$values[] = $scale->getValue();
133+
}
134+
135+
$this->assertEquals(array(100.0, 50.0, 0.0, -10.0, -1000.0), $values);
136+
}
137+
138+
/**
139+
* @param int $value
140+
*
141+
* @return WpTesting_Model_Scale
142+
*/
143+
private function createScale($value)
144+
{
145+
$scale = new WpTesting_Model_Scale();
146+
$scale->setRange(-1000, 1000);
147+
$scale->setValue($value);
148+
149+
return $scale;
150+
}
117151
}

wp-testing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Wp-testing
44
* Plugin URI: http://wordpress.org/extend/plugins/wp-testing/
55
* Description: Helps to create psychological tests.
6-
* Version: 0.21.11
6+
* Version: 0.21.12
77
* Author: Alexander Ustimenko
88
* Author URI: http://ustimen.co
99
* License: GPL3

0 commit comments

Comments
 (0)