/**
  * Note, although the resolve_theme function is copied from the core moodle_page class there do not appear to be
  * any tests for resolve_theme in core code.
  */
 public function test_resolve_theme()
 {
     global $CFG, $COURSE;
     $this->resetAfterTest();
     $COURSE = get_course(SITEID);
     $CFG->enabledevicedetection = false;
     $CFG->theme = 'snap';
     $theme = local::resolve_theme();
     $this->assertEquals('snap', $theme);
     $CFG->allowcoursethemes = true;
     $CFG->allowcategorythemes = true;
     $CFG->allowuserthemes = true;
     $generator = $this->getDataGenerator();
     $cat1 = $generator->create_category((object) ['name' => 'cat1']);
     $cat2 = $generator->create_category((object) ['name' => 'cat2', 'parent' => $cat1->id]);
     $cat3 = $generator->create_category((object) ['name' => 'cat3', 'parent' => $cat2->id, 'theme' => 'clean']);
     $course1 = $generator->create_course((object) ['category' => $cat3->id]);
     $COURSE = $course1;
     $theme = local::resolve_theme();
     $this->assertEquals('clean', $theme);
     $cat4 = $generator->create_category((object) ['name' => 'cat4', 'theme' => 'more']);
     $cat5 = $generator->create_category((object) ['name' => 'cat5', 'parent' => $cat4->id]);
     $cat6 = $generator->create_category((object) ['name' => 'cat6', 'parent' => $cat5->id]);
     $course2 = $generator->create_course((object) ['category' => $cat6->id]);
     $COURSE = $course2;
     $theme = local::resolve_theme();
     $this->assertEquals('more', $theme);
     $course3 = $generator->create_course((object) ['category' => $cat1->id, 'theme' => 'clean']);
     $COURSE = $course3;
     $theme = local::resolve_theme();
     $this->assertEquals('clean', $theme);
     $user1 = $generator->create_user(['theme' => 'more']);
     $COURSE = get_course(SITEID);
     $this->setUser($user1);
     $theme = local::resolve_theme();
     $this->assertEquals('more', $theme);
 }
Example #2
0
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Theme config
 *
 * @package   theme_snap
 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
use theme_snap\local;
global $SESSION, $COURSE, $USER, $PAGE;
$theme = local::resolve_theme();
$themeissnap = $theme === 'snap';
$notajaxscript = !defined('AJAX_SCRIPT') || AJAX_SCRIPT == false;
// The code inside this conditional block is to be executed prior to page rendering when the theme is set to snap and
// when the current request is not an ajax request.
// There doesn't appear to be an official hook we can use for doing things prior to page rendering, so this is a
// workaround.
if ($themeissnap && $notajaxscript) {
    // Setup debugging html.
    // This allows javascript to target debug messages and move them to footer.
    if (!empty($CFG->snapwrapdebug) && !function_exists('xdebug_break')) {
        ini_set('error_prepend_string', '<div class="php-debug">');
        ini_set('error_append_string', '</div>');
    }
    // SL - dec 2015 - Make sure editing sessions are not carried over between courses.
    if (empty($SESSION->theme_snap_last_course) || $SESSION->theme_snap_last_course != $COURSE->id) {