Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

   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;
  18  
  19  /**
  20   * Test util extra features.
  21   *
  22   * @package    core
  23   * @category   test
  24   * @copyright  2015 Andrew Nicols <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       * @dataProvider set_table_modified_by_sql_provider
  30       */
  31      public function test_set_table_modified_by_sql($sql, $expectations) {
  32          \phpunit_util::reset_updated_table_list();
  33          \phpunit_util::set_table_modified_by_sql($sql);
  34          foreach ($expectations as $table => $present) {
  35              $this->assertEquals($present, !empty(\phpunit_util::$tableupdated[$table]));
  36          }
  37      }
  38  
  39      public function set_table_modified_by_sql_provider() {
  40          global $DB;
  41          $prefix = $DB->get_prefix();
  42  
  43          return array(
  44              'Basic update' => array(
  45                  'sql'           => "UPDATE {$prefix}user SET username = username || '_test'",
  46                  'expectations'  => array(
  47                      'user'      => true,
  48                      'course'    => false,
  49                  ),
  50              ),
  51              'Basic update with a fieldname sharing the same prefix' => array(
  52                  'sql'           => "UPDATE {$prefix}user SET {$prefix}username = username || '_test'",
  53                  'expectations'  => array(
  54                      'user'      => true,
  55                      'course'    => false,
  56                  ),
  57              ),
  58              'Basic update with a table which contains the prefix' => array(
  59                  'sql'           => "UPDATE {$prefix}user{$prefix} SET username = username || '_test'",
  60                  'expectations'  => array(
  61                      "user{$prefix}" => true,
  62                      'course'        => false,
  63                  ),
  64              ),
  65              'Update table with a numeric name' => array(
  66                  'sql'           => "UPDATE {$prefix}example42 SET username = username || '_test'",
  67                  'expectations'  => array(
  68                      'example42' => true,
  69                      'user'      => false,
  70                      'course'    => false,
  71                  ),
  72              ),
  73              'Drop basic table' => array(
  74                  'sql'           => "DROP TABLE {$prefix}user",
  75                  'expectations'  => array(
  76                      'user'      => true,
  77                      'course'    => false,
  78                  ),
  79              ),
  80              'Drop table with a numeric name' => array(
  81                  'sql'           => "DROP TABLE {$prefix}example42",
  82                  'expectations'  => array(
  83                      'example42' => true,
  84                      'user'      => false,
  85                      'course'    => false,
  86                  ),
  87              ),
  88              'Insert in table' => array(
  89                  'sql'           => "INSERT INTO {$prefix}user (username,password) VALUES ('moodle', 'test')",
  90                  'expectations'  => array(
  91                      'user'      => true,
  92                      'course'    => false,
  93                  ),
  94              ),
  95          );
  96      }
  97  }