MDL-41228 phpunit: Reset message processors list in unit tests

This commit is contained in:
Yuliya Bozhko 2013-08-19 08:40:57 +12:00
parent 838d78a9ff
commit ed23ad31c7
3 changed files with 33 additions and 1 deletions

View File

@ -194,6 +194,7 @@ class phpunit_util extends testing_util {
reset_text_filters_cache(true);
events_get_handlers('reset');
core_text::reset_caches();
get_message_processors(false, true);
if (class_exists('repository')) {
repository::reset_caches();
}

View File

@ -340,6 +340,33 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
$this->assertTrue($DB->record_exists('user', array('username'=>'onemore')));
}
public function test_message_processors_reset() {
global $DB;
$this->resetAfterTest(true);
// Get all processors first.
$processors1 = get_message_processors();
// Add a new message processor and get all processors again.
$processor = new stdClass();
$processor->name = 'test_processor';
$processor->enabled = 1;
$DB->insert_record('message_processors', $processor);
$processors2 = get_message_processors();
// Assert that new processor still haven't been added to the list.
$this->assertSame($processors1, $processors2);
// Reset message processors data.
$processors3 = get_message_processors(false, true);
// Now, list of processors should not be the same any more,
// And we should have one more message processor in the list.
$this->assertNotSame($processors1, $processors3);
$this->assertEquals(count($processors1) + 1, count($processors3));
}
public function test_message_redirection() {
global $DB;

View File

@ -2280,12 +2280,16 @@ function message_print_heading($title, $colspan=3) {
* system configuration
*
* @param bool $ready only return ready-to-use processors
* @param bool $reset Reset list of message processors (used in unit tests)
* @return mixed $processors array of objects containing information on message processors
*/
function get_message_processors($ready = false) {
function get_message_processors($ready = false, $reset = false) {
global $DB, $CFG;
static $processors;
if ($reset) {
$processors = array();
}
if (empty($processors)) {
// Get all processors, ensure the name column is the first so it will be the array key