|
4 | 4 |
|
5 | 5 | use App\Caliper\Traits\Util; |
6 | 6 | use App\Models\Eppn; |
7 | | -use App\Models\Moodle\User; |
| 7 | +use App\Models\Moodle\{ |
| 8 | + Event, |
| 9 | + User |
| 10 | +}; |
8 | 11 | use Illuminate\Support\Facades\Config; |
9 | 12 | use Tests\TestCase; |
10 | 13 |
|
| 14 | +use function App\Functions\{ |
| 15 | + compile, |
| 16 | + expand, |
| 17 | +}; |
| 18 | + |
11 | 19 | final class EppnTest extends TestCase |
12 | 20 | { |
13 | 21 | public function setUp(): void |
@@ -239,4 +247,55 @@ public function testGetWithoutEppnTableWithLti() |
239 | 247 | $this->assertEquals($anonymizedUsername, hash('sha256', $username)); |
240 | 248 | $this->assertEquals(Eppn::all()->count(), 3); |
241 | 249 | } |
| 250 | + |
| 251 | + public function testGetLtiUsernameWithEppn() |
| 252 | + { |
| 253 | + putenv('DB_EPPN=true'); |
| 254 | + $event = Event::where('userid', 11)->first(); |
| 255 | + $user = User::where('id', 11)->first(); |
| 256 | + $interProd = expand($event); |
| 257 | + $product = compile($interProd); |
| 258 | + $this->assertEquals( |
| 259 | + hash('sha256', $user->alternatename), |
| 260 | + $product->getActor()->getName() |
| 261 | + ); |
| 262 | + $this->assertEquals( |
| 263 | + $user->alternatename, |
| 264 | + $product->getOriginalUsername() |
| 265 | + ); |
| 266 | + } |
| 267 | + |
| 268 | + public function testGetLtiUsernameWhenAlternatenameIsNullWithEppn() |
| 269 | + { |
| 270 | + putenv('DB_EPPN=true'); |
| 271 | + $event = Event::where('userid', 12)->first(); |
| 272 | + $user = User::where('id', 12)->first(); |
| 273 | + $interProd = expand($event); |
| 274 | + $product = compile($interProd); |
| 275 | + $this->assertEquals( |
| 276 | + '', |
| 277 | + $product->getActor()->getName() |
| 278 | + ); |
| 279 | + $this->assertEquals( |
| 280 | + '', |
| 281 | + $product->getOriginalUsername() |
| 282 | + ); |
| 283 | + } |
| 284 | + |
| 285 | + public function testGetLtiUsernameWithoutEppn() |
| 286 | + { |
| 287 | + putenv('DB_EPPN=false'); |
| 288 | + $event = Event::where('userid', 11)->first(); |
| 289 | + $user = User::where('id', 11)->first(); |
| 290 | + $interProd = expand($event); |
| 291 | + $product = compile($interProd); |
| 292 | + $this->assertEquals( |
| 293 | + hash('sha256', $user->username), |
| 294 | + $product->getActor()->getName() |
| 295 | + ); |
| 296 | + $this->assertEquals( |
| 297 | + $user->username, |
| 298 | + $product->getOriginalUsername() |
| 299 | + ); |
| 300 | + } |
242 | 301 | } |
0 commit comments