���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/base_test.php.tar
���ѧ٧ѧ�
home3/cpr76684/public_html/Aem/search/tests/base_test.php 0000644 00000013521 15152206451 0017062 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. namespace core_search; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/fixtures/testable_core_search.php'); require_once($CFG->dirroot . '/search/tests/fixtures/mock_search_area.php'); /** * Search engine base unit tests. * * @package core_search * @copyright 2017 Matt Porritt <mattp@catalyst-au.net> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class base_test extends \advanced_testcase { /** * @var \core_search::manager */ protected $search = null; /** * @var Instace of core_search_generator. */ protected $generator = null; /** * @var Instace of testable_engine. */ protected $engine = null; public function setUp(): void { $this->resetAfterTest(); set_config('enableglobalsearch', true); // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this. $search = \testable_core_search::instance(); $this->generator = self::getDataGenerator()->get_plugin_generator('core_search'); $this->generator->setup(); } public function tearDown(): void { // For unit tests before PHP 7, teardown is called even on skip. So only do our teardown if we did setup. if ($this->generator) { // Moodle DML freaks out if we don't teardown the temp table after each run. $this->generator->teardown(); $this->generator = null; } } /** * Test base get search fileareas */ public function test_get_search_fileareas_base() { $builder = $this->getMockBuilder('\core_search\base'); $builder->disableOriginalConstructor(); $stub = $builder->getMockForAbstractClass(); $result = $stub->get_search_fileareas(); $this->assertEquals(array(), $result); } /** * Test base attach files */ public function test_attach_files_base() { $filearea = 'search'; $component = 'mod_test'; // Create file to add. $fs = get_file_storage(); $filerecord = array( 'contextid' => 1, 'component' => $component, 'filearea' => $filearea, 'itemid' => 1, 'filepath' => '/', 'filename' => 'testfile.txt'); $content = 'All the news that\'s fit to print'; $file = $fs->create_file_from_string($filerecord, $content); // Construct the search document. $rec = new \stdClass(); $rec->contextid = 1; $area = new \core_mocksearch\search\mock_search_area(); $record = $this->generator->create_record($rec); $document = $area->get_document($record); // Create a mock from the abstract class, // with required methods stubbed. $builder = $this->getMockBuilder('\core_search\base'); $builder->disableOriginalConstructor(); $builder->onlyMethods(array('get_search_fileareas', 'get_component_name')); $stub = $builder->getMockForAbstractClass(); $stub->method('get_search_fileareas')->willReturn(array($filearea)); $stub->method('get_component_name')->willReturn($component); // Attach file to our test document. $stub->attach_files($document); // Verify file is attached. $files = $document->get_files(); $file = array_values($files)[0]; $this->assertEquals(1, count($files)); $this->assertEquals($content, $file->get_content()); } /** * Tests the base version (stub) of get_contexts_to_reindex. */ public function test_get_contexts_to_reindex() { $area = new \core_mocksearch\search\mock_search_area(); $this->assertEquals([\context_system::instance()], iterator_to_array($area->get_contexts_to_reindex(), false)); } /** * Test default document icon. */ public function test_get_default_doc_icon() { $basearea = $this->getMockBuilder('\core_search\base') ->disableOriginalConstructor() ->getMockForAbstractClass(); $document = $this->getMockBuilder('\core_search\document') ->disableOriginalConstructor() ->getMock(); $result = $basearea->get_doc_icon($document); $this->assertEquals('i/empty', $result->get_name()); $this->assertEquals('moodle', $result->get_component()); } /** * Test base search area category names. */ public function test_get_category_names() { $builder = $this->getMockBuilder('\core_search\base'); $builder->disableOriginalConstructor(); $stub = $builder->getMockForAbstractClass(); $expected = ['core-other']; $this->assertEquals($expected, $stub->get_category_names()); } /** * Test getting all required search area setting names. */ public function test_get_settingnames() { $expected = array('_enabled', '_indexingstart', '_indexingend', '_lastindexrun', '_docsignored', '_docsprocessed', '_recordsprocessed', '_partial'); $this->assertEquals($expected, \core_search\base::get_settingnames()); } } home3/cpr76684/public_html/Aem/mod/assign/tests/base_test.php 0000644 00000022405 15152217736 0017671 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. namespace mod_assign; use mod_assign_testable_assign; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); require_once($CFG->dirroot . '/mod/assign/upgradelib.php'); require_once(__DIR__ . '/fixtures/testable_assign.php'); /** * Unit tests for (some of) mod/assign/locallib.php. * * @package mod_assign * @category test * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class base_test extends \advanced_testcase { /** @const Default number of students to create */ const DEFAULT_STUDENT_COUNT = 3; /** @const Default number of teachers to create */ const DEFAULT_TEACHER_COUNT = 2; /** @const Default number of editing teachers to create */ const DEFAULT_EDITING_TEACHER_COUNT = 2; /** @const Optional extra number of students to create */ const EXTRA_STUDENT_COUNT = 40; /** @const Optional number of suspended students */ const EXTRA_SUSPENDED_COUNT = 10; /** @const Optional extra number of teachers to create */ const EXTRA_TEACHER_COUNT = 5; /** @const Optional extra number of editing teachers to create */ const EXTRA_EDITING_TEACHER_COUNT = 5; /** @const Number of groups to create */ const GROUP_COUNT = 6; /** @var \stdClass $course New course created to hold the assignments */ protected $course = null; /** @var array $teachers List of DEFAULT_TEACHER_COUNT teachers in the course*/ protected $teachers = null; /** @var array $editingteachers List of DEFAULT_EDITING_TEACHER_COUNT editing teachers in the course */ protected $editingteachers = null; /** @var array $students List of DEFAULT_STUDENT_COUNT students in the course*/ protected $students = null; /** @var array $extrateachers List of EXTRA_TEACHER_COUNT teachers in the course*/ protected $extrateachers = null; /** @var array $extraeditingteachers List of EXTRA_EDITING_TEACHER_COUNT editing teachers in the course*/ protected $extraeditingteachers = null; /** @var array $extrastudents List of EXTRA_STUDENT_COUNT students in the course*/ protected $extrastudents = null; /** @var array $extrasuspendedstudents List of EXTRA_SUSPENDED_COUNT students in the course*/ protected $extrasuspendedstudents = null; /** @var array $groups List of 10 groups in the course */ protected $groups = null; /** * Setup function - we will create a course and add an assign instance to it. */ protected function setUp(): void { global $DB; $this->resetAfterTest(true); $this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $this->teachers = array(); for ($i = 0; $i < self::DEFAULT_TEACHER_COUNT; $i++) { array_push($this->teachers, $this->getDataGenerator()->create_user()); } $this->editingteachers = array(); for ($i = 0; $i < self::DEFAULT_EDITING_TEACHER_COUNT; $i++) { array_push($this->editingteachers, $this->getDataGenerator()->create_user()); } $this->students = array(); for ($i = 0; $i < self::DEFAULT_STUDENT_COUNT; $i++) { array_push($this->students, $this->getDataGenerator()->create_user()); } $this->groups = array(); for ($i = 0; $i < self::GROUP_COUNT; $i++) { array_push($this->groups, $this->getDataGenerator()->create_group(array('courseid'=>$this->course->id))); } $teacherrole = $DB->get_record('role', array('shortname'=>'teacher')); foreach ($this->teachers as $i => $teacher) { $this->getDataGenerator()->enrol_user($teacher->id, $this->course->id, $teacherrole->id); groups_add_member($this->groups[$i % self::GROUP_COUNT], $teacher); } $editingteacherrole = $DB->get_record('role', array('shortname'=>'editingteacher')); foreach ($this->editingteachers as $i => $editingteacher) { $this->getDataGenerator()->enrol_user($editingteacher->id, $this->course->id, $editingteacherrole->id); groups_add_member($this->groups[$i % self::GROUP_COUNT], $editingteacher); } $studentrole = $DB->get_record('role', array('shortname'=>'student')); foreach ($this->students as $i => $student) { $this->getDataGenerator()->enrol_user($student->id, $this->course->id, $studentrole->id); groups_add_member($this->groups[$i % self::GROUP_COUNT], $student); } } /* * For tests that make sense to use alot of data, create extra students/teachers. */ protected function create_extra_users() { global $DB; $this->extrateachers = array(); for ($i = 0; $i < self::EXTRA_TEACHER_COUNT; $i++) { array_push($this->extrateachers, $this->getDataGenerator()->create_user()); } $this->extraeditingteachers = array(); for ($i = 0; $i < self::EXTRA_EDITING_TEACHER_COUNT; $i++) { array_push($this->extraeditingteachers, $this->getDataGenerator()->create_user()); } $this->extrastudents = array(); for ($i = 0; $i < self::EXTRA_STUDENT_COUNT; $i++) { array_push($this->extrastudents, $this->getDataGenerator()->create_user()); } $this->extrasuspendedstudents = array(); for ($i = 0; $i < self::EXTRA_SUSPENDED_COUNT; $i++) { array_push($this->extrasuspendedstudents, $this->getDataGenerator()->create_user()); } $teacherrole = $DB->get_record('role', array('shortname'=>'teacher')); foreach ($this->extrateachers as $i => $teacher) { $this->getDataGenerator()->enrol_user($teacher->id, $this->course->id, $teacherrole->id); groups_add_member($this->groups[$i % self::GROUP_COUNT], $teacher); } $editingteacherrole = $DB->get_record('role', array('shortname'=>'editingteacher')); foreach ($this->extraeditingteachers as $i => $editingteacher) { $this->getDataGenerator()->enrol_user($editingteacher->id, $this->course->id, $editingteacherrole->id); groups_add_member($this->groups[$i % self::GROUP_COUNT], $editingteacher); } $studentrole = $DB->get_record('role', array('shortname'=>'student')); foreach ($this->extrastudents as $i => $student) { $this->getDataGenerator()->enrol_user($student->id, $this->course->id, $studentrole->id); if ($i < (self::EXTRA_STUDENT_COUNT / 2)) { groups_add_member($this->groups[$i % self::GROUP_COUNT], $student); } } foreach ($this->extrasuspendedstudents as $i => $suspendedstudent) { $this->getDataGenerator()->enrol_user($suspendedstudent->id, $this->course->id, $studentrole->id, 'manual', 0, 0, ENROL_USER_SUSPENDED); if ($i < (self::EXTRA_SUSPENDED_COUNT / 2)) { groups_add_member($this->groups[$i % self::GROUP_COUNT], $suspendedstudent); } } } /** * Convenience function to create a testable instance of an assignment. * * @param array $params Array of parameters to pass to the generator * @return testable_assign Testable wrapper around the assign class. */ protected function create_instance($params=array()) { $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); if (!isset($params['course'])) { $params['course'] = $this->course->id; } $instance = $generator->create_instance($params); $cm = get_coursemodule_from_instance('assign', $instance->id); $context = \context_module::instance($cm->id); return new mod_assign_testable_assign($context, $cm, $this->course); } public function test_create_instance() { $this->assertNotEmpty($this->create_instance()); } } class_alias('mod_assign_testable_assign', 'testable_assign');
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