Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

   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  namespace core\testing;
  18  
  19  /**
  20   * Testing util tests.
  21   *
  22   * @package    core
  23   * @category   phpunit
  24   * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
  25   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  class util_test extends \advanced_testcase {
  28      /**
  29       * Note: This test is required for the other two parts because the first time
  30       * a table is written to it may not have had the initial value reset.
  31       *
  32       * @coversNothing
  33       */
  34      public function test_increment_reset_part_one(): void {
  35          global $DB;
  36  
  37          switch ($DB->get_dbfamily()) {
  38              case 'mssql':
  39                  $this->markTestSkipped('MSSQL does not support sequences');
  40                  return;
  41              case 'mysql':
  42                  $version = $DB->get_server_info();
  43                  if (version_compare($version['version'], '5.7.4', '<')) {
  44                      return;
  45                  }
  46          }
  47  
  48          $this->resetAfterTest();
  49          $DB->insert_record('config_plugins', [
  50              'plugin' => 'example',
  51              'name' => 'test_increment',
  52              'value' => 0,
  53          ]);
  54      }
  55  
  56      /**
  57       * @coversNothing
  58       * @depends test_increment_reset_part_one
  59       */
  60      public function test_increment_reset_part_two(): int {
  61          global $DB;
  62  
  63          $this->resetAfterTest();
  64          return $DB->insert_record('config_plugins', [
  65              'plugin' => 'example',
  66              'name' => 'test_increment',
  67              'value' => 0,
  68          ]);
  69      }
  70  
  71      /**
  72       * @depends test_increment_reset_part_two
  73       */
  74      public function test_increment_reset_part_three(int $previousid): void {
  75          global $DB;
  76  
  77          $this->resetAfterTest();
  78          $id = $DB->insert_record('config_plugins', [
  79              'plugin' => 'example',
  80              'name' => 'test_increment',
  81              'value' => 0,
  82          ]);
  83          $this->assertEquals($previousid, $id);
  84      }
  85  }