MDL-49664 renderers: Verify expected render methods are called.

For various renderables (core, plugin, namespaced), all them
against the base and plugin renderers.
This commit is contained in:
Eloy Lafuente (stronk7)
2015-04-27 18:41:24 +02:00
parent e47d9d12c6
commit a9074a2649
2 changed files with 66 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
<?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 something\largely\namespaced;
defined('MOODLE_INTERNAL') || die;
/**
* Simple namespaced renderable class to verify corresponding render methods are called correctly
*/
class renderable_test implements \renderable {
}
+41
View File
@@ -416,4 +416,45 @@ EOF;
$this->assertEquals($expecteda, $pbara->pagelinks);
$this->assertEquals($expectedb, $pbarb->pagelinks);
}
public function test_renderer_method_names() {
global $CFG;
// Note, here we don't verify autoloading at all, but only that
// the renderers call to the correct methods no matter the renderable class
// is namespaced or no. Hence we are loading the needed fixtures manually.
require_once($CFG->dirroot . '/mod/assign/renderable.php');
require_once($CFG->libdir . '/tests/fixtures/namespaced_renderable.php');
// Array of renderable widgets to verify that renderers
// do call to the expected render method. Indexes are the expected
// method and values are the renderable instances.
$renderables = array(
'render_pix_icon' => new pix_icon('test', 'test'), // A core one.
'render_assign_course_index_summary' => new assign_course_index_summary(true, 'test'), // A plugin one.
'render_renderable_test' => new \something\largely\namespaced\renderable_test(), // A namespaced one.
);
// We are going to test all the renderables agains some different renderers.
$renderers = array(
'renderer_base',
'plugin_renderer_base'
);
// Run all combinations.
foreach ($renderables as $method => $renderable) {
foreach ($renderers as $renderer) {
// Create the double with the expected method mocked.
$stub = $this->getMockBuilder($renderer)
->disableOriginalConstructor()
->setMethods(array($method))
->getMock();
// Expect the method is called once and will return true.
$stub->expects($this->once())
->method($method)
->will($this->returnValue(true));
// Assert the return value and verify the expectation.
$this->assertTrue($stub->render($renderable));
}
}
}
}