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.
   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 repository_googledocs\local\node;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  require_once($CFG->dirroot . '/repository/googledocs/tests/repository_googledocs_testcase.php');
  23  
  24  /**
  25   * Class containing unit tests for the repository folder node class.
  26   *
  27   * @package    repository_googledocs
  28   * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class folder_node_test extends \repository_googledocs_testcase {
  32  
  33      /**
  34       * Test create_node_array().
  35       *
  36       * @dataProvider create_node_array_provider
  37       * @param \stdClass $gdfolder The Google Drive folder object
  38       * @param string $path The current path
  39       * @param array $expected The expected repository folder node array
  40       */
  41      public function test_create_node_array(\stdClass $gdfolder, string $path, array $expected) {
  42          $foldernode = new folder_node($gdfolder, $path);
  43          $foldernodearray = $foldernode->create_node_array();
  44          // Assert that the returned repository folder node array by create_node_array() is equal to the expected one.
  45          $this->assertEquals($expected, $foldernodearray);
  46      }
  47  
  48      /**
  49       * Data provider for test_create_node_array().
  50       *
  51       * @return array
  52       */
  53      public function create_node_array_provider(): array {
  54  
  55          $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
  56  
  57          return [
  58              'Google Drive folder with modified date.' =>
  59                  [
  60                      $this->create_google_drive_folder_object('d85b21c0f86cb0', 'Folder', '01/01/21 0:30'),
  61                      "{$rootid}|Google+Drive",
  62                      $this->create_folder_content_node_array('d85b21c0f86cb0', 'Folder',
  63                          "{$rootid}|Google+Drive", '1609432200'),
  64                  ],
  65              'Google Drive folder without modified date.' =>
  66                  [
  67                      $this->create_google_drive_folder_object('d85b21c0f86cb0', 'Folder', ''),
  68                      '',
  69                      $this->create_folder_content_node_array('d85b21c0f86cb0', 'Folder', '', ''),
  70                  ],
  71          ];
  72      }
  73  }