mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-39915 cleanup core_outputcomponents_testcase
This commit is contained in:
parent
be6ce11cae
commit
18c4323019
@ -29,67 +29,65 @@ global $CFG;
|
||||
require_once($CFG->libdir . '/navigationlib.php');
|
||||
|
||||
|
||||
class navigation_node_testcase extends basic_testcase {
|
||||
protected $tree;
|
||||
protected $fakeproperties = array(
|
||||
'text' => 'text',
|
||||
'shorttext' => 'A very silly extra long short text string, more than 25 characters',
|
||||
'key' => 'key',
|
||||
'type' => 'navigation_node::TYPE_COURSE',
|
||||
'action' => 'http://www.moodle.org/');
|
||||
protected $activeurl = null;
|
||||
protected $inactivenode = null;
|
||||
|
||||
class core_navigationlib_testcase extends advanced_testcase {
|
||||
/**
|
||||
* @var navigation_node
|
||||
*/
|
||||
public $node;
|
||||
|
||||
protected function setUp() {
|
||||
global $CFG, $PAGE, $SITE;
|
||||
parent::setUp();
|
||||
protected function setup_node() {
|
||||
global $PAGE, $SITE;
|
||||
|
||||
$PAGE->set_url('/');
|
||||
$PAGE->set_course($SITE);
|
||||
|
||||
$this->activeurl = $PAGE->url;
|
||||
navigation_node::override_active_url($this->activeurl);
|
||||
$activeurl = $PAGE->url;
|
||||
$inactiveurl = new moodle_url('http://www.moodle.com/');
|
||||
|
||||
$this->inactiveurl = new moodle_url('http://www.moodle.com/');
|
||||
$this->fakeproperties['action'] = $this->inactiveurl;
|
||||
navigation_node::override_active_url($PAGE->url);
|
||||
|
||||
$this->node = new navigation_node('Test Node');
|
||||
$this->node->type = navigation_node::TYPE_SYSTEM;
|
||||
// We add the first child without key. This way we make sure all keys search by comparision is performed using ===
|
||||
// We add the first child without key. This way we make sure all keys search by comparison is performed using ===.
|
||||
$this->node->add('first child without key', null, navigation_node::TYPE_CUSTOM);
|
||||
$demo1 = $this->node->add('demo1', $this->inactiveurl, navigation_node::TYPE_COURSE, null, 'demo1', new pix_icon('i/course', ''));
|
||||
$demo2 = $this->node->add('demo2', $this->inactiveurl, navigation_node::TYPE_COURSE, null, 'demo2', new pix_icon('i/course', ''));
|
||||
$demo3 = $this->node->add('demo3', $this->inactiveurl, navigation_node::TYPE_CATEGORY, null, 'demo3',new pix_icon('i/course', ''));
|
||||
$demo4 = $demo3->add('demo4', $this->inactiveurl,navigation_node::TYPE_COURSE, null, 'demo4', new pix_icon('i/course', ''));
|
||||
$demo5 = $demo3->add('demo5', $this->activeurl, navigation_node::TYPE_COURSE, null, 'demo5',new pix_icon('i/course', ''));
|
||||
$demo1 = $this->node->add('demo1', $inactiveurl, navigation_node::TYPE_COURSE, null, 'demo1', new pix_icon('i/course', ''));
|
||||
$demo2 = $this->node->add('demo2', $inactiveurl, navigation_node::TYPE_COURSE, null, 'demo2', new pix_icon('i/course', ''));
|
||||
$demo3 = $this->node->add('demo3', $inactiveurl, navigation_node::TYPE_CATEGORY, null, 'demo3', new pix_icon('i/course', ''));
|
||||
$demo4 = $demo3->add('demo4', $inactiveurl, navigation_node::TYPE_COURSE, null, 'demo4', new pix_icon('i/course', ''));
|
||||
$demo5 = $demo3->add('demo5', $activeurl, navigation_node::TYPE_COURSE, null, 'demo5', new pix_icon('i/course', ''));
|
||||
$demo5->add('activity1', null, navigation_node::TYPE_ACTIVITY, null, 'activity1')->make_active();
|
||||
$hiddendemo1 = $this->node->add('hiddendemo1', $this->inactiveurl, navigation_node::TYPE_CATEGORY, null, 'hiddendemo1', new pix_icon('i/course', ''));
|
||||
$hiddendemo1 = $this->node->add('hiddendemo1', $inactiveurl, navigation_node::TYPE_CATEGORY, null, 'hiddendemo1', new pix_icon('i/course', ''));
|
||||
$hiddendemo1->hidden = true;
|
||||
$hiddendemo1->add('hiddendemo2', $this->inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo2', new pix_icon('i/course', ''))->helpbutton = 'Here is a help button';
|
||||
$hiddendemo1->add('hiddendemo3', $this->inactiveurl, navigation_node::TYPE_COURSE,null, 'hiddendemo3', new pix_icon('i/course', ''))->display = false;
|
||||
$hiddendemo1->add('hiddendemo2', $inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo2', new pix_icon('i/course', ''))->helpbutton = 'Here is a help button';
|
||||
$hiddendemo1->add('hiddendemo3', $inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo3', new pix_icon('i/course', ''))->display = false;
|
||||
}
|
||||
|
||||
public function test___construct() {
|
||||
global $CFG;
|
||||
$node = new navigation_node($this->fakeproperties);
|
||||
$this->assertEquals($node->text, $this->fakeproperties['text']);
|
||||
$this->assertTrue(strpos($this->fakeproperties['shorttext'], substr($node->shorttext,0, -3))===0);
|
||||
$this->assertEquals($node->key, $this->fakeproperties['key']);
|
||||
$this->assertEquals($node->type, $this->fakeproperties['type']);
|
||||
$this->assertEquals($node->action, $this->fakeproperties['action']);
|
||||
public function test_node__construct() {
|
||||
$this->setup_node();
|
||||
|
||||
$fakeproperties = array(
|
||||
'text' => 'text',
|
||||
'shorttext' => 'A very silly extra long short text string, more than 25 characters',
|
||||
'key' => 'key',
|
||||
'type' => 'navigation_node::TYPE_COURSE',
|
||||
'action' => 'http://www.moodle.org/');
|
||||
|
||||
$node = new navigation_node($fakeproperties);
|
||||
$this->assertSame($fakeproperties['text'], $node->text);
|
||||
$this->assertTrue(strpos($fakeproperties['shorttext'], substr($node->shorttext, 0, -3)) === 0);
|
||||
$this->assertSame($fakeproperties['key'], $node->key);
|
||||
$this->assertSame($fakeproperties['type'], $node->type);
|
||||
$this->assertSame($fakeproperties['action'], $node->action);
|
||||
}
|
||||
public function test_add() {
|
||||
global $CFG;
|
||||
// Add a node with all args set
|
||||
$node1 = $this->node->add('test_add_1','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd1','key',new pix_icon('i/course', ''));
|
||||
// Add a node with the minimum args required
|
||||
$node2 = $this->node->add('test_add_2',null, navigation_node::TYPE_CUSTOM,'testadd2');
|
||||
$node3 = $this->node->add(str_repeat('moodle ', 15),str_repeat('moodle', 15));
|
||||
|
||||
public function test_node_add() {
|
||||
$this->setup_node();
|
||||
|
||||
// Add a node with all args set.
|
||||
$node1 = $this->node->add('test_add_1', 'http://www.moodle.org/', navigation_node::TYPE_COURSE, 'testadd1', 'key', new pix_icon('i/course', ''));
|
||||
// Add a node with the minimum args required.
|
||||
$node2 = $this->node->add('test_add_2', null, navigation_node::TYPE_CUSTOM, 'testadd2');
|
||||
$node3 = $this->node->add(str_repeat('moodle ', 15), str_repeat('moodle', 15));
|
||||
|
||||
$this->assertInstanceOf('navigation_node', $node1);
|
||||
$this->assertInstanceOf('navigation_node', $node2);
|
||||
@ -108,71 +106,79 @@ class navigation_node_testcase extends basic_testcase {
|
||||
$this->assertSame($node3, $ref);
|
||||
}
|
||||
|
||||
public function test_add_before() {
|
||||
global $CFG;
|
||||
// Create 3 nodes
|
||||
public function test_node_add_before() {
|
||||
$this->setup_node();
|
||||
|
||||
// Create 3 nodes.
|
||||
$node1 = navigation_node::create('test_add_1', null, navigation_node::TYPE_CUSTOM,
|
||||
'test 1', 'testadd1');
|
||||
$node2 = navigation_node::create('test_add_2', null, navigation_node::TYPE_CUSTOM,
|
||||
'test 2', 'testadd2');
|
||||
$node3 = navigation_node::create('test_add_3', null, navigation_node::TYPE_CUSTOM,
|
||||
'test 3', 'testadd3');
|
||||
// Add node 2, then node 1 before 2, then node 3 at end
|
||||
// Add node 2, then node 1 before 2, then node 3 at end.
|
||||
$this->node->add_node($node2);
|
||||
$this->node->add_node($node1, 'testadd2');
|
||||
$this->node->add_node($node3);
|
||||
// Check the last 3 nodes are in 1, 2, 3 order and have those indexes
|
||||
foreach($this->node->children as $child) {
|
||||
// Check the last 3 nodes are in 1, 2, 3 order and have those indexes.
|
||||
foreach ($this->node->children as $child) {
|
||||
$keys[] = $child->key;
|
||||
}
|
||||
$this->assertEquals('testadd1', $keys[count($keys)-3]);
|
||||
$this->assertEquals('testadd2', $keys[count($keys)-2]);
|
||||
$this->assertEquals('testadd3', $keys[count($keys)-1]);
|
||||
$this->assertSame('testadd1', $keys[count($keys)-3]);
|
||||
$this->assertSame('testadd2', $keys[count($keys)-2]);
|
||||
$this->assertSame('testadd3', $keys[count($keys)-1]);
|
||||
}
|
||||
|
||||
public function test_add_class() {
|
||||
public function test_node_add_class() {
|
||||
$this->setup_node();
|
||||
|
||||
$node = $this->node->get('demo1');
|
||||
$this->assertInstanceOf('navigation_node', $node);
|
||||
if ($node !== false) {
|
||||
$node->add_class('myclass');
|
||||
$classes = $node->classes;
|
||||
$this->assertTrue(in_array('myclass', $classes));
|
||||
$this->assertContains('myclass', $classes);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_node_check_if_active() {
|
||||
$this->setup_node();
|
||||
|
||||
public function test_check_if_active() {
|
||||
// First test the string urls
|
||||
// demo1 -> action is http://www.moodle.org/, thus should be true
|
||||
// Demo1 -> action is http://www.moodle.org/, thus should be true.
|
||||
$demo5 = $this->node->find('demo5', navigation_node::TYPE_COURSE);
|
||||
if ($this->assertInstanceOf('navigation_node', $demo5)) {
|
||||
$this->assertTrue($demo5->check_if_active());
|
||||
}
|
||||
|
||||
// demo2 -> action is http://www.moodle.com/, thus should be false
|
||||
// Demo2 -> action is http://www.moodle.com/, thus should be false.
|
||||
$demo2 = $this->node->get('demo2');
|
||||
if ($this->assertInstanceOf('navigation_node', $demo2)) {
|
||||
$this->assertFalse($demo2->check_if_active());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_contains_active_node() {
|
||||
// demo5, and activity1 were set to active during setup
|
||||
// Should be true as it contains all nodes
|
||||
public function test_node_contains_active_node() {
|
||||
$this->setup_node();
|
||||
|
||||
// Demo5, and activity1 were set to active during setup.
|
||||
// Should be true as it contains all nodes.
|
||||
$this->assertTrue($this->node->contains_active_node());
|
||||
// Should be true as demo5 is a child of demo3
|
||||
// Should be true as demo5 is a child of demo3.
|
||||
$this->assertTrue($this->node->get('demo3')->contains_active_node());
|
||||
// Obviously duff
|
||||
// Obviously duff.
|
||||
$this->assertFalse($this->node->get('demo1')->contains_active_node());
|
||||
// Should be true as demo5 contains activity1
|
||||
// Should be true as demo5 contains activity1.
|
||||
$this->assertTrue($this->node->get('demo3')->get('demo5')->contains_active_node());
|
||||
// Should be true activity1 is the active node
|
||||
// Should be true activity1 is the active node.
|
||||
$this->assertTrue($this->node->get('demo3')->get('demo5')->get('activity1')->contains_active_node());
|
||||
// Obviously duff
|
||||
// Obviously duff.
|
||||
$this->assertFalse($this->node->get('demo3')->get('demo4')->contains_active_node());
|
||||
}
|
||||
|
||||
public function test_find_active_node() {
|
||||
public function test_node_find_active_node() {
|
||||
$this->setup_node();
|
||||
|
||||
$activenode1 = $this->node->find_active_node();
|
||||
$activenode2 = $this->node->get('demo1')->find_active_node();
|
||||
|
||||
@ -184,7 +190,9 @@ class navigation_node_testcase extends basic_testcase {
|
||||
$this->assertNotInstanceOf('navigation_node', $activenode2);
|
||||
}
|
||||
|
||||
public function test_find() {
|
||||
public function test_node_find() {
|
||||
$this->setup_node();
|
||||
|
||||
$node1 = $this->node->find('demo1', navigation_node::TYPE_COURSE);
|
||||
$node2 = $this->node->find('demo5', navigation_node::TYPE_COURSE);
|
||||
$node3 = $this->node->find('demo5', navigation_node::TYPE_CATEGORY);
|
||||
@ -195,44 +203,51 @@ class navigation_node_testcase extends basic_testcase {
|
||||
$this->assertNotInstanceOf('navigation_node', $node4);
|
||||
}
|
||||
|
||||
public function test_find_expandable() {
|
||||
public function test_node_find_expandable() {
|
||||
$this->setup_node();
|
||||
|
||||
$expandable = array();
|
||||
$this->node->find_expandable($expandable);
|
||||
//TODO: find out what is wrong here - it was returning 4 before the conversion
|
||||
//$this->assertEquals(count($expandable), 4);
|
||||
$this->assertEquals(count($expandable), 0);
|
||||
|
||||
$this->assertCount(0, $expandable);
|
||||
if (count($expandable) === 4) {
|
||||
$name = $expandable[0]['key'];
|
||||
$name .= $expandable[1]['key'];
|
||||
$name .= $expandable[2]['key'];
|
||||
$name .= $expandable[3]['key'];
|
||||
$this->assertEquals($name, 'demo1demo2demo4hiddendemo2');
|
||||
$this->assertSame('demo1demo2demo4hiddendemo2', $name);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_get() {
|
||||
$node1 = $this->node->get('demo1'); // Exists
|
||||
$node2 = $this->node->get('demo4'); // Doesn't exist for this node
|
||||
$node3 = $this->node->get('demo0'); // Doesn't exist at all
|
||||
$node4 = $this->node->get(false); // Sometimes occurs in nature code
|
||||
public function test_node_get() {
|
||||
$this->setup_node();
|
||||
|
||||
$node1 = $this->node->get('demo1'); // Exists.
|
||||
$node2 = $this->node->get('demo4'); // Doesn't exist for this node.
|
||||
$node3 = $this->node->get('demo0'); // Doesn't exist at all.
|
||||
$node4 = $this->node->get(false); // Sometimes occurs in nature code.
|
||||
$this->assertInstanceOf('navigation_node', $node1);
|
||||
$this->assertFalse($node2);
|
||||
$this->assertFalse($node3);
|
||||
$this->assertFalse($node4);
|
||||
}
|
||||
|
||||
public function test_get_css_type() {
|
||||
public function test_node_get_css_type() {
|
||||
$this->setup_node();
|
||||
|
||||
$csstype1 = $this->node->get('demo3')->get_css_type();
|
||||
$csstype2 = $this->node->get('demo3')->get('demo5')->get_css_type();
|
||||
$this->node->get('demo3')->get('demo5')->type = 1000;
|
||||
$csstype3 = $this->node->get('demo3')->get('demo5')->get_css_type();
|
||||
$this->assertEquals($csstype1, 'type_category');
|
||||
$this->assertEquals($csstype2, 'type_course');
|
||||
$this->assertEquals($csstype3, 'type_unknown');
|
||||
$this->assertSame('type_category', $csstype1);
|
||||
$this->assertSame('type_course', $csstype2);
|
||||
$this->assertSame('type_unknown', $csstype3);
|
||||
}
|
||||
|
||||
public function test_make_active() {
|
||||
public function test_node_make_active() {
|
||||
global $CFG;
|
||||
$this->setup_node();
|
||||
|
||||
$node1 = $this->node->add('active node 1', null, navigation_node::TYPE_CUSTOM, null, 'anode1');
|
||||
$node2 = $this->node->add('active node 2', new moodle_url($CFG->wwwroot), navigation_node::TYPE_COURSE, null, 'anode2');
|
||||
$node1->make_active();
|
||||
@ -240,7 +255,10 @@ class navigation_node_testcase extends basic_testcase {
|
||||
$this->assertTrue($node1->isactive);
|
||||
$this->assertTrue($this->node->get('anode2')->isactive);
|
||||
}
|
||||
public function test_remove() {
|
||||
|
||||
public function test_node_remove() {
|
||||
$this->setup_node();
|
||||
|
||||
$remove1 = $this->node->add('child to remove 1', null, navigation_node::TYPE_CUSTOM, null, 'remove1');
|
||||
$remove2 = $this->node->add('child to remove 2', null, navigation_node::TYPE_CUSTOM, null, 'remove2');
|
||||
$remove3 = $remove2->add('child to remove 3', null, navigation_node::TYPE_CUSTOM, null, 'remove3');
|
||||
@ -258,16 +276,16 @@ class navigation_node_testcase extends basic_testcase {
|
||||
$this->assertFalse($this->node->get('remove1'));
|
||||
$this->assertFalse(in_array('remove1', $this->node->get_children_key_list(), true));
|
||||
|
||||
// Make sure that we can insert element after removal
|
||||
// Make sure that we can insert element after removal.
|
||||
$insertelement = navigation_node::create('extra element 4', null, navigation_node::TYPE_CUSTOM, null, 'element4');
|
||||
$this->node->add_node($insertelement, 'remove2');
|
||||
$this->assertNotEmpty($this->node->get('element4'));
|
||||
|
||||
// Remove more elements
|
||||
// Remove more elements.
|
||||
$this->assertTrue($this->node->get('remove2')->remove());
|
||||
$this->assertFalse($this->node->get('remove2'));
|
||||
|
||||
// Make sure that we can add element after removal
|
||||
// Make sure that we can add element after removal.
|
||||
$this->node->add('extra element 5', null, navigation_node::TYPE_CUSTOM, null, 'element5');
|
||||
$this->assertNotEmpty($this->node->get('element5'));
|
||||
|
||||
@ -276,84 +294,21 @@ class navigation_node_testcase extends basic_testcase {
|
||||
$this->assertFalse($this->node->get('remove1'));
|
||||
$this->assertFalse($this->node->get('remove2'));
|
||||
}
|
||||
public function test_remove_class() {
|
||||
|
||||
public function test_node_remove_class() {
|
||||
$this->setup_node();
|
||||
|
||||
$this->node->add_class('testclass');
|
||||
$this->assertTrue($this->node->remove_class('testclass'));
|
||||
$this->assertFalse(in_array('testclass', $this->node->classes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a dummy object that allows us to call protected methods within the
|
||||
* global navigation class by prefixing the methods with `exposed_`
|
||||
*/
|
||||
class exposed_global_navigation extends global_navigation {
|
||||
protected $exposedkey = 'exposed_';
|
||||
public function __construct(moodle_page $page=null) {
|
||||
global $PAGE;
|
||||
if ($page === null) {
|
||||
$page = $PAGE;
|
||||
}
|
||||
parent::__construct($page);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method,$this->exposedkey) !== false) {
|
||||
$method = substr($method, strlen($this->exposedkey));
|
||||
}
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array(array($this, $method), $arguments);
|
||||
}
|
||||
throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
|
||||
}
|
||||
public function set_initialised() {
|
||||
$this->initialised = true;
|
||||
}
|
||||
}
|
||||
|
||||
class mock_initialise_global_navigation extends global_navigation {
|
||||
|
||||
static $count = 1;
|
||||
|
||||
public function load_for_category() {
|
||||
$this->add('load_for_category', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
$this->assertNotContains('testclass', $this->node->classes);
|
||||
}
|
||||
|
||||
public function load_for_course() {
|
||||
$this->add('load_for_course', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function load_for_activity() {
|
||||
$this->add('load_for_activity', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function load_for_user($user=null, $forceforcontext=false) {
|
||||
$this->add('load_for_user', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class global_navigation_testcase extends basic_testcase {
|
||||
/**
|
||||
* @var global_navigation
|
||||
*/
|
||||
public $node;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->node = new exposed_global_navigation();
|
||||
// Create an initial tree structure to work with
|
||||
$cat1 = $this->node->add('category 1', null, navigation_node::TYPE_CATEGORY, null, 'cat1');
|
||||
$cat2 = $this->node->add('category 2', null, navigation_node::TYPE_CATEGORY, null, 'cat2');
|
||||
$cat3 = $this->node->add('category 3', null, navigation_node::TYPE_CATEGORY, null, 'cat3');
|
||||
public function test_module_extends_navigation() {
|
||||
$node = new exposed_global_navigation();
|
||||
// Create an initial tree structure to work with.
|
||||
$cat1 = $node->add('category 1', null, navigation_node::TYPE_CATEGORY, null, 'cat1');
|
||||
$cat2 = $node->add('category 2', null, navigation_node::TYPE_CATEGORY, null, 'cat2');
|
||||
$cat3 = $node->add('category 3', null, navigation_node::TYPE_CATEGORY, null, 'cat3');
|
||||
$sub1 = $cat2->add('sub category 1', null, navigation_node::TYPE_CATEGORY, null, 'sub1');
|
||||
$sub2 = $cat2->add('sub category 2', null, navigation_node::TYPE_CATEGORY, null, 'sub2');
|
||||
$sub3 = $cat2->add('sub category 3', null, navigation_node::TYPE_CATEGORY, null, 'sub3');
|
||||
@ -369,56 +324,20 @@ class global_navigation_testcase extends basic_testcase {
|
||||
$res1 = $section2->add('resource 1', null, navigation_node::TYPE_RESOURCE, null, 'res1');
|
||||
$res2 = $section2->add('resource 2', null, navigation_node::TYPE_RESOURCE, null, 'res2');
|
||||
$res3 = $section2->add('resource 3', null, navigation_node::TYPE_RESOURCE, null, 'res3');
|
||||
|
||||
$this->assertTrue($node->exposed_module_extends_navigation('data'));
|
||||
$this->assertFalse($node->exposed_module_extends_navigation('test1'));
|
||||
}
|
||||
|
||||
public function test_module_extends_navigation() {
|
||||
$this->assertTrue($this->node->exposed_module_extends_navigation('data'));
|
||||
$this->assertFalse($this->node->exposed_module_extends_navigation('test1'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a dummy object that allows us to call protected methods within the
|
||||
* global navigation class by prefixing the methods with `exposed_`
|
||||
*/
|
||||
class exposed_navbar extends navbar {
|
||||
protected $exposedkey = 'exposed_';
|
||||
public function __construct(moodle_page $page) {
|
||||
parent::__construct($page);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
function __call($method, $arguments) {
|
||||
if (strpos($method,$this->exposedkey) !== false) {
|
||||
$method = substr($method, strlen($this->exposedkey));
|
||||
}
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array(array($this, $method), $arguments);
|
||||
}
|
||||
throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
|
||||
class navigation_exposed_moodle_page extends moodle_page {
|
||||
public function set_navigation(navigation_node $node) {
|
||||
$this->_navigation = $node;
|
||||
}
|
||||
}
|
||||
|
||||
class navbar_testcase extends advanced_testcase {
|
||||
protected $node;
|
||||
protected $oldnav;
|
||||
|
||||
protected function setUp() {
|
||||
public function test_navbar_add() {
|
||||
global $PAGE, $SITE;
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$PAGE->set_url('/');
|
||||
$PAGE->set_course($SITE);
|
||||
|
||||
$tempnode = new exposed_global_navigation();
|
||||
// Create an initial tree structure to work with
|
||||
// Create an initial tree structure to work with.
|
||||
$cat1 = $tempnode->add('category 1', null, navigation_node::TYPE_CATEGORY, null, 'cat1');
|
||||
$cat2 = $tempnode->add('category 2', null, navigation_node::TYPE_CATEGORY, null, 'cat2');
|
||||
$cat3 = $tempnode->add('category 3', null, navigation_node::TYPE_CATEGORY, null, 'cat3');
|
||||
@ -448,70 +367,183 @@ class navbar_testcase extends advanced_testcase {
|
||||
$navigation->set_initialised();
|
||||
$page->set_navigation($navigation);
|
||||
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
$this->node = new exposed_navbar($page);
|
||||
}
|
||||
public function test_add() {
|
||||
// Add a node with all args set
|
||||
$this->node->add('test_add_1','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd1','testadd1',new pix_icon('i/course', ''));
|
||||
// Add a node with the minimum args required
|
||||
$this->node->add('test_add_2','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd2','testadd2',new pix_icon('i/course', ''));
|
||||
$this->assertInstanceOf('navigation_node', $this->node->get('testadd1'));
|
||||
$this->assertInstanceOf('navigation_node', $this->node->get('testadd2'));
|
||||
}
|
||||
public function test_has_items() {
|
||||
$this->assertTrue($this->node->has_items());
|
||||
}
|
||||
}
|
||||
$cache = new navigation_cache('unittest_nav');
|
||||
$node = new exposed_navbar($page);
|
||||
|
||||
class navigation_cache_testcase extends basic_testcase {
|
||||
protected $cache;
|
||||
// Add a node with all args set.
|
||||
$node->add('test_add_1', 'http://www.moodle.org/', navigation_node::TYPE_COURSE, 'testadd1', 'testadd1', new pix_icon('i/course', ''));
|
||||
// Add a node with the minimum args required.
|
||||
$node->add('test_add_2', 'http://www.moodle.org/', navigation_node::TYPE_COURSE, 'testadd2', 'testadd2', new pix_icon('i/course', ''));
|
||||
$this->assertInstanceOf('navigation_node', $node->get('testadd1'));
|
||||
$this->assertInstanceOf('navigation_node', $node->get('testadd2'));
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
return $node;
|
||||
}
|
||||
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
$this->cache->anysetvariable = true;
|
||||
/**
|
||||
* @depends test_navbar_add
|
||||
* @param $node
|
||||
*/
|
||||
public function test_navbar_has_items($node) {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->assertTrue($node->has_items());
|
||||
}
|
||||
public function test___get() {
|
||||
$this->assertTrue($this->cache->anysetvariable);
|
||||
$this->assertEquals($this->cache->notasetvariable, null);
|
||||
|
||||
public function test_cache__get() {
|
||||
$cache = new navigation_cache('unittest_nav');
|
||||
$cache->anysetvariable = true;
|
||||
|
||||
$this->assertTrue($cache->anysetvariable);
|
||||
$this->assertEquals($cache->notasetvariable, null);
|
||||
}
|
||||
public function test___set() {
|
||||
$this->cache->myname = 'Sam Hemelryk';
|
||||
$this->assertTrue($this->cache->cached('myname'));
|
||||
$this->assertEquals($this->cache->myname, 'Sam Hemelryk');
|
||||
|
||||
public function test_cache__set() {
|
||||
$cache = new navigation_cache('unittest_nav');
|
||||
$cache->anysetvariable = true;
|
||||
|
||||
$cache->myname = 'Sam Hemelryk';
|
||||
$this->assertTrue($cache->cached('myname'));
|
||||
$this->assertSame('Sam Hemelryk', $cache->myname);
|
||||
}
|
||||
public function test_cached() {
|
||||
$this->assertTrue($this->cache->cached('anysetvariable'));
|
||||
$this->assertFalse($this->cache->cached('notasetvariable'));
|
||||
|
||||
public function test_cache_cached() {
|
||||
$cache = new navigation_cache('unittest_nav');
|
||||
$cache->anysetvariable = true;
|
||||
|
||||
$this->assertTrue($cache->cached('anysetvariable'));
|
||||
$this->assertFalse($cache->cached('notasetvariable'));
|
||||
}
|
||||
public function test_clear() {
|
||||
$cache = clone($this->cache);
|
||||
|
||||
public function test_cache_clear() {
|
||||
$cache = new navigation_cache('unittest_nav');
|
||||
$cache->anysetvariable = true;
|
||||
|
||||
$cache = clone($cache);
|
||||
$this->assertTrue($cache->cached('anysetvariable'));
|
||||
$cache->clear();
|
||||
$this->assertFalse($cache->cached('anysetvariable'));
|
||||
}
|
||||
public function test_set() {
|
||||
$this->cache->set('software', 'Moodle');
|
||||
$this->assertTrue($this->cache->cached('software'));
|
||||
$this->assertEquals($this->cache->software, 'Moodle');
|
||||
|
||||
public function test_cache_set() {
|
||||
$cache = new navigation_cache('unittest_nav');
|
||||
$cache->anysetvariable = true;
|
||||
|
||||
$cache->set('software', 'Moodle');
|
||||
$this->assertTrue($cache->cached('software'));
|
||||
$this->assertEquals($cache->software, 'Moodle');
|
||||
}
|
||||
|
||||
public function test_setting___construct() {
|
||||
global $PAGE, $SITE;
|
||||
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$PAGE->set_url('/');
|
||||
$PAGE->set_course($SITE);
|
||||
|
||||
$node = new exposed_settings_navigation();
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_setting___construct
|
||||
* @param mixed $node
|
||||
* @return mixed
|
||||
*/
|
||||
public function test_setting__initialise($node) {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$node->initialise();
|
||||
$this->assertEquals($node->id, 'settingsnav');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_setting__initialise
|
||||
* @param mixed $node
|
||||
* @return mixed
|
||||
*/
|
||||
public function test_setting_in_alternative_role($node) {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->assertFalse($node->exposed_in_alternative_role());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a dummy object that allows us to call protected methods within the
|
||||
* global navigation class by prefixing the methods with `exposed_`
|
||||
*/
|
||||
class exposed_settings_navigation extends settings_navigation {
|
||||
class exposed_global_navigation extends global_navigation {
|
||||
protected $exposedkey = 'exposed_';
|
||||
function __construct() {
|
||||
public function __construct(moodle_page $page=null) {
|
||||
global $PAGE;
|
||||
parent::__construct($PAGE);
|
||||
if ($page === null) {
|
||||
$page = $PAGE;
|
||||
}
|
||||
parent::__construct($page);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
function __call($method, $arguments) {
|
||||
if (strpos($method,$this->exposedkey) !== false) {
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method, $this->exposedkey) !== false) {
|
||||
$method = substr($method, strlen($this->exposedkey));
|
||||
}
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array(array($this, $method), $arguments);
|
||||
}
|
||||
throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
|
||||
}
|
||||
public function set_initialised() {
|
||||
$this->initialised = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class mock_initialise_global_navigation extends global_navigation {
|
||||
|
||||
protected static $count = 1;
|
||||
|
||||
public function load_for_category() {
|
||||
$this->add('load_for_category', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function load_for_course() {
|
||||
$this->add('load_for_course', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function load_for_activity() {
|
||||
$this->add('load_for_activity', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function load_for_user($user=null, $forceforcontext=false) {
|
||||
$this->add('load_for_user', null, null, null, 'initcall'.self::$count);
|
||||
self::$count++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a dummy object that allows us to call protected methods within the
|
||||
* global navigation class by prefixing the methods with `exposed_`.
|
||||
*/
|
||||
class exposed_navbar extends navbar {
|
||||
protected $exposedkey = 'exposed_';
|
||||
public function __construct(moodle_page $page) {
|
||||
parent::__construct($page);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method, $this->exposedkey) !== false) {
|
||||
$method = substr($method, strlen($this->exposedkey));
|
||||
}
|
||||
if (method_exists($this, $method)) {
|
||||
@ -521,30 +553,30 @@ class exposed_settings_navigation extends settings_navigation {
|
||||
}
|
||||
}
|
||||
|
||||
class settings_navigation_testcase extends advanced_testcase {
|
||||
protected $node;
|
||||
protected $cache;
|
||||
|
||||
protected function setUp() {
|
||||
global $PAGE, $SITE;
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$PAGE->set_url('/');
|
||||
$PAGE->set_course($SITE);
|
||||
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
$this->node = new exposed_settings_navigation();
|
||||
}
|
||||
public function test___construct() {
|
||||
$this->node = new exposed_settings_navigation();
|
||||
}
|
||||
public function test___initialise() {
|
||||
$this->node->initialise();
|
||||
$this->assertEquals($this->node->id, 'settingsnav');
|
||||
}
|
||||
public function test_in_alternative_role() {
|
||||
$this->assertFalse($this->node->exposed_in_alternative_role());
|
||||
class navigation_exposed_moodle_page extends moodle_page {
|
||||
public function set_navigation(navigation_node $node) {
|
||||
$this->_navigation = $node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a dummy object that allows us to call protected methods within the
|
||||
* global navigation class by prefixing the methods with `exposed_`.
|
||||
*/
|
||||
class exposed_settings_navigation extends settings_navigation {
|
||||
protected $exposedkey = 'exposed_';
|
||||
public function __construct() {
|
||||
global $PAGE;
|
||||
parent::__construct($PAGE);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method, $this->exposedkey) !== false) {
|
||||
$method = substr($method, strlen($this->exposedkey));
|
||||
}
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array(array($this, $method), $arguments);
|
||||
}
|
||||
throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ global $CFG;
|
||||
require_once($CFG->libdir . '/outputcomponents.php');
|
||||
|
||||
/**
|
||||
* Unit tests for the user_picture class
|
||||
* Unit tests for the user_picture class.
|
||||
*/
|
||||
class outputcomponents_testcase extends advanced_testcase {
|
||||
class core_outputcomponents_testcase extends advanced_testcase {
|
||||
|
||||
public function test_fields_aliasing() {
|
||||
$fields = user_picture::fields();
|
||||
@ -49,7 +49,7 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
|
||||
$returned = user_picture::fields('', array('custom1', 'id'), 'aliasedid', 'prefix');
|
||||
$returned = array_map('trim', explode(',', $returned));
|
||||
$this->assertEquals(count($returned), count($fields) + 1); // only one extra field added
|
||||
$this->assertEquals(count($returned), count($fields) + 1); // Only one extra field added.
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if ($field === 'id') {
|
||||
@ -57,9 +57,9 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
} else {
|
||||
$expected = "$field AS prefix$field";
|
||||
}
|
||||
$this->assertTrue(in_array($expected, $returned), "Expected pattern '$expected' not returned");
|
||||
$this->assertContains($expected, $returned, "Expected pattern '$expected' not returned");
|
||||
}
|
||||
$this->assertTrue(in_array("custom1 AS prefixcustom1", $returned), "Expected pattern 'custom1 AS prefixcustom1' not returned");
|
||||
$this->assertContains("custom1 AS prefixcustom1", $returned, "Expected pattern 'custom1 AS prefixcustom1' not returned");
|
||||
}
|
||||
|
||||
public function test_fields_unaliasing() {
|
||||
@ -77,13 +77,13 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
|
||||
$returned = user_picture::unalias($fakerecord, array('custom1'), 'aliasedid', 'prefix');
|
||||
|
||||
$this->assertEquals($returned->id, 42);
|
||||
$this->assertEquals(42, $returned->id);
|
||||
foreach ($fields as $field) {
|
||||
if ($field !== 'id') {
|
||||
$this->assertEquals($returned->{$field}, "Value of $field");
|
||||
$this->assertSame("Value of $field", $returned->{$field});
|
||||
}
|
||||
}
|
||||
$this->assertEquals($returned->custom1, 'Value of custom1');
|
||||
$this->assertSame('Value of custom1', $returned->custom1);
|
||||
}
|
||||
|
||||
public function test_fields_unaliasing_null() {
|
||||
@ -102,14 +102,14 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
|
||||
$returned = user_picture::unalias($fakerecord, array('custom1'), 'aliasedid', 'prefix');
|
||||
|
||||
$this->assertEquals($returned->id, 42);
|
||||
$this->assertEquals($returned->imagealt, null);
|
||||
$this->assertEquals(42, $returned->id);
|
||||
$this->assertNull($returned->imagealt);
|
||||
foreach ($fields as $field) {
|
||||
if ($field !== 'id' and $field !== 'imagealt') {
|
||||
$this->assertEquals($returned->{$field}, "Value of $field");
|
||||
$this->assertSame("Value of $field", $returned->{$field});
|
||||
}
|
||||
}
|
||||
$this->assertEquals($returned->custom1, 'Value of custom1');
|
||||
$this->assertSame('Value of custom1', $returned->custom1);
|
||||
}
|
||||
|
||||
public function test_get_url() {
|
||||
@ -120,17 +120,17 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
// Force SVG on so that we have predictable URL's.
|
||||
$CFG->svgicons = true;
|
||||
|
||||
// verify new install contains expected defaults
|
||||
$this->assertEquals('standard', $CFG->theme);
|
||||
// Verify new install contains expected defaults.
|
||||
$this->assertSame('standard', $CFG->theme);
|
||||
$this->assertEquals(1, $CFG->slasharguments);
|
||||
$this->assertEquals(1, $CFG->themerev);
|
||||
$this->assertEquals(0, $CFG->themedesignermode);
|
||||
$this->assertEquals('http://www.example.com/moodle', $CFG->wwwroot);
|
||||
$this->assertEquals($CFG->wwwroot, $CFG->httpswwwroot);
|
||||
$this->assertSame('http://www.example.com/moodle', $CFG->wwwroot);
|
||||
$this->assertSame($CFG->wwwroot, $CFG->httpswwwroot);
|
||||
$this->assertEquals(0, $CFG->enablegravatar);
|
||||
$this->assertEquals('mm', $CFG->gravatardefaulturl);
|
||||
$this->assertSame('mm', $CFG->gravatardefaulturl);
|
||||
|
||||
// create some users
|
||||
// Create some users.
|
||||
$page = new moodle_page();
|
||||
$page->set_url('/user/profile.php');
|
||||
$page->set_context(context_system::instance());
|
||||
@ -143,95 +143,95 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
|
||||
$user3 = $this->getDataGenerator()->create_user(array('picture'=>1, 'deleted'=>1, 'email'=>'user3@example.com'));
|
||||
$context3 = context_user::instance($user3->id, IGNORE_MISSING);
|
||||
$this->assertEquals($user3->picture, 0);
|
||||
$this->assertNotEquals($user3->email, 'user3@example.com');
|
||||
$this->assertEquals(0, $user3->picture);
|
||||
$this->assertNotEquals('user3@example.com', $user3->email);
|
||||
$this->assertFalse($context3);
|
||||
|
||||
// try legacy picture == 1
|
||||
// Try legacy picture == 1.
|
||||
$user1->picture = 1;
|
||||
$up1 = new user_picture($user1);
|
||||
$this->assertEquals($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=1', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=1', $up1->get_url($page, $renderer)->out(false));
|
||||
$user1->picture = 11;
|
||||
|
||||
// try valid user with picture when user context is not cached - 1 query expected
|
||||
// Try valid user with picture when user context is not cached - 1 query expected.
|
||||
context_helper::reset_caches();
|
||||
$reads = $DB->perf_get_reads();
|
||||
$up1 = new user_picture($user1);
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
$this->assertEquals($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertEquals($reads+1, $DB->perf_get_reads());
|
||||
|
||||
// try valid user with contextid hint - no queries expected
|
||||
// Try valid user with contextid hint - no queries expected.
|
||||
$user1->contextid = $context1->id;
|
||||
context_helper::reset_caches();
|
||||
$reads = $DB->perf_get_reads();
|
||||
$up1 = new user_picture($user1);
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
$this->assertEquals($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
|
||||
// try valid user without image - no queries expected
|
||||
// Try valid user without image - no queries expected.
|
||||
context_helper::reset_caches();
|
||||
$reads = $DB->perf_get_reads();
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
$this->assertEquals($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
|
||||
// try guessing of deleted users - no queries expected
|
||||
// Try guessing of deleted users - no queries expected.
|
||||
unset($user3->deleted);
|
||||
context_helper::reset_caches();
|
||||
$reads = $DB->perf_get_reads();
|
||||
$up3 = new user_picture($user3);
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
$this->assertEquals($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
|
||||
// try incorrectly deleted users (with valid email and pciture flag) - some DB reads expected
|
||||
// Try incorrectly deleted users (with valid email and pciture flag) - some DB reads expected.
|
||||
$user3->email = 'user3@example.com';
|
||||
$user3->picture = 1;
|
||||
$reads = $DB->perf_get_reads();
|
||||
$up3 = new user_picture($user3);
|
||||
$this->assertEquals($reads, $DB->perf_get_reads());
|
||||
$this->assertEquals($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertTrue($reads < $DB->perf_get_reads());
|
||||
$this->assertSame($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertGreaterThan($reads, $DB->perf_get_reads());
|
||||
|
||||
// test gravatar
|
||||
// Test gravatar.
|
||||
set_config('enablegravatar', 1);
|
||||
|
||||
// deleted user can not have gravatar
|
||||
// Deleted user can not have gravatar.
|
||||
$user3->email = 'deleted';
|
||||
$user3->picture = 0;
|
||||
$up3 = new user_picture($user3);
|
||||
$this->assertEquals($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
|
||||
// verify defaults to misteryman (mm)
|
||||
// Verify defaults to misteryman (mm).
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false));
|
||||
|
||||
// without gravatardefaulturl, verify we pick own file
|
||||
// Without gravatardefaulturl, verify we pick own file.
|
||||
set_config('gravatardefaulturl', '');
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
// uploaded image takes precedence before gravatar
|
||||
$this->assertSame('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
// Uploaded image takes precedence before gravatar.
|
||||
$up1 = new user_picture($user1);
|
||||
$this->assertEquals($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
|
||||
// https version
|
||||
// Https version.
|
||||
$CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
|
||||
|
||||
$up1 = new user_picture($user1);
|
||||
$this->assertEquals($CFG->httpswwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->httpswwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
|
||||
$up3 = new user_picture($user3);
|
||||
$this->assertEquals($CFG->httpswwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->httpswwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
|
||||
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
|
||||
// now test gravatar with one theme having own images (afterburner)
|
||||
// Now test gravatar with one theme having own images (afterburner).
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
$this->assertTrue(file_exists("$CFG->dirroot/theme/afterburner/config.php"));
|
||||
$this->assertFileExists("$CFG->dirroot/theme/afterburner/config.php");
|
||||
set_config('theme', 'afterburner');
|
||||
$page = new moodle_page();
|
||||
$page->set_url('/user/profile.php');
|
||||
@ -241,16 +241,16 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
|
||||
// https version
|
||||
// Https version.
|
||||
$CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
|
||||
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
// end of gravatar tests
|
||||
$this->assertSame('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
|
||||
// End of gravatar tests.
|
||||
|
||||
// test themed images
|
||||
// Test themed images.
|
||||
set_config('enablegravatar', 0);
|
||||
$this->assertTrue(file_exists("$CFG->dirroot/theme/formal_white/config.php")); // use any other theme
|
||||
$this->assertFileExists("$CFG->dirroot/theme/formal_white/config.php"); // Use any other theme.
|
||||
set_config('theme', 'formal_white');
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
$page = new moodle_page();
|
||||
@ -259,12 +259,12 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
$renderer = $page->get_renderer('core');
|
||||
|
||||
$up1 = new user_picture($user1);
|
||||
$this->assertEquals($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/formal_white/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/formal_white/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
|
||||
|
||||
$up2 = new user_picture($user2);
|
||||
$this->assertEquals($CFG->wwwroot.'/theme/image.php/formal_white/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/theme/image.php/formal_white/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
|
||||
|
||||
// test non-slashargument images
|
||||
// Test non-slashargument images.
|
||||
set_config('theme', 'standard');
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
$CFG->slasharguments = 0;
|
||||
@ -274,12 +274,12 @@ class outputcomponents_testcase extends advanced_testcase {
|
||||
$renderer = $page->get_renderer('core');
|
||||
|
||||
$up3 = new user_picture($user3);
|
||||
$this->assertEquals($CFG->wwwroot.'/theme/image.php?theme=standard&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false));
|
||||
$this->assertSame($CFG->wwwroot.'/theme/image.php?theme=standard&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false));
|
||||
}
|
||||
|
||||
public function test_empty_menu() {
|
||||
$emptymenu = new custom_menu();
|
||||
$this->assertTrue($emptymenu instanceof custom_menu);
|
||||
$this->assertInstanceOf('custom_menu', $emptymenu);
|
||||
$this->assertFalse($emptymenu->has_children());
|
||||
}
|
||||
|
||||
@ -297,33 +297,33 @@ Moodle company
|
||||
EOF;
|
||||
|
||||
$menu = new custom_menu($definition);
|
||||
$this->assertTrue($menu instanceof custom_menu);
|
||||
$this->assertInstanceOf('custom_menu', $menu);
|
||||
$this->assertTrue($menu->has_children());
|
||||
$firstlevel = $menu->get_children();
|
||||
$this->assertTrue(is_array($firstlevel));
|
||||
$this->assertEquals(2, count($firstlevel));
|
||||
$this->assertCount(2, $firstlevel);
|
||||
|
||||
$item = array_shift($firstlevel);
|
||||
$this->assertTrue($item instanceof custom_menu_item);
|
||||
$this->assertInstanceOf('custom_menu_item', $item);
|
||||
$this->assertTrue($item->has_children());
|
||||
$this->assertEquals(3, count($item->get_children()));
|
||||
$this->assertCount(3, $item->get_children());
|
||||
$this->assertEquals('Moodle community', $item->get_text());
|
||||
$itemurl = $item->get_url();
|
||||
$this->assertTrue($itemurl instanceof moodle_url);
|
||||
$this->assertEquals('http://moodle.org', $itemurl->out());
|
||||
$this->assertEquals($item->get_text(), $item->get_title()); // implicit title
|
||||
$this->assertEquals($item->get_text(), $item->get_title()); // Implicit title.
|
||||
|
||||
$item = array_shift($firstlevel);
|
||||
$this->assertTrue($item->has_children());
|
||||
$this->assertEquals(2, count($item->get_children()));
|
||||
$this->assertEquals('Moodle company', $item->get_text());
|
||||
$this->assertTrue(is_null($item->get_url()));
|
||||
$this->assertCount(2, $item->get_children());
|
||||
$this->assertSame('Moodle company', $item->get_text());
|
||||
$this->assertNull($item->get_url());
|
||||
|
||||
$children = $item->get_children();
|
||||
$subitem = array_shift($children);
|
||||
$this->assertFalse($subitem->has_children());
|
||||
$this->assertEquals('Hosting', $subitem->get_text());
|
||||
$this->assertEquals('Commercial hosting', $subitem->get_title());
|
||||
$this->assertSame('Hosting', $subitem->get_text());
|
||||
$this->assertSame('Commercial hosting', $subitem->get_title());
|
||||
}
|
||||
|
||||
public function test_multilang_support() {
|
||||
@ -334,53 +334,53 @@ Info
|
||||
-Deutsch|http://school.info/de|Informationen in deutscher Sprache|de,de_du,de_kids
|
||||
EOF;
|
||||
|
||||
// the menu without multilang support
|
||||
// The menu without multilang support.
|
||||
$menu = new custom_menu($definition);
|
||||
$this->assertTrue($menu->has_children());
|
||||
$this->assertEquals(2, count($menu->get_children()));
|
||||
$this->assertCount(2, $menu->get_children());
|
||||
|
||||
$children = $menu->get_children();
|
||||
$infomenu = array_pop($children);
|
||||
$this->assertTrue($infomenu->has_children());
|
||||
$children = $infomenu->get_children();
|
||||
$this->assertEquals(2, count($children));
|
||||
$this->assertCount(2, $children);
|
||||
|
||||
$children = $infomenu->get_children();
|
||||
$langspecinfo = array_shift($children);
|
||||
$this->assertEquals('Information in English', $langspecinfo->get_title());
|
||||
$this->assertSame('Information in English', $langspecinfo->get_title());
|
||||
|
||||
// same menu for English language selected
|
||||
// Same menu for English language selected.
|
||||
$menu = new custom_menu($definition, 'en');
|
||||
$this->assertTrue($menu->has_children());
|
||||
$this->assertEquals(2, count($menu->get_children()));
|
||||
$this->assertCount(2, $menu->get_children());
|
||||
|
||||
$children = $menu->get_children();
|
||||
$infomenu = array_pop($children);
|
||||
$this->assertTrue($infomenu->has_children());
|
||||
$this->assertEquals(1, count($infomenu->get_children()));
|
||||
$this->assertCount(1, $infomenu->get_children());
|
||||
|
||||
$children = $infomenu->get_children();
|
||||
$langspecinfo = array_shift($children);
|
||||
$this->assertEquals('Information in English', $langspecinfo->get_title());
|
||||
$this->assertSame('Information in English', $langspecinfo->get_title());
|
||||
|
||||
// same menu for German (de_du) language selected
|
||||
// Same menu for German (de_du) language selected.
|
||||
$menu = new custom_menu($definition, 'de_du');
|
||||
$this->assertTrue($menu->has_children());
|
||||
$this->assertEquals(2, count($menu->get_children()));
|
||||
$this->assertCount(2, $menu->get_children());
|
||||
|
||||
$children = $menu->get_children();
|
||||
$infomenu = array_pop($children);
|
||||
$this->assertTrue($infomenu->has_children());
|
||||
$this->assertEquals(1, count($infomenu->get_children()));
|
||||
$this->assertCount(1, $infomenu->get_children());
|
||||
|
||||
$children = $infomenu->get_children();
|
||||
$langspecinfo = array_shift($children);
|
||||
$this->assertEquals('Informationen in deutscher Sprache', $langspecinfo->get_title());
|
||||
$this->assertSame('Informationen in deutscher Sprache', $langspecinfo->get_title());
|
||||
|
||||
// same menu for Czech language selected
|
||||
// Same menu for Czech language selected.
|
||||
$menu = new custom_menu($definition, 'cs');
|
||||
$this->assertTrue($menu->has_children());
|
||||
$this->assertEquals(2, count($menu->get_children()));
|
||||
$this->assertCount(2, $menu->get_children());
|
||||
|
||||
$children = $infomenu->get_children();
|
||||
$infomenu = array_pop( $children);
|
||||
@ -407,12 +407,12 @@ EOF;
|
||||
$mpage = new moodle_page();
|
||||
$rbase = new renderer_base($mpage, "/");
|
||||
$pbara = new paging_bar(40, 0, 5, 'index.php');
|
||||
$pbara->prepare($rbase,$mpage, "/");
|
||||
$pbara->prepare($rbase, $mpage, "/");
|
||||
$pbarb = new paging_bar(100, 5, 5, 'page');
|
||||
$pbarb->maxdisplay = 5;
|
||||
$pbarb->prepare($rbase,$mpage,"/");
|
||||
$pbarb->prepare($rbase, $mpage, "/");
|
||||
|
||||
$this->assertEquals($pbara->pagelinks, $expecteda);
|
||||
$this->assertEquals($pbarb->pagelinks, $expectedb);
|
||||
$this->assertEquals($expecteda, $pbara->pagelinks);
|
||||
$this->assertEquals($expectedb, $pbarb->pagelinks);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user