[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/tests/ -> mustache_template_finder_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   * Unit tests for lib/classes/output/mustache_template_finder.php
  19   *
  20   * @package   core
  21   * @category  phpunit
  22   * @copyright 2015 Damyon Wiese
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use core\output\mustache_template_finder;
  29  
  30  /**
  31   * Unit tests for the Mustache template finder class (contains logic about
  32   * resolving mustache template locations.
  33   */
  34  class core_output_mustache_template_finder_testcase extends advanced_testcase {
  35  
  36      public function test_get_template_directories_for_component() {
  37          global $CFG;
  38  
  39          // Test a plugin.
  40          $dirs = mustache_template_finder::get_template_directories_for_component('mod_assign', 'clean');
  41  
  42          $correct = array(
  43              'theme/clean/templates/mod_assign/',
  44              'theme/bootstrapbase/templates/mod_assign/',
  45              'mod/assign/templates/'
  46          );
  47          foreach ($dirs as $index => $dir) {
  48              $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
  49          }
  50          // Test a subsystem.
  51          $dirs = mustache_template_finder::get_template_directories_for_component('core_user', 'clean');
  52  
  53          $correct = array(
  54              'theme/clean/templates/core_user/',
  55              'theme/bootstrapbase/templates/core_user/',
  56              'user/templates/'
  57          );
  58          foreach ($dirs as $index => $dir) {
  59              $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
  60          }
  61          // Test core.
  62          $dirs = mustache_template_finder::get_template_directories_for_component('core', 'clean');
  63  
  64          $correct = array(
  65              'theme/clean/templates/core/',
  66              'theme/bootstrapbase/templates/core/',
  67              'lib/templates/'
  68          );
  69          foreach ($dirs as $index => $dir) {
  70              $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
  71          }
  72          return;
  73      }
  74  
  75      /**
  76       * @expectedException coding_exception
  77       */
  78      public function test_invalid_get_template_directories_for_component() {
  79          // Test something invalid.
  80          $dirs = mustache_template_finder::get_template_directories_for_component('octopus', 'clean');
  81      }
  82  
  83      public function test_get_template_filepath() {
  84          global $CFG;
  85  
  86          $filename = mustache_template_finder::get_template_filepath('core/pix_icon', 'clean');
  87          $correct = $CFG->dirroot . '/lib/templates/pix_icon.mustache';
  88          $this->assertSame($correct, $filename);
  89      }
  90  
  91      /**
  92       * @expectedException moodle_exception
  93       */
  94      public function test_invalid_get_template_filepath() {
  95          // Test something invalid.
  96          $dirs = mustache_template_finder::get_template_filepath('core/octopus', 'clean');
  97      }
  98  }


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