Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 24... Línea 24...
24
 * @package enrol_lti
24
 * @package enrol_lti
25
 * @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
25
 * @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
26
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @coversDefaultClass \enrol_lti\local\ltiadvantage\entity\migration_claim
27
 * @coversDefaultClass \enrol_lti\local\ltiadvantage\entity\migration_claim
28
 */
28
 */
29
class migration_claim_test extends \advanced_testcase {
29
final class migration_claim_test extends \advanced_testcase {
30
    /**
30
    /**
31
     * Setup run for each test case.
31
     * Setup run for each test case.
32
     */
32
     */
33
    protected function setUp(): void {
33
    protected function setUp(): void {
-
 
34
        parent::setUp();
34
        $this->resetAfterTest();
35
        $this->resetAfterTest();
35
    }
36
    }
Línea 36... Línea 37...
36
 
37
 
37
    /**
38
    /**
Línea 46... Línea 47...
46
 
47
 
47
    /**
48
    /**
48
     * Test instantiation and getters of the migration_claim.
49
     * Test instantiation and getters of the migration_claim.
49
     *
50
     *
50
     * @dataProvider migration_claim_provider
51
     * @dataProvider migration_claim_provider
51
     * @param array $migrationclaimdata the lti1p1 migration claim.
52
     * @param array $lti1p1migrationclaim the lti1p1 migration claim.
52
     * @param string $deploymentid string id of the tool deployment.
53
     * @param string $deploymentid string id of the tool deployment.
53
     * @param string $platform string url of the issuer.
54
     * @param string $platform string url of the issuer.
54
     * @param string $clientid string id of the client.
55
     * @param string $clientid string id of the client.
55
     * @param string $exp expiry time.
56
     * @param string $exp expiry time.
56
     * @param string $nonce nonce.
57
     * @param string $nonce nonce.
57
     * @param legacy_consumer_repository $legacyconsumerrepo legacy consumer repo instance.
58
     * @param bool $stublegacyconsumerrepo Whether the legacy consumer repo is a stub
58
     * @param array $expected array containing expectation data.
59
     * @param array $expected array containing expectation data.
59
     * @covers ::__construct
60
     * @covers ::__construct
60
     */
61
     */
-
 
62
    public function test_migration_claim(
-
 
63
        array $lti1p1migrationclaim,
-
 
64
        string $deploymentid,
-
 
65
        string $platform,
-
 
66
        string $clientid,
-
 
67
        string $exp,
61
    public function test_migration_claim(array $migrationclaimdata, string $deploymentid, string $platform,
68
        string $nonce,
62
            string $clientid, string $exp, string $nonce, legacy_consumer_repository $legacyconsumerrepo,
69
        bool $stublegacyconsumerrepo,
-
 
70
        array $expected,
-
 
71
    ): void {
-
 
72
        if ($stublegacyconsumerrepo) {
-
 
73
            $legacyconsumerrepo = $this->get_stub_legacy_consumer_repo();
-
 
74
        } else {
-
 
75
            $legacyconsumerrepo = new legacy_consumer_repository();
Línea 63... Línea 76...
63
            array $expected): void {
76
        }
64
 
77
 
65
        if (!empty($expected['exception'])) {
78
        if (!empty($expected['exception'])) {
-
 
79
            $this->expectException($expected['exception']);
66
            $this->expectException($expected['exception']);
80
            $this->expectExceptionMessage($expected['exceptionmessage']);
-
 
81
            new migration_claim(
-
 
82
                $lti1p1migrationclaim,
-
 
83
                $deploymentid,
-
 
84
                $platform,
-
 
85
                $clientid,
67
            $this->expectExceptionMessage($expected['exceptionmessage']);
86
                $exp,
-
 
87
                $nonce,
68
            new migration_claim($migrationclaimdata, $deploymentid, $platform, $clientid, $exp, $nonce,
88
                $legacyconsumerrepo,
69
                $legacyconsumerrepo);
89
            );
-
 
90
        } else {
-
 
91
            $migrationclaim = new migration_claim(
-
 
92
                $lti1p1migrationclaim,
-
 
93
                $deploymentid,
-
 
94
                $platform,
-
 
95
                $clientid,
70
        } else {
96
                $exp,
-
 
97
                $nonce,
71
            $migrationclaim = new migration_claim($migrationclaimdata, $deploymentid, $platform, $clientid, $exp,
98
                $legacyconsumerrepo,
72
                $nonce, $legacyconsumerrepo);
99
            );
73
            $this->assertInstanceOf(migration_claim::class, $migrationclaim);
100
            $this->assertInstanceOf(migration_claim::class, $migrationclaim);
-
 
101
            $this->assertEquals($expected['user_id'], $migrationclaim->get_user_id());
74
            $this->assertEquals($expected['user_id'], $migrationclaim->get_user_id());
102
            $this->assertEquals($expected['context_id'], $migrationclaim->get_context_id());
75
            $this->assertEquals($expected['context_id'], $migrationclaim->get_context_id());
103
            $this->assertEquals(
-
 
104
                $expected['tool_consumer_instance_guid'],
76
            $this->assertEquals($expected['tool_consumer_instance_guid'],
105
                $migrationclaim->get_tool_consumer_instance_guid(),
77
                $migrationclaim->get_tool_consumer_instance_guid());
106
            );
78
            $this->assertEquals($expected['resource_link_id'], $migrationclaim->get_resource_link_id());
107
            $this->assertEquals($expected['resource_link_id'], $migrationclaim->get_resource_link_id());
Línea 79... Línea 108...
79
        }
108
        }
80
    }
109
    }
81
 
110
 
82
    /**
111
    /**
83
     * Data provider testing migration_claim instantiation.
112
     * Data provider testing migration_claim instantiation.
84
     *
113
     *
85
     * @return array[] the test case data.
114
     * @return array[] the test case data.
86
     */
115
     */
87
    public function migration_claim_provider(): array {
116
    public static function migration_claim_provider(): array {
88
        // Note: See https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim for details regarding the
117
        // Note: See https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim for details regarding the
89
        // correct generation of oauth_consumer_key_sign signature.
118
        // correct generation of oauth_consumer_key_sign signature.
Línea 96... Línea 125...
96
                'deploymentid' => 'D12345',
125
                'deploymentid' => 'D12345',
97
                'platform' => 'https://lms.example.org/',
126
                'platform' => 'https://lms.example.org/',
98
                'clientid' => 'a1b2c3d4',
127
                'clientid' => 'a1b2c3d4',
99
                'exp' => '1622612930',
128
                'exp' => '1622612930',
100
                'nonce' => 'j45j2j5nnjn24544',
129
                'nonce' => 'j45j2j5nnjn24544',
101
                new legacy_consumer_repository(),
130
                'stublegacyconsumerrepo' => false,
102
                'expected' => [
131
                'expected' => [
103
                    'exception' => \coding_exception::class,
132
                    'exception' => \coding_exception::class,
104
                    'exceptionmessage' => "Missing 'oauth_consumer_key' property in lti1p1 migration claim."
133
                    'exceptionmessage' => "Missing 'oauth_consumer_key' property in lti1p1 migration claim."
105
                ]
134
                ]
106
            ],
135
            ],
Línea 112... Línea 141...
112
                'deploymentid' => 'D12345',
141
                'deploymentid' => 'D12345',
113
                'platform' => 'https://lms.example.org/',
142
                'platform' => 'https://lms.example.org/',
114
                'clientid' => 'a1b2c3d4',
143
                'clientid' => 'a1b2c3d4',
115
                'exp' => '1622612930',
144
                'exp' => '1622612930',
116
                'nonce' => 'j45j2j5nnjn24544',
145
                'nonce' => 'j45j2j5nnjn24544',
117
                new legacy_consumer_repository(),
146
                'stublegacyconsumerrepo' => false,
118
                'expected' => [
147
                'expected' => [
119
                    'exception' => \coding_exception::class,
148
                    'exception' => \coding_exception::class,
120
                    'exceptionmessage' => "Missing 'oauth_consumer_key_sign' property in lti1p1 migration claim."
149
                    'exceptionmessage' => "Missing 'oauth_consumer_key_sign' property in lti1p1 migration claim."
121
                ]
150
                ]
122
            ],
151
            ],
