See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Grade object tests. 19 * 20 * @package core_grades 21 * @category phpunit 22 * @copyright 2014 Frédéric Massart - FMCorz.net 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once (__DIR__ . '/fixtures/lib.php'); 29 30 /** 31 * Grade object testcase. 32 * 33 * @package core_grades 34 * @category phpunit 35 * @copyright 2014 Frédéric Massart - FMCorz.net 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class core_grade_object_testcase extends grade_base_testcase { 39 40 public function test_fetch_all_helper() { 41 // Simple ID lookup. 42 $params = array('id' => $this->grade_items[0]->id); 43 $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 44 $this->assertCount(1, $items); 45 $item = array_shift($items); 46 $this->assertInstanceOf('grade_item', $item); 47 $this->assertEquals($item->id, $this->grade_items[0]->id); 48 49 // Various parameters lookup, multiple results. 50 $params = array('courseid' => $this->course->id, 'categoryid' => $this->grade_categories[1]->id); 51 $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 52 $this->assertCount(2, $items); 53 $expecteditems = array($this->grade_items[0]->id => true, $this->grade_items[1]->id => true); 54 foreach ($items as $item) { 55 $this->assertInstanceOf('grade_item', $item); 56 $this->assertArrayHasKey($item->id, $expecteditems); 57 unset($expecteditems[$item->id]); 58 } 59 60 // Text column lookup. 61 $params = array('iteminfo' => $this->grade_items[2]->iteminfo); 62 $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 63 $this->assertCount(1, $items); 64 $item = array_shift($items); 65 $this->assertInstanceOf('grade_item', $item); 66 $this->assertEquals($item->id, $this->grade_items[2]->id); 67 68 // Lookup using non-existing columns. 69 $params = array('doesnotexist' => 'ignoreme', 'id' => $this->grade_items[0]->id); 70 $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 71 $this->assertCount(1, $items); 72 $item = array_shift($items); 73 $this->assertInstanceOf('grade_item', $item); 74 $this->assertEquals($item->id, $this->grade_items[0]->id); 75 } 76 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body