Skip to content

Commit ee2169c

Browse files
release: fixes
- Fix variable mismatch in the install category function.
2 parents f49135b + 9be39ed commit ee2169c

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

src/Modules/Script_loader.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function get_survey_common_data( $reference_data = array() ) {
186186
) {
187187
$common_data['attributes']['days_since_install'] = $this->install_time_category( $reference_data['attributes']['install_days_number'] );
188188
}
189-
189+
190190
return $common_data;
191191
}
192192

@@ -198,19 +198,23 @@ public function get_survey_common_data( $reference_data = array() ) {
198198
* @return int The category.
199199
*/
200200
private function install_time_category( $install_days_number ) {
201-
$install_category = 0;
202-
203201
if ( 1 < $install_days_number && 8 > $install_days_number ) {
204-
$install_category = 7;
205-
} elseif ( 8 <= $install_days_number && 31 > $install_days_number ) {
206-
$install_days_number = 30;
207-
} elseif ( 30 < $install_days_number && 90 > $install_days_number ) {
208-
$install_category = 90;
209-
} elseif ( 90 <= $install_days_number ) {
210-
$install_category = 91;
202+
return 7;
203+
}
204+
205+
if ( 8 <= $install_days_number && 31 > $install_days_number ) {
206+
return 30;
207+
}
208+
209+
if ( 30 < $install_days_number && 90 > $install_days_number ) {
210+
return 90;
211+
}
212+
213+
if ( 90 <= $install_days_number ) {
214+
return 91;
211215
}
212216

213-
return $install_category;
217+
return 0;
214218
}
215219

216220
/**

tests/script-loader-test.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,40 @@ public function test_secret_masking() {
241241
$this->assertEquals( null, $script_loader->secret_masking( null ) );
242242
$this->assertEquals( [], $script_loader->secret_masking( [] ) );
243243
}
244+
245+
/**
246+
* Test the install_time_category method for all cases.
247+
*
248+
* @return void
249+
*/
250+
public function test_install_time_category() {
251+
$script_loader = new \ThemeisleSDK\Modules\Script_Loader();
252+
253+
$test_data = [
254+
// Test default case (0-1 days)
255+
0 => 0,
256+
1 => 0,
257+
// Test 1-7 days category
258+
2 => 7,
259+
5 => 7,
260+
7 => 7,
261+
// Test 8-30 days category
262+
8 => 30,
263+
15 => 30,
264+
30 => 30,
265+
// Test 31-89 days category
266+
31 => 90,
267+
45 => 90,
268+
89 => 90,
269+
// Test 90+ days category
270+
90 => 91,
271+
100 => 91,
272+
365 => 91,
273+
];
274+
275+
foreach ( $test_data as $days => $expected ) {
276+
$data = $script_loader->get_survey_common_data( [ 'attributes' => [ 'install_days_number' => $days ] ] );
277+
$this->assertEquals( $expected, $data['attributes']['days_since_install'], "Failed asserting that {$days} days maps to category {$expected}" );
278+
}
279+
}
244280
}

0 commit comments

Comments
 (0)