[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/badges/tests/ -> badgeslib_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 badges
  19   *
  20   * @package    core
  21   * @subpackage badges
  22   * @copyright  2013 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  require_once($CFG->libdir . '/badgeslib.php');
  31  require_once($CFG->dirroot . '/badges/lib.php');
  32  
  33  class core_badges_badgeslib_testcase extends advanced_testcase {
  34      protected $badgeid;
  35      protected $course;
  36      protected $user;
  37      protected $module;
  38      protected $coursebadge;
  39      protected $assertion;
  40  
  41      protected function setUp() {
  42          global $DB, $CFG;
  43          $this->resetAfterTest(true);
  44  
  45          $CFG->enablecompletion = true;
  46  
  47          $user = $this->getDataGenerator()->create_user();
  48  
  49          $fordb = new stdClass();
  50          $fordb->id = null;
  51          $fordb->name = "Test badge";
  52          $fordb->description = "Testing badges";
  53          $fordb->timecreated = time();
  54          $fordb->timemodified = time();
  55          $fordb->usercreated = $user->id;
  56          $fordb->usermodified = $user->id;
  57          $fordb->issuername = "Test issuer";
  58          $fordb->issuerurl = "http://issuer-url.domain.co.nz";
  59          $fordb->issuercontact = "issuer@example.com";
  60          $fordb->expiredate = null;
  61          $fordb->expireperiod = null;
  62          $fordb->type = BADGE_TYPE_SITE;
  63          $fordb->courseid = null;
  64          $fordb->messagesubject = "Test message subject";
  65          $fordb->message = "Test message body";
  66          $fordb->attachment = 1;
  67          $fordb->notification = 0;
  68          $fordb->status = BADGE_STATUS_INACTIVE;
  69  
  70          $this->badgeid = $DB->insert_record('badge', $fordb, true);
  71  
  72          // Create a course with activity and auto completion tracking.
  73          $this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => true));
  74          $this->user = $this->getDataGenerator()->create_user();
  75          $studentrole = $DB->get_record('role', array('shortname' => 'student'));
  76          $this->assertNotEmpty($studentrole);
  77  
  78          // Get manual enrolment plugin and enrol user.
  79          require_once($CFG->dirroot.'/enrol/manual/locallib.php');
  80          $manplugin = enrol_get_plugin('manual');
  81          $maninstance = $DB->get_record('enrol', array('courseid' => $this->course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
  82          $manplugin->enrol_user($maninstance, $this->user->id, $studentrole->id);
  83          $this->assertEquals(1, $DB->count_records('user_enrolments'));
  84  
  85          $completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
  86          $this->module = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id), $completionauto);
  87  
  88          // Build badge and criteria.
  89          $fordb->type = BADGE_TYPE_COURSE;
  90          $fordb->courseid = $this->course->id;
  91          $fordb->status = BADGE_STATUS_ACTIVE;
  92  
  93          $this->coursebadge = $DB->insert_record('badge', $fordb, true);
  94          $this->assertion = new stdClass();
  95          $this->assertion->badge = '{"uid":"%s","recipient":{"identity":"%s","type":"email","hashed":true,"salt":"%s"},"badge":"%s","verify":{"type":"hosted","url":"%s"},"issuedOn":"%d","evidence":"%s"}';
  96          $this->assertion->class = '{"name":"%s","description":"%s","image":"%s","criteria":"%s","issuer":"%s"}';
  97          $this->assertion->issuer = '{"name":"%s","url":"%s","email":"%s"}';
  98      }
  99  
 100      public function test_create_badge() {
 101          $badge = new badge($this->badgeid);
 102  
 103          $this->assertInstanceOf('badge', $badge);
 104          $this->assertEquals($this->badgeid, $badge->id);
 105      }
 106  
 107      public function test_clone_badge() {
 108          $badge = new badge($this->badgeid);
 109          $newid = $badge->make_clone();
 110          $cloned_badge = new badge($newid);
 111  
 112          $this->assertEquals($badge->description, $cloned_badge->description);
 113          $this->assertEquals($badge->issuercontact, $cloned_badge->issuercontact);
 114          $this->assertEquals($badge->issuername, $cloned_badge->issuername);
 115          $this->assertEquals($badge->issuercontact, $cloned_badge->issuercontact);
 116          $this->assertEquals($badge->issuerurl, $cloned_badge->issuerurl);
 117          $this->assertEquals($badge->expiredate, $cloned_badge->expiredate);
 118          $this->assertEquals($badge->expireperiod, $cloned_badge->expireperiod);
 119          $this->assertEquals($badge->type, $cloned_badge->type);
 120          $this->assertEquals($badge->courseid, $cloned_badge->courseid);
 121          $this->assertEquals($badge->message, $cloned_badge->message);
 122          $this->assertEquals($badge->messagesubject, $cloned_badge->messagesubject);
 123          $this->assertEquals($badge->attachment, $cloned_badge->attachment);
 124          $this->assertEquals($badge->notification, $cloned_badge->notification);
 125      }
 126  
 127      public function test_badge_status() {
 128          $badge = new badge($this->badgeid);
 129          $old_status = $badge->status;
 130          $badge->set_status(BADGE_STATUS_ACTIVE);
 131          $this->assertAttributeNotEquals($old_status, 'status', $badge);
 132          $this->assertAttributeEquals(BADGE_STATUS_ACTIVE, 'status', $badge);
 133      }
 134  
 135      public function test_delete_badge() {
 136          $badge = new badge($this->badgeid);
 137          $badge->delete();
 138          // We don't actually delete badges. We archive them.
 139          $this->assertAttributeEquals(BADGE_STATUS_ARCHIVED, 'status', $badge);
 140      }
 141  
 142      public function test_create_badge_criteria() {
 143          $badge = new badge($this->badgeid);
 144          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
 145          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL));
 146  
 147          $this->assertCount(1, $badge->get_criteria());
 148  
 149          $criteria_profile = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $badge->id));
 150          $params = array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address');
 151          $criteria_profile->save($params);
 152  
 153          $this->assertCount(2, $badge->get_criteria());
 154      }
 155  
 156      public function test_add_badge_criteria_description() {
 157          $criteriaoverall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid));
 158          $criteriaoverall->save(array(
 159                  'agg' => BADGE_CRITERIA_AGGREGATION_ALL,
 160                  'description' => 'Overall description',
 161                  'descriptionformat' => FORMAT_HTML
 162          ));
 163  
 164          $criteriaprofile = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $this->badgeid));
 165          $params = array(
 166                  'agg' => BADGE_CRITERIA_AGGREGATION_ALL,
 167                  'field_address' => 'address',
 168                  'description' => 'Description',
 169                  'descriptionformat' => FORMAT_HTML
 170          );
 171          $criteriaprofile->save($params);
 172  
 173          $badge = new badge($this->badgeid);
 174          $this->assertEquals('Overall description', $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->description);
 175          $this->assertEquals('Description', $badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->description);
 176      }
 177  
 178      public function test_delete_badge_criteria() {
 179          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid));
 180          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL));
 181          $badge = new badge($this->badgeid);
 182  
 183          $this->assertInstanceOf('award_criteria_overall', $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
 184  
 185          $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->delete();
 186          $this->assertEmpty($badge->get_criteria());
 187      }
 188  
 189      public function test_badge_awards() {
 190          $this->preventResetByRollback(); // Messaging is not compatible with transactions.
 191          $badge = new badge($this->badgeid);
 192          $user1 = $this->getDataGenerator()->create_user();
 193  
 194          $badge->issue($user1->id, true);
 195          $this->assertTrue($badge->is_issued($user1->id));
 196  
 197          $user2 = $this->getDataGenerator()->create_user();
 198          $badge->issue($user2->id, true);
 199          $this->assertTrue($badge->is_issued($user2->id));
 200  
 201          $this->assertCount(2, $badge->get_awards());
 202      }
 203  
 204      /**
 205       * Test the {@link badges_get_user_badges()} function in lib/badgeslib.php
 206       */
 207      public function test_badges_get_user_badges() {
 208          global $DB;
 209  
 210          // Messaging is not compatible with transactions.
 211          $this->preventResetByRollback();
 212  
 213          $badges = array();
 214          $user1 = $this->getDataGenerator()->create_user();
 215          $user2 = $this->getDataGenerator()->create_user();
 216  
 217          // Record the current time, we need to be precise about a couple of things.
 218          $now = time();
 219          // Create 11 badges with which to test.
 220          for ($i = 1; $i <= 11; $i++) {
 221              // Mock up a badge.
 222              $badge = new stdClass();
 223              $badge->id = null;
 224              $badge->name = "Test badge $i";
 225              $badge->description = "Testing badges $i";
 226              $badge->timecreated = $now - 12;
 227              $badge->timemodified = $now - 12;
 228              $badge->usercreated = $user1->id;
 229              $badge->usermodified = $user1->id;
 230              $badge->issuername = "Test issuer";
 231              $badge->issuerurl = "http://issuer-url.domain.co.nz";
 232              $badge->issuercontact = "issuer@example.com";
 233              $badge->expiredate = null;
 234              $badge->expireperiod = null;
 235              $badge->type = BADGE_TYPE_SITE;
 236              $badge->courseid = null;
 237              $badge->messagesubject = "Test message subject for badge $i";
 238              $badge->message = "Test message body for badge $i";
 239              $badge->attachment = 1;
 240              $badge->notification = 0;
 241              $badge->status = BADGE_STATUS_INACTIVE;
 242  
 243              $badgeid = $DB->insert_record('badge', $badge, true);
 244              $badges[$badgeid] = new badge($badgeid);
 245              $badges[$badgeid]->issue($user2->id, true);
 246              // Check it all actually worked.
 247              $this->assertCount(1, $badges[$badgeid]->get_awards());
 248  
 249              // Hack the database to adjust the time each badge was issued.
 250              // The alternative to this is sleep which is a no-no in unit tests.
 251              $DB->set_field('badge_issued', 'dateissued', $now - 11 + $i, array('userid' => $user2->id, 'badgeid' => $badgeid));
 252          }
 253  
 254          // Make sure the first user has no badges.
 255          $result = badges_get_user_badges($user1->id);
 256          $this->assertInternalType('array', $result);
 257          $this->assertCount(0, $result);
 258  
 259          // Check that the second user has the expected 11 badges.
 260          $result = badges_get_user_badges($user2->id);
 261          $this->assertCount(11, $result);
 262  
 263          // Test pagination.
 264          // Ordering is by time issued desc, so things will come out with the last awarded badge first.
 265          $result = badges_get_user_badges($user2->id, 0, 0, 4);
 266          $this->assertCount(4, $result);
 267          $lastbadgeissued = reset($result);
 268          $this->assertSame('Test badge 11', $lastbadgeissued->name);
 269          // Page 2. Expecting 4 results again.
 270          $result = badges_get_user_badges($user2->id, 0, 1, 4);
 271          $this->assertCount(4, $result);
 272          $lastbadgeissued = reset($result);
 273          $this->assertSame('Test badge 7', $lastbadgeissued->name);
 274          // Page 3. Expecting just three results here.
 275          $result = badges_get_user_badges($user2->id, 0, 2, 4);
 276          $this->assertCount(3, $result);
 277          $lastbadgeissued = reset($result);
 278          $this->assertSame('Test badge 3', $lastbadgeissued->name);
 279          // Page 4.... there is no page 4.
 280          $result = badges_get_user_badges($user2->id, 0, 3, 4);
 281          $this->assertCount(0, $result);
 282  
 283          // Test search.
 284          $result = badges_get_user_badges($user2->id, 0, 0, 0, 'badge 1');
 285          $this->assertCount(3, $result);
 286          $lastbadgeissued = reset($result);
 287          $this->assertSame('Test badge 11', $lastbadgeissued->name);
 288          // The term Totara doesn't appear anywhere in the badges.
 289          $result = badges_get_user_badges($user2->id, 0, 0, 0, 'Totara');
 290          $this->assertCount(0, $result);
 291      }
 292  
 293      public function data_for_message_from_template() {
 294          return array(
 295              array(
 296                  'This is a message with no variables',
 297                  array(), // no params
 298                  'This is a message with no variables'
 299              ),
 300              array(
 301                  'This is a message with %amissing% variables',
 302                  array(), // no params
 303                  'This is a message with %amissing% variables'
 304              ),
 305              array(
 306                  'This is a message with %one% variable',
 307                  array('one' => 'a single'),
 308                  'This is a message with a single variable'
 309              ),
 310              array(
 311                  'This is a message with %one% %two% %three% variables',
 312                  array('one' => 'more', 'two' => 'than', 'three' => 'one'),
 313                  'This is a message with more than one variables'
 314              ),
 315              array(
 316                  'This is a message with %three% %two% %one%',
 317                  array('one' => 'variables', 'two' => 'ordered', 'three' => 'randomly'),
 318                  'This is a message with randomly ordered variables'
 319              ),
 320              array(
 321                  'This is a message with %repeated% %one% %repeated% of variables',
 322                  array('one' => 'and', 'repeated' => 'lots'),
 323                  'This is a message with lots and lots of variables'
 324              ),
 325          );
 326      }
 327  
 328      /**
 329       * @dataProvider data_for_message_from_template
 330       */
 331      public function test_badge_message_from_template($message, $params, $result) {
 332          $this->assertEquals(badge_message_from_template($message, $params), $result);
 333      }
 334  
 335      /**
 336       * Test badges observer when course module completion event id fired.
 337       */
 338      public function test_badges_observer_course_module_criteria_review() {
 339          $this->preventResetByRollback(); // Messaging is not compatible with transactions.
 340          $badge = new badge($this->coursebadge);
 341          $this->assertFalse($badge->is_issued($this->user->id));
 342  
 343          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
 344          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
 345          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_ACTIVITY, 'badgeid' => $badge->id));
 346          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'module_'.$this->module->cmid => $this->module->cmid));
 347  
 348          // Assert the badge will not be issued to the user as is.
 349          $badge = new badge($this->coursebadge);
 350          $badge->review_all_criteria();
 351          $this->assertFalse($badge->is_issued($this->user->id));
 352  
 353          // Set completion for forum activity.
 354          $c = new completion_info($this->course);
 355          $activities = $c->get_activities();
 356          $this->assertEquals(1, count($activities));
 357          $this->assertTrue(isset($activities[$this->module->cmid]));
 358          $this->assertEquals($activities[$this->module->cmid]->name, $this->module->name);
 359  
 360          $current = $c->get_data($activities[$this->module->cmid], false, $this->user->id);
 361          $current->completionstate = COMPLETION_COMPLETE;
 362          $current->timemodified = time();
 363          $sink = $this->redirectEmails();
 364          $c->internal_set_data($activities[$this->module->cmid], $current);
 365          $this->assertCount(1, $sink->get_messages());
 366          $sink->close();
 367  
 368          // Check if badge is awarded.
 369          $this->assertDebuggingCalled('Error baking badge image!');
 370          $this->assertTrue($badge->is_issued($this->user->id));
 371      }
 372  
 373      /**
 374       * Test badges observer when course_completed event is fired.
 375       */
 376      public function test_badges_observer_course_criteria_review() {
 377          $this->preventResetByRollback(); // Messaging is not compatible with transactions.
 378          $badge = new badge($this->coursebadge);
 379          $this->assertFalse($badge->is_issued($this->user->id));
 380  
 381          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
 382          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
 383          $criteria_overall1 = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_COURSE, 'badgeid' => $badge->id));
 384          $criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'course_'.$this->course->id => $this->course->id));
 385  
 386          $ccompletion = new completion_completion(array('course' => $this->course->id, 'userid' => $this->user->id));
 387  
 388          // Assert the badge will not be issued to the user as is.
 389          $badge = new badge($this->coursebadge);
 390          $badge->review_all_criteria();
 391          $this->assertFalse($badge->is_issued($this->user->id));
 392  
 393          // Mark course as complete.
 394          $sink = $this->redirectEmails();
 395          $ccompletion->mark_complete();
 396          $this->assertCount(1, $sink->get_messages());
 397          $sink->close();
 398  
 399          // Check if badge is awarded.
 400          $this->assertDebuggingCalled('Error baking badge image!');
 401          $this->assertTrue($badge->is_issued($this->user->id));
 402      }
 403  
 404      /**
 405       * Test badges observer when user_updated event is fired.
 406       */
 407      public function test_badges_observer_profile_criteria_review() {
 408          global $CFG, $DB;
 409          require_once($CFG->dirroot.'/user/profile/lib.php');
 410  
 411          // Add a custom field of textarea type.
 412          $customprofileid = $DB->insert_record('user_info_field', array(
 413              'shortname' => 'newfield', 'name' => 'Description of new field', 'categoryid' => 1,
 414              'datatype' => 'textarea'));
 415  
 416          $this->preventResetByRollback(); // Messaging is not compatible with transactions.
 417          $badge = new badge($this->coursebadge);
 418  
 419          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
 420          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
 421          $criteria_overall1 = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $badge->id));
 422          $criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address', 'field_aim' => 'aim',
 423              'field_' . $customprofileid => $customprofileid));
 424  
 425          // Assert the badge will not be issued to the user as is.
 426          $badge = new badge($this->coursebadge);
 427          $badge->review_all_criteria();
 428          $this->assertFalse($badge->is_issued($this->user->id));
 429  
 430          // Set the required fields and make sure the badge got issued.
 431          $this->user->address = 'Test address';
 432          $this->user->aim = '999999999';
 433          $sink = $this->redirectEmails();
 434          profile_save_data((object)array('id' => $this->user->id, 'profile_field_newfield' => 'X'));
 435          user_update_user($this->user, false);
 436          $this->assertCount(1, $sink->get_messages());
 437          $sink->close();
 438          // Check if badge is awarded.
 439          $this->assertDebuggingCalled('Error baking badge image!');
 440          $this->assertTrue($badge->is_issued($this->user->id));
 441      }
 442  
 443      /**
 444       * Test badges assertion generated when a badge is issued.
 445       */
 446      public function test_badges_assertion() {
 447          $this->preventResetByRollback(); // Messaging is not compatible with transactions.
 448          $badge = new badge($this->coursebadge);
 449          $this->assertFalse($badge->is_issued($this->user->id));
 450  
 451          $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
 452          $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
 453          $criteria_overall1 = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $badge->id));
 454          $criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address'));
 455  
 456          $this->user->address = 'Test address';
 457          $sink = $this->redirectEmails();
 458          user_update_user($this->user, false);
 459          $this->assertCount(1, $sink->get_messages());
 460          $sink->close();
 461          // Check if badge is awarded.
 462          $this->assertDebuggingCalled('Error baking badge image!');
 463          $awards = $badge->get_awards();
 464          $this->assertCount(1, $awards);
 465  
 466          // Get assertion.
 467          $award = reset($awards);
 468          $assertion = new core_badges_assertion($award->uniquehash);
 469          $testassertion = $this->assertion;
 470  
 471          // Make sure JSON strings have the same structure.
 472          $this->assertStringMatchesFormat($testassertion->badge, json_encode($assertion->get_badge_assertion()));
 473          $this->assertStringMatchesFormat($testassertion->class, json_encode($assertion->get_badge_class()));
 474          $this->assertStringMatchesFormat($testassertion->issuer, json_encode($assertion->get_issuer()));
 475      }
 476  
 477      /**
 478       * Tests the core_badges_myprofile_navigation() function.
 479       */
 480      public function test_core_badges_myprofile_navigation() {
 481          // Set up the test.
 482          $tree = new \core_user\output\myprofile\tree();
 483          $this->setAdminUser();
 484          $badge = new badge($this->badgeid);
 485          $badge->issue($this->user->id, true);
 486          $iscurrentuser = true;
 487          $course = null;
 488  
 489          // Enable badges.
 490          set_config('enablebadges', true);
 491  
 492          // Check the node tree is correct.
 493          core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $course);
 494          $reflector = new ReflectionObject($tree);
 495          $nodes = $reflector->getProperty('nodes');
 496          $nodes->setAccessible(true);
 497          $this->assertArrayHasKey('localbadges', $nodes->getValue($tree));
 498      }
 499  
 500      /**
 501       * Tests the core_badges_myprofile_navigation() function with badges disabled..
 502       */
 503      public function test_core_badges_myprofile_navigation_badges_disabled() {
 504          // Set up the test.
 505          $tree = new \core_user\output\myprofile\tree();
 506          $this->setAdminUser();
 507          $badge = new badge($this->badgeid);
 508          $badge->issue($this->user->id, true);
 509          $iscurrentuser = false;
 510          $course = null;
 511  
 512          // Disable badges.
 513          set_config('enablebadges', false);
 514  
 515          // Check the node tree is correct.
 516          core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $course);
 517          $reflector = new ReflectionObject($tree);
 518          $nodes = $reflector->getProperty('nodes');
 519          $nodes->setAccessible(true);
 520          $this->assertArrayNotHasKey('localbadges', $nodes->getValue($tree));
 521      }
 522  
 523      /**
 524       * Tests the core_badges_myprofile_navigation() function with a course badge.
 525       */
 526      public function test_core_badges_myprofile_navigation_with_course_badge() {
 527          // Set up the test.
 528          $tree = new \core_user\output\myprofile\tree();
 529          $this->setAdminUser();
 530          $badge = new badge($this->coursebadge);
 531          $badge->issue($this->user->id, true);
 532          $iscurrentuser = false;
 533  
 534          // Check the node tree is correct.
 535          core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $this->course);
 536          $reflector = new ReflectionObject($tree);
 537          $nodes = $reflector->getProperty('nodes');
 538          $nodes->setAccessible(true);
 539          $this->assertArrayHasKey('localbadges', $nodes->getValue($tree));
 540      }
 541  }


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