Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-35669 gravatar amend and complete gravatar tests.

  • Loading branch information...
commit 54dd6ee7504b8bc3b3fbfdc14aa2fc4e6c415975 1 parent ba804c9
@stronk7 stronk7 authored
Showing with 33 additions and 9 deletions.
  1. +33 −9 lib/tests/outputcomponents_test.php
View
42 lib/tests/outputcomponents_test.php
@@ -126,6 +126,7 @@ public function test_get_url() {
$this->assertEquals('http://www.example.com/moodle', $CFG->wwwroot);
$this->assertEquals($CFG->wwwroot, $CFG->httpswwwroot);
$this->assertEquals(0, $CFG->enablegravatar);
+ $this->assertEquals('mm', $CFG->gravatardefaulturl);
// create some users
$page = new moodle_page();
@@ -197,21 +198,25 @@ public function test_get_url() {
// test gravatar
set_config('enablegravatar', 1);
- $up2 = new user_picture($user2);
- $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fimage.php%2Fstandard%2Fcore%2F1%2Fu%2Ff2', $up2->get_url($page, $renderer)->out(false));
-
- // uploaded image takes precedence before gravatar
- $up1 = new user_picture($user1);
- $this->assertEquals($CFG->wwwroot.'/pluginfile.php/15/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
-
// deleted user can not have gravatar
$user3->email = 'deleted';
$user3->picture = 0;
$up3 = new user_picture($user3);
$this->assertEquals($CFG->wwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
+ // verify defaults to misteryman (mm)
+ $up2 = new user_picture($user2);
+ $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false));
+
+ // without gravatardefaulturl, verify we pick own file
+ set_config('gravatardefaulturl', '');
+ $up2 = new user_picture($user2);
+ $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
+ // uploaded image takes precedence before gravatar
+ $up1 = new user_picture($user1);
+ $this->assertEquals($CFG->wwwroot.'/pluginfile.php/15/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
- // https versions
+ // https version
$CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
$up1 = new user_picture($user1);
@@ -221,7 +226,26 @@ public function test_get_url() {
$this->assertEquals($CFG->httpswwwroot.'/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
$up2 = new user_picture($user2);
- $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fimage.php%2Fstandard%2Fcore%2F1%2Fu%2Ff2', $up2->get_url($page, $renderer)->out(false));
+ $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
+
+ // now test gravatar with one theme having own images (afterburner)
+ $CFG->httpswwwroot = $CFG->wwwroot;
+ $this->assertTrue(file_exists("$CFG->dirroot/theme/afterburner/config.php"));
+ set_config('theme', 'afterburner');
+ $page = new moodle_page();
+ $page->set_url('/user/profile.php');
+ $page->set_context(context_system::instance());
+ $renderer = $page->get_renderer('core');
+
+ $up2 = new user_picture($user2);
+ $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
+
+ // https version
+ $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
+
+ $up2 = new user_picture($user2);
+ $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
+ // end of gravatar tests
// test themed images
set_config('enablegravatar', 0);
Please sign in to comment.
Something went wrong with that request. Please try again.