Línea 128... Línea 157...
128
                'deploymentid' => 'D12345',
157
                'deploymentid' => 'D12345',
129
                'platform' => 'https://lms.example.org/',
158
                'platform' => 'https://lms.example.org/',
130
                'clientid' => 'a1b2c3d4',
159
                'clientid' => 'a1b2c3d4',
131
                'exp' => '1622612930',
160
                'exp' => '1622612930',
132
                'nonce' => 'j45j2j5nnjn24544',
161
                'nonce' => 'j45j2j5nnjn24544',
133
                new legacy_consumer_repository(),
162
                'stublegacyconsumerrepo' => false,
134
                'expected' => [
163
                'expected' => [
135
                    'exception' => \coding_exception::class,
164
                    'exception' => \coding_exception::class,
136
                    'exceptionmessage' => "Invalid 'oauth_consumer_key_sign' signature in lti1p1 claim."
165
                    'exceptionmessage' => "Invalid 'oauth_consumer_key_sign' signature in lti1p1 claim."
137
                ]
166
                ]
138
            ],
167
            ],
Línea 150... Línea 179...
150
                'deploymentid' => 'D12345',
179
                'deploymentid' => 'D12345',
151
                'platform' => 'https://lms.example.org/',
180
                'platform' => 'https://lms.example.org/',
152
                'clientid' => 'a1b2c3d4',
181
                'clientid' => 'a1b2c3d4',
153
                'exp' => '1622612930',
182
                'exp' => '1622612930',
154
                'nonce' => 'j45j2j5nnjn24544',
183
                'nonce' => 'j45j2j5nnjn24544',
155
                $this->get_stub_legacy_consumer_repo(),
184
                'stublegacyconsumerrepo' => true,
156
                'expected' => [
185
                'expected' => [
157
                    'user_id' => null,
186
                    'user_id' => null,
158
                    'context_id' => null,
187
                    'context_id' => null,
159
                    'tool_consumer_instance_guid' => null,
188
                    'tool_consumer_instance_guid' => null,
160
                    'resource_link_id' => null
189
                    'resource_link_id' => null
Línea 178... Línea 207...
178
                'deploymentid' => 'D12345',
207
                'deploymentid' => 'D12345',
179
                'platform' => 'https://lms.example.org/',
208
                'platform' => 'https://lms.example.org/',
180
                'clientid' => 'a1b2c3d4',
209
                'clientid' => 'a1b2c3d4',
181
                'exp' => '1622612930',
210
                'exp' => '1622612930',
182
                'nonce' => 'j45j2j5nnjn24544',
211
                'nonce' => 'j45j2j5nnjn24544',
183
                $this->get_stub_legacy_consumer_repo(),
212
                'stublegacyconsumerrepo' => true,
184
                'expected' => [
213
                'expected' => [
185
                    'user_id' => '24',
214
                    'user_id' => '24',
186
                    'context_id' => 'd345b',
215
                    'context_id' => 'd345b',
187
                    'tool_consumer_instance_guid' => '12345-123',
216
                    'tool_consumer_instance_guid' => '12345-123',
188
                    'resource_link_id' => '4b6fa'
217
                    'resource_link_id' => '4b6fa'