Permalink
Browse files

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

  • Loading branch information...
1 parent 661777c commit 5dffc067da26f3e345efb1cbb6fb2f9f8a6d8f35 @ybozhko ybozhko committed Aug 18, 2013
Showing with 33 additions and 1 deletion.
  1. +1 −0 lib/phpunit/classes/util.php
  2. +27 −0 lib/phpunit/tests/advanced_test.php
  3. +5 −1 message/lib.php
@@ -187,6 +187,7 @@ public static function reset_all_data($detectchanges = false) {
reset_text_filters_cache(true);
events_get_handlers('reset');
textlib::reset_caches();
+ get_message_processors(false, true);
if (class_exists('repository')) {
repository::reset_caches();
}
@@ -340,6 +340,33 @@ public function test_load_dataset() {
$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
@@ -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

0 comments on commit 5dffc06

Please sign in to comment.