@@ -5092,4 +5092,50 @@ public function test_course_get_recent_courses() {
50925092 $ this ->assertCount (3 , $ result );
50935093 $ this ->assertArrayNotHasKey ($ courses [0 ]->id , $ result );
50945094 }
5095+
5096+ /**
5097+ * Data provider for test_course_modules_pending_deletion.
5098+ *
5099+ * @return array An array of arrays contain test data
5100+ */
5101+ public function provider_course_modules_pending_deletion () {
5102+ return [
5103+ 'Non-gradable activity, check all ' => [['forum ' ], 0 , false , true ],
5104+ 'Gradable activity, check all ' => [['assign ' ], 0 , false , true ],
5105+ 'Non-gradable activity, check gradables ' => [['forum ' ], 0 , true , false ],
5106+ 'Gradable activity, check gradables ' => [['assign ' ], 0 , true , true ],
5107+ 'Non-gradable within multiple, check all ' => [['quiz ' , 'forum ' , 'assign ' ], 1 , false , true ],
5108+ 'Non-gradable within multiple, check gradables ' => [['quiz ' , 'forum ' , 'assign ' ], 1 , true , false ],
5109+ 'Gradable within multiple, check all ' => [['quiz ' , 'forum ' , 'assign ' ], 2 , false , true ],
5110+ 'Gradable within multiple, check gradables ' => [['quiz ' , 'forum ' , 'assign ' ], 2 , true , true ],
5111+ ];
5112+ }
5113+
5114+ /**
5115+ * Tests the function course_modules_pending_deletion.
5116+ *
5117+ * @param string[] $modules A complete list aff all available modules before deletion
5118+ * @param int $indextodelete The index of the module in the $modules array that we want to test with
5119+ * @param bool $gradable The value to pass to the gradable argument of the course_modules_pending_deletion function
5120+ * @param bool $expected The expected result
5121+ * @dataProvider provider_course_modules_pending_deletion
5122+ */
5123+ public function test_course_modules_pending_deletion (array $ modules , int $ indextodelete , bool $ gradable , bool $ expected ) {
5124+ $ this ->resetAfterTest ();
5125+
5126+ // Ensure recyclebin is enabled.
5127+ set_config ('coursebinenable ' , true , 'tool_recyclebin ' );
5128+
5129+ // Create course and modules.
5130+ $ generator = $ this ->getDataGenerator ();
5131+ $ course = $ generator ->create_course ();
5132+
5133+ $ moduleinstances = [];
5134+ foreach ($ modules as $ module ) {
5135+ $ moduleinstances [] = $ generator ->create_module ($ module , array ('course ' => $ course ->id ));
5136+ }
5137+
5138+ course_delete_module ($ moduleinstances [$ indextodelete ]->cmid , true ); // Try to delete the instance asynchronously.
5139+ $ this ->assertEquals ($ expected , course_modules_pending_deletion ($ course ->id , $ gradable ));
5140+ }
50955141}
0 commit comments