Commit 9194f591 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

Merge branch 'wip-mdl-51266-m28' of https://github.com/rajeshtaneja/moodle into MOODLE_28_STABLE

parents b68783c8 551dce86
......@@ -35,7 +35,7 @@ use core_availability\info_section;
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class info_testcase extends \advanced_testcase {
class info_testcase extends advanced_testcase {
public function setUp() {
// Load the mock condition so that it can be used.
require_once(__DIR__ . '/fixtures/mock_condition.php');
......@@ -87,8 +87,8 @@ class info_testcase extends \advanced_testcase {
// Check invalid one.
$info = new info_module($cm3);
$this->assertFalse($info->is_available($information));
$debugging = phpunit_util::get_debugging_messages();
phpunit_util::reset_debugging();
$debugging = $this->getDebuggingMessages();
$this->resetDebugging();
$this->assertEquals(1, count($debugging));
$this->assertContains('Invalid availability', $debugging[0]->message);
......@@ -141,8 +141,8 @@ class info_testcase extends \advanced_testcase {
// Check invalid one.
$info = new info_section($sections[3]);
$this->assertFalse($info->is_available($information));
$debugging = phpunit_util::get_debugging_messages();
phpunit_util::reset_debugging();
$debugging = $this->getDebuggingMessages();
$this->resetDebugging();
$this->assertEquals(1, count($debugging));
$this->assertContains('Invalid availability', $debugging[0]->message);
......
......@@ -83,14 +83,14 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
// Deal with any debugging messages.
$debugerror = phpunit_util::display_debugging_messages();
phpunit_util::reset_debugging();
$this->resetDebugging();
if ($debugerror) {
trigger_error('Unenxpected debugging() call detected.', E_USER_NOTICE);
}
} catch (Exception $e) {
// cleanup after failed expectation
phpunit_util::reset_all_data();
self::resetAllData();
throw $e;
}
......@@ -104,7 +104,7 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
phpunit_util::reset_all_database_sequences();
phpunit_util::$lastdbwrites = $DB->perf_get_writes(); // no db reset necessary
}
phpunit_util::reset_all_data(null);
self::resetAllData(null);
} else if ($this->resetAfterTest === false) {
if ($this->testdbtransaction) {
......@@ -118,16 +118,16 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
try {
$this->testdbtransaction->allow_commit();
} catch (dml_transaction_exception $e) {
phpunit_util::reset_all_data();
self::resetAllData();
throw new coding_exception('Invalid transaction state detected in test '.$this->getName());
}
}
phpunit_util::reset_all_data(true);
self::resetAllData(true);
}
// make sure test did not forget to close transaction
if ($DB->is_transaction_started()) {
phpunit_util::reset_all_data();
self::resetAllData();
if ($this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED
or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED
or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
......@@ -272,7 +272,7 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
* @param string $message
*/
public function assertDebuggingCalled($debugmessage = null, $debuglevel = null, $message = '') {
$debugging = phpunit_util::get_debugging_messages();
$debugging = $this->getDebuggingMessages();
$count = count($debugging);
if ($count == 0) {
......@@ -297,7 +297,7 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
$this->assertSame($debuglevel, $debug->level, $message);
}
phpunit_util::reset_debugging();
$this->resetDebugging();
}
/**
......@@ -305,7 +305,7 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
* @param string $message
*/
public function assertDebuggingNotCalled($message = '') {
$debugging = phpunit_util::get_debugging_messages();
$debugging = $this->getDebuggingMessages();
$count = count($debugging);
if ($message === '') {
......@@ -446,16 +446,21 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
* @return void
*/
public static function tearDownAfterClass() {
phpunit_util::reset_all_data();
self::resetAllData();
}
/**
* Reset all database tables, restore global state and clear caches and optionally purge dataroot dir.
* @static
*
* @param bool $detectchanges
* true - changes in global state and database are reported as errors
* false - no errors reported
* null - only critical problems are reported as errors
* @return void
*/
public static function resetAllData() {
phpunit_util::reset_all_data();
public static function resetAllData($detectchanges = false) {
phpunit_util::reset_all_data($detectchanges);
}
/**
......
......@@ -176,7 +176,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
* @param string $message
*/
public function assertDebuggingCalled($debugmessage = null, $debuglevel = null, $message = '') {
$debugging = phpunit_util::get_debugging_messages();
$debugging = $this->getDebuggingMessages();
$count = count($debugging);
if ($count == 0) {
......@@ -201,7 +201,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
$this->assertSame($debuglevel, $debug->level, $message);
}
phpunit_util::reset_debugging();
$this->resetDebugging();
}
/**
......@@ -209,7 +209,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
* @param string $message
*/
public function assertDebuggingNotCalled($message = '') {
$debugging = phpunit_util::get_debugging_messages();
$debugging = $this->getDebuggingMessages();
$count = count($debugging);
if ($message === '') {
......
......@@ -104,7 +104,7 @@ class phpunit_util extends testing_util {
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
// Stop any message redirection.
phpunit_util::stop_message_redirection();
self::stop_message_redirection();
// Stop any message redirection.
phpunit_util::stop_phpmailer_redirection();
......@@ -297,7 +297,7 @@ class phpunit_util extends testing_util {
self::$globals['DB'] = $DB;
// refresh data in all tables, clear caches, etc.
phpunit_util::reset_all_data();
self::reset_all_data();
}
/**
......@@ -404,7 +404,7 @@ class phpunit_util extends testing_util {
}
if ($DB->get_tables()) {
list($errorcode, $message) = phpunit_util::testing_ready_problem();
list($errorcode, $message) = self::testing_ready_problem();
if ($errorcode) {
phpunit_bootstrap_error(PHPUNIT_EXITCODE_REINSTALL, 'Database tables already present, Moodle PHPUnit test environment can not be initialised');
} else {
......
......@@ -198,13 +198,13 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
global $DB, $CFG, $COURSE, $SITE, $USER;
$this->preventResetByRollback();
phpunit_util::reset_all_data(true);
self::resetAllData(true);
// Database change.
$this->assertEquals(1, $DB->get_field('user', 'confirmed', array('id'=>2)));
$DB->set_field('user', 'confirmed', 0, array('id'=>2));
try {
phpunit_util::reset_all_data(true);
self::resetAllData(true);
} catch (Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
}
......@@ -215,7 +215,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
unset($CFG->admin);
$CFG->rolesactive = 0;
try {
phpunit_util::reset_all_data(true);
self::resetAllData(true);
} catch (Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
$this->assertContains('xx', $e->getMessage());
......@@ -228,28 +228,28 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
// _GET change.
$_GET['__somethingthatwillnotnormallybepresent__'] = 'yy';
phpunit_util::reset_all_data(true);
self::resetAllData(true);
$this->assertEquals(array(), $_GET);
// _POST change.
$_POST['__somethingthatwillnotnormallybepresent2__'] = 'yy';
phpunit_util::reset_all_data(true);
self::resetAllData(true);
$this->assertEquals(array(), $_POST);
// _FILES change.
$_FILES['__somethingthatwillnotnormallybepresent3__'] = 'yy';
phpunit_util::reset_all_data(true);
self::resetAllData(true);
$this->assertEquals(array(), $_FILES);
// _REQUEST change.
$_REQUEST['__somethingthatwillnotnormallybepresent4__'] = 'yy';
phpunit_util::reset_all_data(true);
self::resetAllData(true);
$this->assertEquals(array(), $_REQUEST);
// Silent changes.
$_SERVER['xx'] = 'yy';
phpunit_util::reset_all_data(true);
self::resetAllData(true);
$this->assertFalse(isset($_SERVER['xx']));
// COURSE change.
......@@ -257,7 +257,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
$COURSE = new stdClass();
$COURSE->id = 7;
try {
phpunit_util::reset_all_data(true);
self::resetAllData(true);
} catch (Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
$this->assertEquals(1, $SITE->id);
......@@ -268,7 +268,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
// USER change.
$this->setUser(2);
try {
phpunit_util::reset_all_data(true);
self::resetAllData(true);
} catch (Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
$this->assertEquals(0, $USER->id);
......
......@@ -52,7 +52,6 @@ class core_messagelib_testcase extends advanced_testcase {
// Check message is not sent.
$sink = $this->redirectEmails();
$this->assertTrue(phpunit_util::is_redirecting_phpmailer());
message_send($message);
$emails = $sink->get_messages();
$this->assertEmpty($emails);
......@@ -63,7 +62,6 @@ class core_messagelib_testcase extends advanced_testcase {
$this->assertTrue($preferences->$disableprovidersetting == 0);
$sink = $this->redirectEmails();
$this->assertTrue(phpunit_util::is_redirecting_phpmailer());
message_send($message);
$emails = $sink->get_messages();
$email = reset($emails);
......@@ -850,7 +848,6 @@ class core_messagelib_testcase extends advanced_testcase {
// Make sure we are redirecting emails.
$sink = $this->redirectEmails();
$this->assertTrue(phpunit_util::is_redirecting_phpmailer());
message_send($message);
// Get the email that we just sent.
......
......@@ -222,8 +222,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Check that the user is unsubscribed from the discussion too.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -267,8 +267,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Subscribing to the forum should create a record in the subscriptions table, but not the forum discussion
// subscriptions table.
forum_subscribe($author->id, $forum->id);
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
$this->assertEquals(1, $DB->count_records('forum_subscriptions', array(
'userid' => $author->id,
'forum' => $forum->id,
......@@ -281,8 +281,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Unsubscribing should remove the record from the forum subscriptions table, and not modify the forum
// discussion subscriptions table.
forum_unsubscribe($author->id, $forum->id);
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
$this->assertEquals(0, $DB->count_records('forum_subscriptions', array(
'userid' => $author->id,
'forum' => $forum->id,
......@@ -441,8 +441,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Post a discussion to the forum.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
......@@ -478,8 +478,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Post a discussion to the forum.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
......@@ -508,8 +508,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Post a discussion to the forum.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
......@@ -525,8 +525,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// But subscribed to the discussion.
$this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -555,8 +555,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Post a discussion to the forum.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
......@@ -569,8 +569,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// But unsubscribed from the discussion.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -601,8 +601,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Post a discussion to the forum.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
......@@ -631,8 +631,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// An attempt to unsubscribe again should result in a falsey return to indicate that no change was made.
$this->assertFalse(\mod_forum\subscriptions::unsubscribe_user_from_discussion($author->id, $discussion));
......@@ -670,13 +670,13 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// And is subscribed to the discussion again.
$this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -701,8 +701,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// But unsubscribed from the discussion.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -749,8 +749,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// But unsubscribed from the discussion.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -808,8 +808,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// Post a discussion to the forum.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
......@@ -828,8 +828,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// But subscribed to the discussion.
$this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -848,8 +848,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// And is unsubscribed from the discussion again.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -868,8 +868,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// And is subscribed to the discussion again.
$this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -888,8 +888,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check the deprecated function too.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// But unsubscribed from the discussion.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
......@@ -920,25 +920,25 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
// Check that the user is currently unsubscribed to the forum.
$this->assertFalse(forum_is_subscribed($author->id, $forum->id));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// It should match the result of when it's called with the forum object.
$this->assertFalse(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// And when the user is subscribed, we should also get the correct result.
\mod_forum\subscriptions::subscribe_user($author->id, $forum);
$this->assertTrue(forum_is_subscribed($author->id, $forum->id));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
// It should match the result of when it's called with the forum object.
$this->assertTrue(forum_is_subscribed($author->id, $forum));
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
phpunit_util::reset_debugging();
$this->assertEquals(1, count($this->getDebuggingMessages()));
$this->resetDebugging();
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment