Differences Between: [Versions 310 and 311] [Versions 39 and 311]
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 namespace core; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 require_once (__DIR__ . '/fixtures/lib.php'); 22 23 /** 24 * Grade object testcase. 25 * 26 * @package core 27 * @category test 28 * @copyright 2014 Frédéric Massart - FMCorz.net 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class grade_object_test extends \grade_base_testcase { 32 33 public function test_fetch_all_helper() { 34 // Simple ID lookup. 35 $params = array('id' => $this->grade_items[0]->id); 36 $items = \grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 37 $this->assertCount(1, $items); 38 $item = array_shift($items); 39 $this->assertInstanceOf('grade_item', $item); 40 $this->assertEquals($item->id, $this->grade_items[0]->id); 41 42 // Various parameters lookup, multiple results. 43 $params = array('courseid' => $this->course->id, 'categoryid' => $this->grade_categories[1]->id); 44 $items = \grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 45 $this->assertCount(2, $items); 46 $expecteditems = array($this->grade_items[0]->id => true, $this->grade_items[1]->id => true); 47 foreach ($items as $item) { 48 $this->assertInstanceOf('grade_item', $item); 49 $this->assertArrayHasKey($item->id, $expecteditems); 50 unset($expecteditems[$item->id]); 51 } 52 53 // Text column lookup. 54 $params = array('iteminfo' => $this->grade_items[2]->iteminfo); 55 $items = \grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 56 $this->assertCount(1, $items); 57 $item = array_shift($items); 58 $this->assertInstanceOf('grade_item', $item); 59 $this->assertEquals($item->id, $this->grade_items[2]->id); 60 61 // Lookup using non-existing columns. 62 $params = array('doesnotexist' => 'ignoreme', 'id' => $this->grade_items[0]->id); 63 $items = \grade_object::fetch_all_helper('grade_items', 'grade_item', $params); 64 $this->assertCount(1, $items); 65 $item = array_shift($items); 66 $this->assertInstanceOf('grade_item', $item); 67 $this->assertEquals($item->id, $this->grade_items[0]->id); 68 } 69 70 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body