/** * Creates a small test course specifying a maximum size and checks the generated files size is limited. */ public function test_filesize_limit() { $this->resetAfterTest(); $this->setAdminUser(); // Limit. $filesizelimit = 100; // Create a limited XS course. $backend = new tool_generator_course_backend('TOOL_XS_LIMITED', 0, false, $filesizelimit, false); $courseid = $backend->make(); $course = get_course($courseid); $modinfo = get_fast_modinfo($course); // Check there are small files. $fs = get_file_storage(); $resources = $modinfo->get_instances_of('resource'); foreach ($resources as $resource) { $resourcecontext = context_module::instance($resource->id); $files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false); foreach ($files as $file) { if ($file->get_mimetype() == 'application/octet-stream') { $this->assertLessThanOrEqual($filesizelimit, $file->get_filesize()); } } } // Create a non-limited XS course. $backend = new tool_generator_course_backend('TOOL_XS_NOLIMITS', 0, false, false, false); $courseid = $backend->make(); $course = get_course($courseid); $modinfo = get_fast_modinfo($course); // Check there are small files. $fs = get_file_storage(); $resources = $modinfo->get_instances_of('resource'); foreach ($resources as $resource) { $resourcecontext = context_module::instance($resource->id); $files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false); foreach ($files as $file) { if ($file->get_mimetype() == 'application/octet-stream') { $this->assertGreaterThan($filesizelimit, (int) $file->get_filesize()); } } } }
exit(empty($options['help']) ? 1 : 0); } // Check debugging is set to developer level. if (empty($options['bypasscheck']) && !debugging('', DEBUG_DEVELOPER)) { cli_error(get_string('error_notdebugging', 'tool_generator')); } // Get options. $shortname = $options['shortname']; $fullname = $options['fullname']; $summary = $options['summary']; $sizename = $options['size']; $fixeddataset = $options['fixeddataset']; $filesizelimit = $options['filesizelimit']; // Check size. try { $size = tool_generator_course_backend::size_for_name($sizename); } catch (coding_exception $e) { cli_error("Invalid size ({$sizename}). Use --help for help."); } // Check shortname. if ($error = tool_generator_course_backend::check_shortname_available($shortname)) { cli_error($error); } // Switch to admin user account. \core\session\manager::set_user(get_admin()); // Do backend code to generate course. $backend = new tool_generator_course_backend($shortname, $size, $fixeddataset, $filesizelimit, empty($options['quiet']), $fullname, $summary, FORMAT_HTML); $id = $backend->make(); if (empty($options['quiet'])) { echo PHP_EOL . 'Generated course: ' . course_get_url($id) . PHP_EOL; }