// 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;
}
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) {
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) {
* @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) {
$this->assertSame($debuglevel, $debug->level, $message);
}
- phpunit_util::reset_debugging();
+ $this->resetDebugging();
}
/**
* @param string $message
*/
public function assertDebuggingNotCalled($message = '') {
- $debugging = phpunit_util::get_debugging_messages();
+ $debugging = $this->getDebuggingMessages();
$count = count($debugging);
if ($message === '') {
* @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);
}
/**
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);
}
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());
// _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.
$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);
// 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);
$this->resetAfterTest();
- // If this fails \phpunit_util::reset_all_data() must be updated.
+ // If this fails self::resetAllData(); must be updated.
$this->assertSame('en_AU.UTF-8', get_string('locale', 'langconfig'));
$this->assertSame('English_Australia.1252', get_string('localewin', 'langconfig'));
}
try {
- phpunit_util::reset_all_data(true);
+ self::resetAllData(true);
} catch (Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
}
setlocale(LC_TIME, 'en_US.UTF-8');
}
- phpunit_util::reset_all_data(false);
+ self::resetAllData(false);
if ($CFG->ostype === 'WINDOWS') {
$this->assertSame('English_Australia.1252', setlocale(LC_TIME, 0));
// 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));
// 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,
// 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,
// 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);
// 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);
// 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);
// 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));
// 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);
// 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));
// 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);
// 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));
// 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));
// 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));
// 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));
// 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);
// 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));
// 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));
// 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));
// 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));
// 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();
}
/**