File tree Expand file tree Collapse file tree 2 files changed +51
-11
lines changed Expand file tree Collapse file tree 2 files changed +51
-11
lines changed Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments