mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-60342 test: Reset user agent after tests
- Add a test that proves this useragent is not being reset after a test - Reset user agent
This commit is contained in:
parent
9a316f3367
commit
5a97f26be9
@ -278,6 +278,9 @@ class phpunit_util extends testing_util {
|
||||
// Reset the log manager cache.
|
||||
get_log_manager(true);
|
||||
|
||||
// Reset user agent.
|
||||
core_useragent::instance(true, null);
|
||||
|
||||
// verify db writes just in case something goes wrong in reset
|
||||
if (self::$lastdbwrites != $DB->perf_get_writes()) {
|
||||
error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
|
||||
|
@ -662,4 +662,23 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
|
||||
$this->assertSame('en_AU.UTF-8', setlocale(LC_TIME, 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test sets a user agent and makes sure that it is cleared when the test is reset.
|
||||
*/
|
||||
public function test_it_resets_useragent_after_test() {
|
||||
$this->resetAfterTest();
|
||||
$fakeagent = 'New user agent set.';
|
||||
|
||||
// Sanity check: it should not be set when test begins.
|
||||
self::assertFalse(core_useragent::get_user_agent_string(), 'It should not be set at first.');
|
||||
|
||||
// Set a fake useragent and check it was set properly.
|
||||
core_useragent::instance(true, $fakeagent);
|
||||
self::assertSame($fakeagent, core_useragent::get_user_agent_string(), 'It should be the forced agent.');
|
||||
|
||||
// Reset test data and ansure the useragent was cleaned.
|
||||
self::resetAllData(false);
|
||||
self::assertFalse(core_useragent::get_user_agent_string(), 'It should not be set again, data was reset.');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user