[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpunit/tests/ -> advanced_test.php (source)

   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   * PHPUnit integration tests
  19   *
  20   * @package    core
  21   * @category   phpunit
  22   * @copyright  2012 Petr Skoda {@link http://skodak.org}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  
  29  /**
  30   * Test advanced_testcase extra features.
  31   *
  32   * @package    core
  33   * @category   phpunit
  34   * @copyright  2012 Petr Skoda {@link http://skodak.org}
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class core_phpunit_advanced_testcase extends advanced_testcase {
  38  
  39      public function test_debugging() {
  40          global $CFG;
  41          $this->resetAfterTest();
  42  
  43          debugging('hokus');
  44          $this->assertDebuggingCalled();
  45          debugging('pokus');
  46          $this->assertDebuggingCalled('pokus');
  47          debugging('pokus', DEBUG_MINIMAL);
  48          $this->assertDebuggingCalled('pokus', DEBUG_MINIMAL);
  49          $this->assertDebuggingNotCalled();
  50  
  51          debugging('a');
  52          debugging('b', DEBUG_MINIMAL);
  53          debugging('c', DEBUG_DEVELOPER);
  54          $debuggings = $this->getDebuggingMessages();
  55          $this->assertCount(3, $debuggings);
  56          $this->assertSame('a', $debuggings[0]->message);
  57          $this->assertSame(DEBUG_NORMAL, $debuggings[0]->level);
  58          $this->assertSame('b', $debuggings[1]->message);
  59          $this->assertSame(DEBUG_MINIMAL, $debuggings[1]->level);
  60          $this->assertSame('c', $debuggings[2]->message);
  61          $this->assertSame(DEBUG_DEVELOPER, $debuggings[2]->level);
  62  
  63          $this->resetDebugging();
  64          $this->assertDebuggingNotCalled();
  65          $debuggings = $this->getDebuggingMessages();
  66          $this->assertCount(0, $debuggings);
  67  
  68          set_debugging(DEBUG_NONE);
  69          debugging('hokus');
  70          $this->assertDebuggingNotCalled();
  71          set_debugging(DEBUG_DEVELOPER);
  72      }
  73  
  74      public function test_set_user() {
  75          global $USER, $DB, $SESSION;
  76  
  77          $this->resetAfterTest();
  78  
  79          $this->assertEquals(0, $USER->id);
  80          $this->assertSame($_SESSION['USER'], $USER);
  81          $this->assertSame($GLOBALS['USER'], $USER);
  82  
  83          $user = $DB->get_record('user', array('id'=>2));
  84          $this->assertNotEmpty($user);
  85          $this->setUser($user);
  86          $this->assertEquals(2, $USER->id);
  87          $this->assertEquals(2, $_SESSION['USER']->id);
  88          $this->assertSame($_SESSION['USER'], $USER);
  89          $this->assertSame($GLOBALS['USER'], $USER);
  90  
  91          $USER->id = 3;
  92          $this->assertEquals(3, $USER->id);
  93          $this->assertEquals(3, $_SESSION['USER']->id);
  94          $this->assertSame($_SESSION['USER'], $USER);
  95          $this->assertSame($GLOBALS['USER'], $USER);
  96  
  97          \core\session\manager::set_user($user);
  98          $this->assertEquals(2, $USER->id);
  99          $this->assertEquals(2, $_SESSION['USER']->id);
 100          $this->assertSame($_SESSION['USER'], $USER);
 101          $this->assertSame($GLOBALS['USER'], $USER);
 102  
 103          $USER = $DB->get_record('user', array('id'=>1));
 104          $this->assertNotEmpty($USER);
 105          $this->assertEquals(1, $USER->id);
 106          $this->assertEquals(1, $_SESSION['USER']->id);
 107          $this->assertSame($_SESSION['USER'], $USER);
 108          $this->assertSame($GLOBALS['USER'], $USER);
 109  
 110          $this->setUser(null);
 111          $this->assertEquals(0, $USER->id);
 112          $this->assertSame($_SESSION['USER'], $USER);
 113          $this->assertSame($GLOBALS['USER'], $USER);
 114  
 115          // Ensure session is reset after setUser, as it may contain extra info.
 116          $SESSION->sometestvalue = true;
 117          $this->setUser($user);
 118          $this->assertObjectNotHasAttribute('sometestvalue', $SESSION);
 119      }
 120  
 121      public function test_set_admin_user() {
 122          global $USER;
 123  
 124          $this->resetAfterTest();
 125  
 126          $this->setAdminUser();
 127          $this->assertEquals($USER->id, 2);
 128          $this->assertTrue(is_siteadmin());
 129      }
 130  
 131      public function test_set_guest_user() {
 132          global $USER;
 133  
 134          $this->resetAfterTest();
 135  
 136          $this->setGuestUser();
 137          $this->assertEquals($USER->id, 1);
 138          $this->assertTrue(isguestuser());
 139      }
 140  
 141      public function test_database_reset() {
 142          global $DB;
 143  
 144          $this->resetAfterTest();
 145  
 146          $this->preventResetByRollback();
 147  
 148          $this->assertEquals(1, $DB->count_records('course')); // Only frontpage in new site.
 149  
 150          // This is weird table - id is NOT a sequence here.
 151          $this->assertEquals(0, $DB->count_records('context_temp'));
 152          $DB->import_record('context_temp', array('id'=>5, 'path'=>'/1/2', 'depth'=>2));
 153          $record = $DB->get_record('context_temp', array());
 154          $this->assertEquals(5, $record->id);
 155  
 156          $this->assertEquals(0, $DB->count_records('user_preferences'));
 157          $originaldisplayid = $DB->insert_record('user_preferences', array('userid'=>2, 'name'=> 'phpunittest', 'value'=>'x'));
 158          $this->assertEquals(1, $DB->count_records('user_preferences'));
 159  
 160          $numcourses = $DB->count_records('course');
 161          $course = $this->getDataGenerator()->create_course();
 162          $this->assertEquals($numcourses + 1, $DB->count_records('course'));
 163  
 164          $this->assertEquals(2, $DB->count_records('user'));
 165          $DB->delete_records('user', array('id'=>1));
 166          $this->assertEquals(1, $DB->count_records('user'));
 167  
 168          $this->resetAllData();
 169  
 170          $this->assertEquals(1, $DB->count_records('course')); // Only frontpage in new site.
 171          $this->assertEquals(0, $DB->count_records('context_temp')); // Only frontpage in new site.
 172  
 173          $numcourses = $DB->count_records('course');
 174          $course = $this->getDataGenerator()->create_course();
 175          $this->assertEquals($numcourses + 1, $DB->count_records('course'));
 176  
 177          $displayid = $DB->insert_record('user_preferences', array('userid'=>2, 'name'=> 'phpunittest', 'value'=>'x'));
 178          $this->assertEquals($originaldisplayid, $displayid);
 179  
 180          $this->assertEquals(2, $DB->count_records('user'));
 181          $DB->delete_records('user', array('id'=>2));
 182          $user = $this->getDataGenerator()->create_user();
 183          $this->assertEquals(2, $DB->count_records('user'));
 184          $this->assertGreaterThan(2, $user->id);
 185  
 186          $this->resetAllData();
 187  
 188          $numcourses = $DB->count_records('course');
 189          $course = $this->getDataGenerator()->create_course();
 190          $this->assertEquals($numcourses + 1, $DB->count_records('course'));
 191  
 192          $this->assertEquals(2, $DB->count_records('user'));
 193          $DB->delete_records('user', array('id'=>2));
 194  
 195          $this->resetAllData();
 196  
 197          $numcourses = $DB->count_records('course');
 198          $course = $this->getDataGenerator()->create_course();
 199          $this->assertEquals($numcourses + 1, $DB->count_records('course'));
 200  
 201          $this->assertEquals(2, $DB->count_records('user'));
 202      }
 203  
 204      public function test_change_detection() {
 205          global $DB, $CFG, $COURSE, $SITE, $USER;
 206  
 207          $this->preventResetByRollback();
 208          self::resetAllData(true);
 209  
 210          // Database change.
 211          $this->assertEquals(1, $DB->get_field('user', 'confirmed', array('id'=>2)));
 212          $DB->set_field('user', 'confirmed', 0, array('id'=>2));
 213          try {
 214              self::resetAllData(true);
 215          } catch (Exception $e) {
 216              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 217          }
 218          $this->assertEquals(1, $DB->get_field('user', 'confirmed', array('id'=>2)));
 219  
 220          // Config change.
 221          $CFG->xx = 'yy';
 222          unset($CFG->admin);
 223          $CFG->rolesactive = 0;
 224          try {
 225              self::resetAllData(true);
 226          } catch (Exception $e) {
 227              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 228              $this->assertContains('xx', $e->getMessage());
 229              $this->assertContains('admin', $e->getMessage());
 230              $this->assertContains('rolesactive', $e->getMessage());
 231          }
 232          $this->assertFalse(isset($CFG->xx));
 233          $this->assertTrue(isset($CFG->admin));
 234          $this->assertEquals(1, $CFG->rolesactive);
 235  
 236          // _GET change.
 237          $_GET['__somethingthatwillnotnormallybepresent__'] = 'yy';
 238          self::resetAllData(true);
 239  
 240          $this->assertEquals(array(), $_GET);
 241  
 242          // _POST change.
 243          $_POST['__somethingthatwillnotnormallybepresent2__'] = 'yy';
 244          self::resetAllData(true);
 245          $this->assertEquals(array(), $_POST);
 246  
 247          // _FILES change.
 248          $_FILES['__somethingthatwillnotnormallybepresent3__'] = 'yy';
 249          self::resetAllData(true);
 250          $this->assertEquals(array(), $_FILES);
 251  
 252          // _REQUEST change.
 253          $_REQUEST['__somethingthatwillnotnormallybepresent4__'] = 'yy';
 254          self::resetAllData(true);
 255          $this->assertEquals(array(), $_REQUEST);
 256  
 257          // Silent changes.
 258          $_SERVER['xx'] = 'yy';
 259          self::resetAllData(true);
 260          $this->assertFalse(isset($_SERVER['xx']));
 261  
 262          // COURSE change.
 263          $SITE->id = 10;
 264          $COURSE = new stdClass();
 265          $COURSE->id = 7;
 266          try {
 267              self::resetAllData(true);
 268          } catch (Exception $e) {
 269              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 270              $this->assertEquals(1, $SITE->id);
 271              $this->assertSame($SITE, $COURSE);
 272              $this->assertSame($SITE, $COURSE);
 273          }
 274  
 275          // USER change.
 276          $this->setUser(2);
 277          try {
 278              self::resetAllData(true);
 279          } catch (Exception $e) {
 280              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 281              $this->assertEquals(0, $USER->id);
 282          }
 283      }
 284  
 285      public function test_getDataGenerator() {
 286          $generator = $this->getDataGenerator();
 287          $this->assertInstanceOf('testing_data_generator', $generator);
 288      }
 289  
 290      public function test_database_mock1() {
 291          global $DB;
 292  
 293          try {
 294              $DB->get_record('pokus', array());
 295              $this->fail('Exception expected when accessing non existent table');
 296          } catch (moodle_exception $e) {
 297              $this->assertInstanceOf('dml_exception', $e);
 298          }
 299          $DB = $this->createMock(get_class($DB));
 300          $this->assertNull($DB->get_record('pokus', array()));
 301          // Rest continues after reset.
 302      }
 303  
 304      public function test_database_mock2() {
 305          global $DB;
 306  
 307          // Now the database should be back to normal.
 308          $this->assertFalse($DB->get_record('user', array('id'=>9999)));
 309      }
 310  
 311      public function test_load_dataset() {
 312          global $DB;
 313  
 314          $this->resetAfterTest();
 315  
 316          $this->assertFalse($DB->record_exists('user', array('id'=>5)));
 317          $this->assertFalse($DB->record_exists('user', array('id'=>7)));
 318          $dataset = $this->createXMLDataSet(__DIR__.'/fixtures/sample_dataset.xml');
 319          $this->loadDataSet($dataset);
 320          $this->assertTrue($DB->record_exists('user', array('id'=>5)));
 321          $this->assertTrue($DB->record_exists('user', array('id'=>7)));
 322          $user5 = $DB->get_record('user', array('id'=>5));
 323          $user7 = $DB->get_record('user', array('id'=>7));
 324          $this->assertSame('john.doe', $user5->username);
 325          $this->assertSame('jane.doe', $user7->username);
 326  
 327          $dataset = $this->createCsvDataSet(array('user'=>__DIR__.'/fixtures/sample_dataset.csv'));
 328          $this->loadDataSet($dataset);
 329          $this->assertEquals(8, $DB->get_field('user', 'id', array('username'=>'pepa.novak')));
 330          $this->assertEquals(9, $DB->get_field('user', 'id', array('username'=>'bozka.novakova')));
 331  
 332          $data = array(
 333              'user' => array(
 334                  array('username', 'email'),
 335                  array('top.secret', 'top@example.com'),
 336                  array('low.secret', 'low@example.com'),
 337              ),
 338          );
 339          $dataset = $this->createArrayDataSet($data);
 340          $this->loadDataSet($dataset);
 341          $this->assertTrue($DB->record_exists('user', array('email'=>'top@example.com')));
 342          $this->assertTrue($DB->record_exists('user', array('email'=>'low@example.com')));
 343  
 344          $data = array(
 345              'user' => array(
 346                  array('username'=>'noidea', 'email'=>'noidea@example.com'),
 347                  array('username'=>'onemore', 'email'=>'onemore@example.com'),
 348              ),
 349          );
 350          $dataset = $this->createArrayDataSet($data);
 351          $this->loadDataSet($dataset);
 352          $this->assertTrue($DB->record_exists('user', array('username'=>'noidea')));
 353          $this->assertTrue($DB->record_exists('user', array('username'=>'onemore')));
 354      }
 355  
 356      public function test_assert_time_current() {
 357          $this->assertTimeCurrent(time());
 358  
 359          $this->setCurrentTimeStart();
 360          $this->assertTimeCurrent(time());
 361          sleep(2);
 362          $this->assertTimeCurrent(time());
 363          $this->assertTimeCurrent(time()-1);
 364  
 365          try {
 366              $this->setCurrentTimeStart();
 367              $this->assertTimeCurrent(time()+10);
 368              $this->fail('Failed assert expected');
 369          } catch (Exception $e) {
 370              $this->assertInstanceOf('PHPUnit_Framework_ExpectationFailedException', $e);
 371          }
 372  
 373          try {
 374              $this->setCurrentTimeStart();
 375              $this->assertTimeCurrent(time()-10);
 376              $this->fail('Failed assert expected');
 377          } catch (Exception $e) {
 378              $this->assertInstanceOf('PHPUnit_Framework_ExpectationFailedException', $e);
 379          }
 380      }
 381  
 382      public function test_message_processors_reset() {
 383          global $DB;
 384  
 385          $this->resetAfterTest(true);
 386  
 387          // Get all processors first.
 388          $processors1 = get_message_processors();
 389  
 390          // Add a new message processor and get all processors again.
 391          $processor = new stdClass();
 392          $processor->name = 'test_processor';
 393          $processor->enabled = 1;
 394          $DB->insert_record('message_processors', $processor);
 395  
 396          $processors2 = get_message_processors();
 397  
 398          // Assert that new processor still haven't been added to the list.
 399          $this->assertSame($processors1, $processors2);
 400  
 401          // Reset message processors data.
 402          $processors3 = get_message_processors(false, true);
 403          // Now, list of processors should not be the same any more,
 404          // And we should have one more message processor in the list.
 405          $this->assertNotSame($processors1, $processors3);
 406          $this->assertEquals(count($processors1) + 1, count($processors3));
 407      }
 408  
 409      public function test_message_redirection() {
 410          $this->preventResetByRollback(); // Messaging is not compatible with transactions...
 411          $this->resetAfterTest(false);
 412  
 413          $user1 = $this->getDataGenerator()->create_user();
 414          $user2 = $this->getDataGenerator()->create_user();
 415  
 416          // Any core message will do here.
 417          $message1 = new stdClass();
 418          $message1->component         = 'moodle';
 419          $message1->name              = 'instantmessage';
 420          $message1->userfrom          = $user1;
 421          $message1->userto            = $user2;
 422          $message1->subject           = 'message subject 1';
 423          $message1->fullmessage       = 'message body';
 424          $message1->fullmessageformat = FORMAT_MARKDOWN;
 425          $message1->fullmessagehtml   = '<p>message body</p>';
 426          $message1->smallmessage      = 'small message';
 427          $message1->notification      = 0;
 428  
 429          $message2 = new stdClass();
 430          $message2->component         = 'moodle';
 431          $message2->name              = 'instantmessage';
 432          $message2->userfrom          = $user2;
 433          $message2->userto            = $user1;
 434          $message2->subject           = 'message subject 2';
 435          $message2->fullmessage       = 'message body';
 436          $message2->fullmessageformat = FORMAT_MARKDOWN;
 437          $message2->fullmessagehtml   = '<p>message body</p>';
 438          $message2->smallmessage      = 'small message';
 439          $message2->notification      = 0;
 440  
 441          // There should be debugging message without redirection.
 442          $mailsink = $this->redirectEmails();
 443          $mailsink->close();
 444          message_send($message1);
 445          $this->assertDebuggingCalled(null, null, 'message_send() must print debug message that messaging is disabled in phpunit tests.');
 446  
 447          // Sink should catch messages.
 448          $sink = $this->redirectMessages();
 449          $mid1 = message_send($message1);
 450          $mid2 = message_send($message2);
 451  
 452          $this->assertDebuggingNotCalled('message redirection must prevent debug messages from the message_send()');
 453          $this->assertEquals(2, $sink->count());
 454          $this->assertGreaterThanOrEqual(1, $mid1);
 455          $this->assertGreaterThanOrEqual($mid1, $mid2);
 456  
 457          $messages = $sink->get_messages();
 458          $this->assertInternalType('array', $messages);
 459          $this->assertCount(2, $messages);
 460          $this->assertEquals($mid1, $messages[0]->id);
 461          $this->assertEquals($message1->userto->id, $messages[0]->useridto);
 462          $this->assertEquals($message1->userfrom->id, $messages[0]->useridfrom);
 463          $this->assertEquals($message1->smallmessage, $messages[0]->smallmessage);
 464          $this->assertEquals($mid2, $messages[1]->id);
 465          $this->assertEquals($message2->userto->id, $messages[1]->useridto);
 466          $this->assertEquals($message2->userfrom->id, $messages[1]->useridfrom);
 467          $this->assertEquals($message2->smallmessage, $messages[1]->smallmessage);
 468  
 469          // Test resetting.
 470          $sink->clear();
 471          $messages = $sink->get_messages();
 472          $this->assertInternalType('array', $messages);
 473          $this->assertCount(0, $messages);
 474  
 475          message_send($message1);
 476          $messages = $sink->get_messages();
 477          $this->assertInternalType('array', $messages);
 478          $this->assertCount(1, $messages);
 479  
 480          // Test closing.
 481          $sink->close();
 482          $messages = $sink->get_messages();
 483          $this->assertInternalType('array', $messages);
 484          $this->assertCount(1, $messages, 'Messages in sink are supposed to stay there after close');
 485  
 486          // Test debugging is enabled again.
 487          message_send($message1);
 488          $this->assertDebuggingCalled(null, null, 'message_send() must print debug message that messaging is disabled in phpunit tests.');
 489  
 490          // Test invalid names and components.
 491  
 492          $sink = $this->redirectMessages();
 493  
 494          $message3 = new stdClass();
 495          $message3->component         = 'xxxx_yyyyy';
 496          $message3->name              = 'instantmessage';
 497          $message3->userfrom          = $user2;
 498          $message3->userto            = $user1;
 499          $message3->subject           = 'message subject 2';
 500          $message3->fullmessage       = 'message body';
 501          $message3->fullmessageformat = FORMAT_MARKDOWN;
 502          $message3->fullmessagehtml   = '<p>message body</p>';
 503          $message3->smallmessage      = 'small message';
 504          $message3->notification      = 0;
 505  
 506          try {
 507              message_send($message3);
 508              $this->fail('coding expcetion expected if invalid component specified');
 509          } catch (moodle_exception $e) {
 510              $this->assertInstanceOf('coding_exception', $e);
 511          }
 512  
 513          $message3->component = 'moodle';
 514          $message3->name      = 'yyyyyy';
 515          try {
 516              message_send($message3);
 517              $this->fail('coding expcetion expected if invalid name specified');
 518          } catch (moodle_exception $e) {
 519              $this->assertInstanceOf('coding_exception', $e);
 520          }
 521  
 522          message_send($message1);
 523          $this->assertEquals(1, $sink->count());
 524  
 525          // Test if sink can be carried over to next test.
 526          $this->assertTrue(phpunit_util::is_redirecting_messages());
 527          return $sink;
 528      }
 529  
 530      /**
 531       * @depends test_message_redirection
 532       */
 533      public function test_message_redirection_noreset($sink) {
 534          $this->preventResetByRollback(); // Messaging is not compatible with transactions...
 535          $this->resetAfterTest();
 536  
 537          $this->assertTrue(phpunit_util::is_redirecting_messages());
 538          $this->assertEquals(1, $sink->count());
 539  
 540          $message = new stdClass();
 541          $message->component         = 'moodle';
 542          $message->name              = 'instantmessage';
 543          $message->userfrom          = get_admin();
 544          $message->userto            = get_admin();
 545          $message->subject           = 'message subject 1';
 546          $message->fullmessage       = 'message body';
 547          $message->fullmessageformat = FORMAT_MARKDOWN;
 548          $message->fullmessagehtml   = '<p>message body</p>';
 549          $message->smallmessage      = 'small message';
 550          $message->notification      = 0;
 551  
 552          message_send($message);
 553          $this->assertEquals(2, $sink->count());
 554      }
 555  
 556      /**
 557       * @depends test_message_redirection_noreset
 558       */
 559      public function test_message_redirection_reset() {
 560          $this->assertFalse(phpunit_util::is_redirecting_messages(), 'Test reset must stop message redirection.');
 561      }
 562  
 563      public function test_set_timezone() {
 564          global $CFG;
 565          $this->resetAfterTest();
 566  
 567          $this->assertSame('Australia/Perth', $CFG->timezone);
 568          $this->assertSame('Australia/Perth', date_default_timezone_get());
 569  
 570          $this->setTimezone('Pacific/Auckland', 'Europe/Prague');
 571          $this->assertSame('Pacific/Auckland', $CFG->timezone);
 572          $this->assertSame('Pacific/Auckland', date_default_timezone_get());
 573  
 574          $this->setTimezone('99', 'Europe/Prague');
 575          $this->assertSame('99', $CFG->timezone);
 576          $this->assertSame('Europe/Prague', date_default_timezone_get());
 577  
 578          $this->setTimezone('xxx', 'Europe/Prague');
 579          $this->assertSame('xxx', $CFG->timezone);
 580          $this->assertSame('Europe/Prague', date_default_timezone_get());
 581  
 582          $this->setTimezone();
 583          $this->assertSame('Australia/Perth', $CFG->timezone);
 584          $this->assertSame('Australia/Perth', date_default_timezone_get());
 585  
 586          try {
 587              $this->setTimezone('Pacific/Auckland', '');
 588          } catch (Exception $e) {
 589              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 590          }
 591  
 592          try {
 593              $this->setTimezone('Pacific/Auckland', 'xxxx');
 594          } catch (Exception $e) {
 595              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 596          }
 597  
 598          try {
 599              $this->setTimezone('Pacific/Auckland', null);
 600          } catch (Exception $e) {
 601              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 602          }
 603  
 604      }
 605  
 606      public function test_locale_reset() {
 607          global $CFG;
 608  
 609          $this->resetAfterTest();
 610  
 611          // If this fails self::resetAllData(); must be updated.
 612          $this->assertSame('en_AU.UTF-8', get_string('locale', 'langconfig'));
 613          $this->assertSame('English_Australia.1252', get_string('localewin', 'langconfig'));
 614  
 615          if ($CFG->ostype === 'WINDOWS') {
 616              $this->assertSame('English_Australia.1252', setlocale(LC_TIME, 0));
 617              setlocale(LC_TIME, 'English_USA.1252');
 618          } else {
 619              $this->assertSame('en_AU.UTF-8', setlocale(LC_TIME, 0));
 620              setlocale(LC_TIME, 'en_US.UTF-8');
 621          }
 622  
 623          try {
 624              self::resetAllData(true);
 625          } catch (Exception $e) {
 626              $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
 627          }
 628  
 629          if ($CFG->ostype === 'WINDOWS') {
 630              $this->assertSame('English_Australia.1252', setlocale(LC_TIME, 0));
 631          } else {
 632              $this->assertSame('en_AU.UTF-8', setlocale(LC_TIME, 0));
 633          }
 634  
 635          if ($CFG->ostype === 'WINDOWS') {
 636              $this->assertSame('English_Australia.1252', setlocale(LC_TIME, 0));
 637              setlocale(LC_TIME, 'English_USA.1252');
 638          } else {
 639              $this->assertSame('en_AU.UTF-8', setlocale(LC_TIME, 0));
 640              setlocale(LC_TIME, 'en_US.UTF-8');
 641          }
 642  
 643          self::resetAllData(false);
 644  
 645          if ($CFG->ostype === 'WINDOWS') {
 646              $this->assertSame('English_Australia.1252', setlocale(LC_TIME, 0));
 647          } else {
 648              $this->assertSame('en_AU.UTF-8', setlocale(LC_TIME, 0));
 649          }
 650      }
 651  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1