@@ -443,4 +443,60 @@ public function test_targeted_process_with_named_subcategory(): void {
443
443
$ this ->assertEquals ("top " , $ manifest ->context ->defaultsubdirectory );
444
444
$ this ->assertEquals (123 , $ manifest ->context ->defaultsubcategoryid );
445
445
}
446
+
447
+ /**
448
+ * Test the full process with subcategoryid and truncated file names.
449
+ */
450
+ public function test_process_with_subcategory_id_and_truncation (): void {
451
+ $ this ->options ['qcategoryid ' ] = 123 ;
452
+ $ this ->clihelper = $ this ->getMockBuilder (\qbank_gitsync \cli_helper::class)->onlyMethods ([
453
+ 'get_arguments ' , 'check_context ' ,
454
+ ])->setConstructorArgs ([[]])->getMock ();
455
+ $ this ->clihelper ->expects ($ this ->any ())->method ('get_arguments ' )->will ($ this ->returnValue ($ this ->options ));
456
+ $ this ->clihelper ->expects ($ this ->any ())->method ('check_context ' )->willReturn (
457
+ json_decode ('{"contextinfo":{"contextlevel": "module", "categoryname":"", "coursename":"Course 1",
458
+ "modulename":"Module 1", "instanceid":"", "qcategoryname":"top/Default for Test 1/sub 2",
459
+ "qcategoryid":123},
460
+ "questions": []} ' )
461
+ );
462
+ $ this ->createrepo = $ this ->getMockBuilder (\qbank_gitsync \create_repo::class)->onlyMethods ([
463
+ 'get_curl_request ' , 'call_exit ' ,
464
+ ])->setConstructorArgs ([$ this ->clihelper , $ this ->moodleinstances ])->getMock ();
465
+
466
+ $ this ->createrepo ->curlrequest = $ this ->curl ;
467
+ $ this ->createrepo ->listcurlrequest = $ this ->listcurl ;
468
+
469
+ $ this ->listcurl ->expects ($ this ->exactly (1 ))->method ('execute ' )->willReturn (
470
+ '{"contextinfo":{"contextlevel": "module", "categoryname":"", "coursename":"Course 1",
471
+ "modulename":"Module 1", "instanceid":"", "qcategoryname":"top/Default for Test 1/sub 2"},
472
+ "questions": [{"questionbankentryid": "3", "name": "Three", "questioncategory": ""},
473
+ {"questionbankentryid": "4", "name": "Four", "questioncategory": ""}]} '
474
+ );
475
+ $ this ->curl ->expects ($ this ->exactly (2 ))->method ('execute ' )->willReturnOnConsecutiveCalls (
476
+ '{"question": "<quiz><question type=\"category\"><category><text>top/Default for Test 1/sub 2 ' .
477
+ '</text></category></question><question><name><text>Three</text></name></question></quiz>" ' .
478
+ ', "version": "1"} ' ,
479
+ '{"question": "<quiz><question type=\"category\"><category><text>top/Default for Test 1/sub 2 ' .
480
+ '</text></category></question><question><name><text>Four</text></name></question></quiz>" ' .
481
+ ', "version": "1"} ' ,
482
+ );
483
+ $ this ->createrepo ->maxcatlength = 5 ;
484
+ $ this ->createrepo ->maxqlength = 3 ;
485
+ $ this ->createrepo ->process ($ this ->clihelper , $ this ->moodleinstances );
486
+
487
+ // Check question files exist.
488
+ $ this ->assertStringContainsString ('Three ' , file_get_contents ($ this ->rootpath . '/top/Defau/sub-2/Thr.xml ' ));
489
+ $ this ->assertStringContainsString ('Four ' , file_get_contents ($ this ->rootpath . '/top/Defau/sub-2/Fou.xml ' ));
490
+
491
+ // Check category files exist.
492
+ $ this ->assertStringContainsString ('top/Default for Test 1/sub 2 ' ,
493
+ file_get_contents ($ this ->rootpath . '/top/Defau/sub-2/ ' . cli_helper::CATEGORY_FILE . '.xml ' ));
494
+ $ this ->assertStringContainsString ('top/Default for Test 1/sub 2 ' ,
495
+ file_get_contents ($ this ->rootpath . '/top/Defau/sub-2/ ' . cli_helper::CATEGORY_FILE . '.xml ' ));
496
+
497
+ $ this ->expectOutputRegex ('/^\nAdded 2 questions.\n$/s ' );
498
+ $ manifest = $ this ->createrepo ->manifestcontents ;
499
+ $ this ->assertEquals ("top/Defau/sub-2 " , $ manifest ->context ->defaultsubdirectory );
500
+ $ this ->assertEquals (123 , $ manifest ->context ->defaultsubcategoryid );
501
+ }
446
502
}
0 commit comments