prophesize(LoggerInterface::class); $emptyLaunch = new LtiLaunchData([LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL => 'notAurl'], []); $emptyLaunch->setLogger($logger->reveal()); $this->assertFalse($emptyLaunch->hasReturnUrl()); $logger->warning("Invalid LTI Return URL 'notAurl'.", Argument::any())->shouldHaveBeenCalled(); } public function testNoReturnUrl() { $logger = $this->prophesize(LoggerInterface::class); $emptyLaunch = new LtiLaunchData([], []); $emptyLaunch->setLogger($logger->reveal()); $this->assertFalse($emptyLaunch->hasReturnUrl()); $logger->warning(Argument::any(), Argument::any())->shouldNotHaveBeenCalled(); } public function testGoodReturnUrl() { $logger = $this->prophesize(LoggerInterface::class); $emptyLaunch = new LtiLaunchData([LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL => 'http://valid.url.com'], []); $emptyLaunch->setLogger($logger->reveal()); $this->assertTrue($emptyLaunch->hasReturnUrl()); $logger->warning(Argument::any(), Argument::any())->shouldNotHaveBeenCalled(); } public function testJsonEncode() { $sampleLaunch = new LtiLaunchData(['a$%' => '!@#$%^&*()_', 'b' => 'c'], ['\\\'s' => '+++']); $unserialized = LtiLaunchData::fromJsonArray(json_decode(json_encode($sampleLaunch), true)); $this->assertEquals($sampleLaunch, $unserialized); $emptyLaunch = new LtiLaunchData([], []); $unserialized = LtiLaunchData::fromJsonArray(json_decode(json_encode($emptyLaunch), true)); $this->assertEquals($emptyLaunch, $unserialized); } /** * @param array $ltiVariables * * @dataProvider dataProviderTestGetBooleanVariableInvalidValueThrowsException * * @throws LtiException * @throws LtiVariableMissingException */ public function testGetBooleanVariableInvalidValueThrowsException(array $ltiVariables) { $customParameters = []; $boolVariableKey = 'boolVariableKey'; $this->expectException(LtiInvalidVariableException::class); $launchData = new LtiLaunchData($ltiVariables, $customParameters); $launchData->getBooleanVariable($boolVariableKey); } /** * @param array $ltiVariables * @param boolean $expectedResult * * @dataProvider dataProviderTestGetBooleanVariable * * @throws LtiException * @throws LtiVariableMissingException */ public function testGetBooleanVariable(array $ltiVariables, $expectedResult) { $customParameters = []; $boolVariableKey = 'boolVariableKey'; $launchData = new LtiLaunchData($ltiVariables, $customParameters); $result = $launchData->getBooleanVariable($boolVariableKey); $this->assertEquals($expectedResult, $result, "Method must return correct boolean value"); } public function dataProviderTestGetBooleanVariableInvalidValueThrowsException() { return [ 'Value integer 1' => [ 'ltiVariables' => [ 'boolVariableKey' => 1, ] ], 'Value integer 0' => [ 'ltiVariables' => [ 'boolVariableKey' => 0, ] ], 'Value string 1' => [ 'ltiVariables' => [ 'boolVariableKey' => '1', ] ], 'Value string 0' => [ 'ltiVariables' => [ 'boolVariableKey' => '0', ] ], 'Value random string' => [ 'ltiVariables' => [ 'boolVariableKey' => 'DUMMY_VALUE', ] ] ]; } public function dataProviderTestGetBooleanVariable() { return [ 'Value capital "TRUE"' => [ 'ltiVariables' => [ 'boolVariableKey' => 'TRUE' ], 'expectedResult' => true, ], 'Value capital "true"' => [ 'ltiVariables' => [ 'boolVariableKey' => 'true' ], 'expectedResult' => true, ], 'Value capital "FALSE"' => [ 'ltiVariables' => [ 'boolVariableKey' => 'FALSE' ], 'expectedResult' => false, ], 'Value lover case "false"' => [ 'ltiVariables' => [ 'boolVariableKey' => 'false' ], 'expectedResult' => false, ] ]; } }