| Línea 22... |
Línea 22... |
| 22 |
* @package enrol_lti
|
22 |
* @package enrol_lti
|
| 23 |
* @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
|
23 |
* @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
|
| 24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 25 |
* @coversDefaultClass \enrol_lti\local\ltiadvantage\entity\user
|
25 |
* @coversDefaultClass \enrol_lti\local\ltiadvantage\entity\user
|
| 26 |
*/
|
26 |
*/
|
| 27 |
class user_test extends \advanced_testcase {
|
27 |
final class user_test extends \advanced_testcase {
|
| Línea 28... |
Línea 28... |
| 28 |
|
28 |
|
| 29 |
/**
|
29 |
/**
|
| 30 |
* Test creation of a user instance using the factory method.
|
30 |
* Test creation of a user instance using the factory method.
|
| 31 |
*
|
31 |
*
|
| 32 |
* @dataProvider create_data_provider
|
32 |
* @dataProvider create_data_provider
|
| 33 |
* @param array $args the arguments to the creation method.
|
33 |
* @param array $args the arguments to the creation method.
|
| 34 |
* @param array $expectations various expectations for the test cases.
|
34 |
* @param array $expectations various expectations for the test cases.
|
| 35 |
* @covers ::create
|
35 |
* @covers ::create
|
| 36 |
*/
|
36 |
*/
|
| 37 |
public function test_create(array $args, array $expectations) {
|
37 |
public function test_create(array $args, array $expectations): void {
|
| 38 |
if ($expectations['valid']) {
|
38 |
if ($expectations['valid']) {
|
| 39 |
$user = user::create(...array_values($args));
|
39 |
$user = user::create(...array_values($args));
|
| 40 |
$this->assertInstanceOf(user::class, $user);
|
40 |
$this->assertInstanceOf(user::class, $user);
|
| 41 |
$this->assertEquals($expectations['id'], $user->get_id());
|
41 |
$this->assertEquals($expectations['id'], $user->get_id());
|
| Línea 62... |
Línea 62... |
| 62 |
/**
|
62 |
/**
|
| 63 |
* Data provider for testing the user::create() method.
|
63 |
* Data provider for testing the user::create() method.
|
| 64 |
*
|
64 |
*
|
| 65 |
* @return array the data for testing.
|
65 |
* @return array the data for testing.
|
| 66 |
*/
|
66 |
*/
|
| 67 |
public function create_data_provider(): array {
|
67 |
public static function create_data_provider(): array {
|
| 68 |
global $CFG;
|
68 |
global $CFG;
|
| 69 |
return [
|
69 |
return [
|
| 70 |
'Valid create, only required args provided' => [
|
70 |
'Valid create, only required args provided' => [
|
| 71 |
'args' => [
|
71 |
'args' => [
|
| 72 |
'resourceid' => 22,
|
72 |
'resourceid' => 22,
|
| Línea 240... |
Línea 240... |
| 240 |
* @dataProvider create_from_resource_link_data_provider
|
240 |
* @dataProvider create_from_resource_link_data_provider
|
| 241 |
* @param array $args the arguments to the creation method.
|
241 |
* @param array $args the arguments to the creation method.
|
| 242 |
* @param array $expectations various expectations for the test cases.
|
242 |
* @param array $expectations various expectations for the test cases.
|
| 243 |
* @covers ::create_from_resource_link
|
243 |
* @covers ::create_from_resource_link
|
| 244 |
*/
|
244 |
*/
|
| 245 |
public function test_create_from_resource_link(array $args, array $expectations) {
|
245 |
public function test_create_from_resource_link(array $args, array $expectations): void {
|
| 246 |
if ($expectations['valid']) {
|
246 |
if ($expectations['valid']) {
|
| 247 |
$user = user::create_from_resource_link(...array_values($args));
|
247 |
$user = user::create_from_resource_link(...array_values($args));
|
| 248 |
$this->assertInstanceOf(user::class, $user);
|
248 |
$this->assertInstanceOf(user::class, $user);
|
| 249 |
$this->assertEquals($expectations['id'], $user->get_id());
|
249 |
$this->assertEquals($expectations['id'], $user->get_id());
|
| 250 |
$this->assertEquals($expectations['localid'], $user->get_localid());
|
250 |
$this->assertEquals($expectations['localid'], $user->get_localid());
|
| Línea 270... |
Línea 270... |
| 270 |
/**
|
270 |
/**
|
| 271 |
* Data provider used in testing the user::create_from_resource_link() method.
|
271 |
* Data provider used in testing the user::create_from_resource_link() method.
|
| 272 |
*
|
272 |
*
|
| 273 |
* @return array the data for testing.
|
273 |
* @return array the data for testing.
|
| 274 |
*/
|
274 |
*/
|
| 275 |
public function create_from_resource_link_data_provider(): array {
|
275 |
public static function create_from_resource_link_data_provider(): array {
|
| 276 |
global $CFG;
|
276 |
global $CFG;
|
| 277 |
return [
|
277 |
return [
|
| 278 |
'Valid creation, all args provided explicitly' => [
|
278 |
'Valid creation, all args provided explicitly' => [
|
| 279 |
'args' => [
|
279 |
'args' => [
|
| 280 |
'resourcelinkid' => 11,
|
280 |
'resourcelinkid' => 11,
|
| Línea 485... |
Línea 485... |
| 485 |
* @param string $methodname the name of the setter
|
485 |
* @param string $methodname the name of the setter
|
| 486 |
* @param mixed $arg the argument to the setter
|
486 |
* @param mixed $arg the argument to the setter
|
| 487 |
* @param array $expectations the array of expectations
|
487 |
* @param array $expectations the array of expectations
|
| 488 |
* @covers ::__construct
|
488 |
* @covers ::__construct
|
| 489 |
*/
|
489 |
*/
|
| 490 |
public function test_setters_and_getters(string $methodname, $arg, array $expectations) {
|
490 |
public function test_setters_and_getters(string $methodname, $arg, array $expectations): void {
|
| 491 |
$user = $this->create_test_user();
|
491 |
$user = $this->create_test_user();
|
| 492 |
$setter = 'set_'.$methodname;
|
492 |
$setter = 'set_'.$methodname;
|
| 493 |
$getter = 'get_'.$methodname;
|
493 |
$getter = 'get_'.$methodname;
|
| 494 |
if ($expectations['valid']) {
|
494 |
if ($expectations['valid']) {
|
| 495 |
$user->$setter($arg);
|
495 |
$user->$setter($arg);
|
| Línea 509... |
Línea 509... |
| 509 |
/**
|
509 |
/**
|
| 510 |
* Data provider for testing the user object setters.
|
510 |
* Data provider for testing the user object setters.
|
| 511 |
*
|
511 |
*
|
| 512 |
* @return array the array of test data.
|
512 |
* @return array the array of test data.
|
| 513 |
*/
|
513 |
*/
|
| 514 |
public function setters_getters_data_provider(): array {
|
514 |
public static function setters_getters_data_provider(): array {
|
| 515 |
global $CFG;
|
515 |
global $CFG;
|
| 516 |
return [
|
516 |
return [
|
| 517 |
'Testing set_resourcelinkid with valid id' => [
|
517 |
'Testing set_resourcelinkid with valid id' => [
|
| 518 |
'methodname' => 'resourcelinkid',
|
518 |
'methodname' => 'resourcelinkid',
|
| 519 |
'arg' => 8,
|
519 |
'arg' => 8,
|
| Línea 618... |
Línea 618... |
| 618 |
'valid' => true,
|
618 |
'valid' => true,
|
| 619 |
]
|
619 |
]
|
| 620 |
],
|
620 |
],
|
| 621 |
'Testing set_maildisplay with a valid int: 2' => [
|
621 |
'Testing set_maildisplay with a valid int: 2' => [
|
| 622 |
'methodname' => 'maildisplay',
|
622 |
'methodname' => 'maildisplay',
|
| 623 |
'arg' => '1',
|
623 |
'arg' => '2',
|
| 624 |
'expectations' => [
|
624 |
'expectations' => [
|
| 625 |
'valid' => true,
|
625 |
'valid' => true,
|
| 626 |
]
|
626 |
]
|
| 627 |
],
|
627 |
],
|
| 628 |
'Testing set_maildisplay with invalid int' => [
|
628 |
'Testing set_maildisplay with invalid int: -1' => [
|
| 629 |
'methodname' => 'maildisplay',
|
629 |
'methodname' => 'maildisplay',
|
| 630 |
'arg' => '-1',
|
630 |
'arg' => '-1',
|
| 631 |
'expectations' => [
|
631 |
'expectations' => [
|
| 632 |
'valid' => false,
|
632 |
'valid' => false,
|
| 633 |
'exception' => \coding_exception::class,
|
633 |
'exception' => \coding_exception::class,
|
| 634 |
'exceptionmessage' => "Invalid maildisplay value '-1'. Must be in the range {0..2}."
|
634 |
'exceptionmessage' => "Invalid maildisplay value '-1'. Must be in the range {0..2}."
|
| 635 |
]
|
635 |
]
|
| 636 |
],
|
636 |
],
|
| 637 |
'Testing set_maildisplay with invalid int' => [
|
637 |
'Testing set_maildisplay with invalid int: 3' => [
|
| 638 |
'methodname' => 'maildisplay',
|
638 |
'methodname' => 'maildisplay',
|
| 639 |
'arg' => '3',
|
639 |
'arg' => '3',
|
| 640 |
'expectations' => [
|
640 |
'expectations' => [
|
| 641 |
'valid' => false,
|
641 |
'valid' => false,
|
| 642 |
'exception' => \coding_exception::class,
|
642 |
'exception' => \coding_exception::class,
|
| Línea 657... |
Línea 657... |
| 657 |
'valid' => false,
|
657 |
'valid' => false,
|
| 658 |
'exception' => \coding_exception::class,
|
658 |
'exception' => \coding_exception::class,
|
| 659 |
'exceptionmessage' => 'Invalid lang value. Cannot be an empty string.'
|
659 |
'exceptionmessage' => 'Invalid lang value. Cannot be an empty string.'
|
| 660 |
]
|
660 |
]
|
| 661 |
],
|
661 |
],
|
| 662 |
'Testing set_lang with an empty string' => [
|
662 |
'Testing set_lang with invalid lang code' => [
|
| 663 |
'methodname' => 'lang',
|
663 |
'methodname' => 'lang',
|
| 664 |
'arg' => 'ff',
|
664 |
'arg' => 'ff',
|
| 665 |
'expectations' => [
|
665 |
'expectations' => [
|
| 666 |
'valid' => false,
|
666 |
'valid' => false,
|
| 667 |
'exception' => \coding_exception::class,
|
667 |
'exception' => \coding_exception::class,
|