~ubuntu-branches/ubuntu/saucy/moodle/saucy

« back to all changes in this revision

Viewing changes to lib/phpunit/classes/util.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-09-09 15:22:35 UTC
  • mfrom: (1.1.17) (3.1.29 sid)
  • Revision ID: package-import@ubuntu.com-20130909152235-f5g7gphaseb84qeu
Tags: 2.5.2-1
* New upstream version: 2.5.2.
  - Incorporates S3 security patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    /** @var phpunit_message_sink alternative target for moodle messaging */
44
44
    protected static $messagesink = null;
45
45
 
 
46
    /** @var phpunit_phpmailer_sink alternative target for phpmailer messaging */
 
47
    protected static $phpmailersink = null;
 
48
 
46
49
    /**
47
50
     * @var array Files to skip when resetting dataroot folder
48
51
     */
95
98
        // Stop any message redirection.
96
99
        phpunit_util::stop_message_redirection();
97
100
 
 
101
        // Stop any message redirection.
 
102
        phpunit_util::stop_phpmailer_redirection();
 
103
 
98
104
        // Release memory and indirectly call destroy() methods to release resource handles, etc.
99
105
        gc_collect_cycles();
100
106
 
160
166
        $_SERVER = self::get_global_backup('_SERVER');
161
167
        $CFG = self::get_global_backup('CFG');
162
168
        $SITE = self::get_global_backup('SITE');
 
169
        $_GET = array();
 
170
        $_POST = array();
 
171
        $_FILES = array();
 
172
        $_REQUEST = array();
163
173
        $COURSE = $SITE;
164
174
 
165
175
        // reinitialise following globals
656
666
            self::$messagesink->add_message($message);
657
667
        }
658
668
    }
 
669
 
 
670
    /**
 
671
     * Start phpmailer redirection.
 
672
     *
 
673
     * Note: Do not call directly from tests,
 
674
     *       use $sink = $this->redirectEmails() instead.
 
675
     *
 
676
     * @return phpunit_phpmailer_sink
 
677
     */
 
678
    public static function start_phpmailer_redirection() {
 
679
        if (self::$phpmailersink) {
 
680
            self::stop_phpmailer_redirection();
 
681
        }
 
682
        self::$phpmailersink = new phpunit_phpmailer_sink();
 
683
        return self::$phpmailersink;
 
684
    }
 
685
 
 
686
    /**
 
687
     * End phpmailer redirection.
 
688
     *
 
689
     * Note: Do not call directly from tests,
 
690
     *       use $sink->close() instead.
 
691
     */
 
692
    public static function stop_phpmailer_redirection() {
 
693
        self::$phpmailersink = null;
 
694
    }
 
695
 
 
696
    /**
 
697
     * Are messages for phpmailer redirected to some sink?
 
698
     *
 
699
     * Note: to be called from moodle_phpmailer.php only!
 
700
     *
 
701
     * @return bool
 
702
     */
 
703
    public static function is_redirecting_phpmailer() {
 
704
        return !empty(self::$phpmailersink);
 
705
    }
 
706
 
 
707
    /**
 
708
     * To be called from messagelib.php only!
 
709
     *
 
710
     * @param stdClass $message record from message_read table
 
711
     * @return bool true means send message, false means message "sent" to sink.
 
712
     */
 
713
    public static function phpmailer_sent($message) {
 
714
        if (self::$phpmailersink) {
 
715
            self::$phpmailersink->add_message($message);
 
716
        }
 
717
    }
659
718
}