See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
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 /** 18 * Unit tests for core\notification. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Unit tests for core\notification. 30 * 31 * @package core 32 * @category phpunit 33 * @category phpunit 34 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class core_notification_testcase extends advanced_testcase { 38 39 /** 40 * Setup required for all notification tests. 41 * 42 * This includes emptying the list of notifications on the session, resetting any session which exists, and setting 43 * up a new moodle_page object. 44 */ 45 public function setUp() { 46 global $PAGE, $SESSION; 47 48 parent::setUp(); 49 $PAGE = new moodle_page(); 50 \core\session\manager::init_empty_session(); 51 $SESSION->notifications = []; 52 } 53 54 /** 55 * Tear down required for all notification tests. 56 * 57 * This includes emptying the list of notifications on the session, resetting any session which exists, and setting 58 * up a new moodle_page object. 59 */ 60 public function tearDown() { 61 global $PAGE, $SESSION; 62 63 $PAGE = null; 64 \core\session\manager::init_empty_session(); 65 $SESSION->notifications = []; 66 parent::tearDown(); 67 } 68 69 /** 70 * Test the way in which notifications are added to the session in different stages of the page load. 71 */ 72 public function test_add_during_output_stages() { 73 global $PAGE, $SESSION; 74 75 \core\notification::add('Example before header', \core\notification::INFO); 76 $this->assertCount(1, $SESSION->notifications); 77 78 $PAGE->set_state(\moodle_page::STATE_PRINTING_HEADER); 79 \core\notification::add('Example during header', \core\notification::INFO); 80 $this->assertCount(2, $SESSION->notifications); 81 82 $PAGE->set_state(\moodle_page::STATE_IN_BODY); 83 \core\notification::add('Example in body', \core\notification::INFO); 84 $this->expectOutputRegex('/Example in body/'); 85 $this->assertCount(2, $SESSION->notifications); 86 87 $PAGE->set_state(\moodle_page::STATE_DONE); 88 \core\notification::add('Example after page', \core\notification::INFO); 89 $this->assertCount(3, $SESSION->notifications); 90 } 91 92 /** 93 * Test fetching of notifications from the session. 94 */ 95 public function test_fetch() { 96 // Initially there won't be any notifications. 97 $this->assertCount(0, \core\notification::fetch()); 98 99 // Adding a notification should make one available to fetch. 100 \core\notification::success('Notification created'); 101 $this->assertCount(1, \core\notification::fetch()); 102 $this->assertCount(0, \core\notification::fetch()); 103 } 104 105 /** 106 * Test that session notifications are persisted across session clears. 107 */ 108 public function test_session_persistance() { 109 global $PAGE, $SESSION; 110 111 // Initially there won't be any notifications. 112 $this->assertCount(0, $SESSION->notifications); 113 114 // Adding a notification should make one available to fetch. 115 \core\notification::success('Notification created'); 116 $this->assertCount(1, $SESSION->notifications); 117 118 // Re-creating the session will not empty the notification bag. 119 \core\session\manager::init_empty_session(); 120 $this->assertCount(1, $SESSION->notifications); 121 } 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body