public function test_launchkey_sso_session_redirects_to_logout_url_and_exits() { $this->user->launchkey_sso_session = "Not Null"; $this->client->logout(); Phake::inOrder(Phake::verify($this->facade)->wp_redirect(static::LOGOUT_URL), Phake::verify($this->facade)->_exit(Phake::anyParameters())); Phake::verifyNoFurtherInteraction($this->facade); }
public function test_username_login_removes_all_authentication_filters_and_then_adds_the_launchkey_filter() { Phake::when($this->facade)->get_user_by(Phake::anyParameters())->thenReturn($this->user); $this->user->launchkey_username = '******'; $this->client->authentication_controller(null, 'username', null); Phake::inOrder(Phake::verify($this->facade)->remove_all_filters('authenticate'), Phake::verify($this->facade)->add_filter('authenticate', array($this->client, 'null_method')), Phake::verify($this->facade)->add_filter('authenticate', array($this->client, 'launchkey_user_authentication'), 30, 2)); }
public function test_gets_the_current_user_and_checks_their_status() { Phake::when($this->wpdb)->prepare(Phake::anyParameters())->thenReturn('PREPARED QUERY'); $this->client->launchkey_still_authenticated_page_load(); Phake::inOrder(Phake::verify($this->wpdb)->prepare(Phake::capture($query), $this->user->ID), Phake::verify($this->wpdb)->get_var('PREPARED QUERY')); $this->assertEquals($query, "SELECT meta_value FROM {$this->wpdb->usermeta} WHERE user_id = %s AND meta_key = 'launchkey_authorized' LIMIT 1"); }
public function test_register_actions_adds_filter_for_plugin_action_links() { Phake::when($this->facade)->plugin_basename(Phake::anyParameters())->thenReturn('BASENAME'); Phake::when($this->facade)->plugin_dir_path(Phake::anyParameters())->thenReturn('DIRPATH'); $this->admin->register_actions(); $reflection_class = new ReflectionClass('LaunchKey_WP_Admin'); Phake::inOrder(Phake::verify($this->facade)->plugin_dir_path(dirname($reflection_class->getFileName())), Phake::verify($this->facade)->plugin_basename('DIRPATH' . 'launchkey.php'), Phake::verify($this->facade)->add_filter('plugin_action_links_BASENAME', array($this->admin, 'add_action_links'))); }
/** * @depends test_gets_the_current_user_and_checks_their_status */ public function test_logs_out_user_and_redirects_if_user_authed_with_launchkey_and_no_longer_authenticated() { Phake::when($this->facade)->is_user_logged_in()->thenReturn(true); Phake::when($this->wpdb)->get_var(Phake::anyParameters())->thenReturn('false'); Phake::when($this->facade)->wp_login_url()->thenReturn('Login URL'); $this->client->launchkey_still_authenticated_page_load(); Phake::verify($this->facade)->update_user_meta($this->user->ID, 'launchkey_sso_session', null); Phake::verify($this->facade)->update_user_meta($this->user->ID, 'launchkey_authorized', null); Phake::verify($this->facade)->wp_logout(); Phake::inOrder(Phake::verify($this->facade)->wp_redirect('Login URL'), Phake::verify($this->facade)->_exit()); }
public function testUpload() { $gateway = \Phake::mock('Modera\\FileUploaderBundle\\Uploading\\UploadGatewayInterface'); $provider = \Phake::mock(ContributorInterface::CLAZZ); \Phake::when($provider)->getItems()->thenReturn(array($gateway)); $request = \Phake::mock('Symfony\\Component\\HttpFoundation\\Request'); \Phake::when($gateway)->isResponsible($request)->thenReturn(true); \Phake::when($gateway)->upload($request)->thenReturn('foobar'); $wu = new WebUploader($provider); $result = $wu->upload($request); \Phake::inOrder(\Phake::verify($provider)->getItems(), \Phake::verify($gateway)->isResponsible($request), \Phake::verify($gateway)->upload($request)); $this->assertEquals('foobar', $result); }
public function testMagicCallMethodChecksForImplicitStubFirst() { $ref = array('foo', array('bar')); Phake::when($this->stubMapper)->getStubByCall(Phake::anyParameters())->thenReturn(null); $this->handler->invoke($this->mock, '__call', $ref, $ref); Phake::inOrder(Phake::verify($this->stubMapper)->getStubByCall('foo', array('bar')), Phake::verify($this->stubMapper)->getStubByCall('__call', array('foo', array('bar')))); }
public function test_when_token_invalid_and_refresh_token_exists_and_refresh_returns_no_access_token__user_is_logged_out_and_redirected() { Phake::when($this->facade)->wp_remote_post('https://oauth.launchkey.com/access_token', $this->anything())->thenReturn(array('body' => '{"refresh_token": "New Refresh Token", "expires_in": 9999}')); $this->client->launchkey_admin_callback(); Phake::verify($this->facade)->wp_login_url(); Phake::inOrder(Phake::verify($this->facade)->wp_logout(), Phake::verify($this->facade)->wp_redirect('LoginURL?loggedout=1')); Phake::verifyNoFurtherInteraction($this->facade); }
public function test_session_index_already_registered_redirects_to_error_url_and_exits() { Phake::when($this->saml_response_service)->is_session_index_registered()->thenReturn(true); $this->client->authenticate(null, null, null); Phake::inOrder(Phake::verify($this->saml_response_service)->is_session_index_registered(), Phake::verify($this->facade)->wp_redirect(static::ERROR_URL), Phake::verify($this->facade)->_exit(Phake::anyParameters())); }
public function test_is_session_index_registered_makes_proper_query_against_database() { $this->service->is_session_index_registered(); Phake::inOrder(Phake::verify($this->wpdb)->prepare("SELECT COUNT(*) FROM prefix_launchkey_sso_sessions WHERE id = %s", "id-b4373c87a6f18f97862c931744fd799f"), Phake::verify($this->wpdb)->get_var(static::PREPARED_STARTEMENT)); }
public function test_unpair_handler_with_verified_nonce_unpairs_current_user_if_user_has_password() { $_GET['launchkey_unpair'] = '1'; $_GET['launchkey_nonce'] = 'nonce value'; Phake::when($this->facade)->wp_verify_nonce(Phake::anyParameters())->thenReturn(true); $this->client->unpair_handler(); Phake::verify($this->facade)->wp_get_current_user(); Phake::inOrder(Phake::verify($this->facade)->wp_verify_nonce('nonce value', LaunchKey_WP_User_Profile::NONCE_KEY), Phake::verify($this->facade)->delete_user_meta(12345, 'launchkey_user')); }
public function test_enqueue_wizard_script_localizes_script_before_enqueueing() { $this->wizard->enqueue_wizard_script(); Phake::inOrder(Phake::verify($this->facade)->wp_enqueue_script(Phake::anyParameters()), Phake::verify($this->facade)->wp_localize_script(Phake::anyParameters())); }
public function test_dies_with_invalid_request_when_timestamp_not_within_restrictions() { Phake::when($this->saml_request_service)->is_timestamp_within_restrictions(Phake::anyParameters())->thenReturn(false); $this->client->authenticate(null, null, null); Phake::inOrder(Phake::verify($this->saml_request_service)->is_timestamp_within_restrictions(static::NOW), Phake::verify($this->facade)->wp_die('Invalid Request', 400)); }
public function test_enqueue_wizard_script_localizes_script_after_enqueueing_scripts() { $this->wizard->enqueue_scripts(); Phake::inOrder(Phake::verify($this->facade, Phake::atLeast(1))->wp_enqueue_script(Phake::anyParameters()), Phake::verify($this->facade)->wp_localize_script(Phake::anyParameters())); }
public function testUnitOfWorkCleanupDelayedUntilOuterUnitOfWorkIsCleanedUp_InnerCommit_OuterRollback() { $outerListener = \Phake::mock(UnitOfWorkListenerInterface::class); $innerListener = \Phake::mock(UnitOfWorkListenerInterface::class); $outer = DefaultUnitOfWork::startAndGet(); $inner = DefaultUnitOfWork::startAndGet(); $inner->registerListener($innerListener); $outer->registerListener($outerListener); $inner->commit(); \Phake::verify($innerListener, \Phake::never())->afterCommit(\Phake::anyParameters()); \Phake::verify($innerListener, \Phake::never())->onCleanup(\Phake::anyParameters()); $outer->rollback(); \Phake::verify($outerListener, \Phake::never())->onPrepareCommit(\Phake::anyParameters()); \Phake::inOrder(\Phake::verify($innerListener)->onPrepareCommit(\Phake::anyParameters()), \Phake::verify($innerListener)->onRollback(\Phake::anyParameters()), \Phake::verify($outerListener)->onRollback(\Phake::anyParameters()), \Phake::verify($innerListener)->onCleanup(\Phake::anyParameters()), \Phake::verify($outerListener)->onCleanup(\Phake::anyParameters())); }
public function testCallOrderInObjectFailsWithPHPUnit() { Phake::setClient(Phake::CLIENT_PHPUNIT); $mock = Phake::mock('PhakeTest_MockedClass'); $mock->foo(); $mock->callInnerFunc(); $mock->fooWithReturnValue(); $this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'); Phake::inOrder(Phake::verify($mock)->foo(), Phake::verify($mock)->fooWithReturnValue(), Phake::verify($mock)->callInnerFunc()); }
public function test_post_get_option_filter_uses_empty_string_for_iv_when_decrypting_private_key_and_secret_key_is_null() { $this->options->post_get_option_filter(array(LaunchKey_WP_Options::OPTION_PRIVATE_KEY => base64_encode('encrypted private key'))); Phake::inOrder(Phake::verify($this->crypt_aes)->setIV(LaunchKey_WP_Options::STATIC_IV), Phake::verify($this->crypt_aes)->decrypt('encrypted private key')); }
/** * @Test * public void testDispatchCommand_UnitOfWorkIsCommittedOnCheckedException() { * UnitOfWorkFactory mockUnitOfWorkFactory = mock(DefaultUnitOfWorkFactory.class); * UnitOfWork mockUnitOfWork = mock(UnitOfWork.class); * when(mockUnitOfWorkFactory.createUnitOfWork()).thenReturn(mockUnitOfWork); * * testSubject.setUnitOfWorkFactory(mockUnitOfWorkFactory); * testSubject.subscribe(String.class.getName(), new CommandHandler<String>() { * @Override * public Object handle(CommandMessage<String> command, UnitOfWork unitOfWork) throws Throwable { * throw new Exception(); * } * }); * testSubject.setRollbackConfiguration(new RollbackOnUncheckedExceptionConfiguration()); * * testSubject.dispatch(GenericCommandMessage.asCommandMessage("Say hi!"), new CommandCallback<Object>() { * @Override * public void onSuccess(Object result) { * fail("Expected exception"); * } * * @Override * public void onFailure(Throwable cause) { * assertThat(cause, is(Exception.class)); * } * }); * * verify(mockUnitOfWork).commit(); * }*/ public function testInterceptorChain_CommandHandledSuccessfully() { $mockInterceptor1 = \Phake::mock(CommandHandlerInterceptorInterface::class); $mockInterceptor2 = \Phake::mock(CommandHandlerInterceptorInterface::class); $commandHandler = \Phake::mock(CommandHandlerInterface::class); \Phake::when($mockInterceptor1)->handle(\Phake::anyParameters())->thenGetReturnByLambda(function (CommandMessageInterface $commandMessage, UnitOfWorkInterface $unitOfWork, InterceptorChainInterface $interceptorChain) use($mockInterceptor2) { return $mockInterceptor2->handle($commandMessage, $unitOfWork, $interceptorChain); }); \Phake::when($mockInterceptor2)->handle(\Phake::anyParameters())->thenGetReturnByLambda(function (CommandMessageInterface $commandMessage, UnitOfWorkInterface $unitOfWork, InterceptorChainInterface $interceptorChain) use($commandHandler) { return $commandHandler->handle($commandMessage, $unitOfWork); }); \Phake::when($commandHandler)->handle(\Phake::anyParameters())->thenReturn(new TestCommand("Hi there!")); $subject = new SimpleCommandBus(new DefaultUnitOfWorkFactory()); $subject->setHandlerInterceptors([$mockInterceptor1, $mockInterceptor2]); $subject->subscribe(TestCommand::class, $commandHandler); $command = GenericCommandMessage::asCommandMessage(new TestCommand("Hi there!")); $callback = new ClosureCommandCallback(function ($result) { $this->assertEquals("Hi there!", $result->getText()); }, function ($exception) { $this->fail("Did not expect exception"); }); $subject->dispatch($command, $callback); \Phake::inOrder(\Phake::verify($mockInterceptor1)->handle(\Phake::anyParameters()), \Phake::verify($mockInterceptor2)->handle(\Phake::anyParameters()), \Phake::verify($commandHandler)->handle(\Phake::anyParameters())); }
public function testEventReceivedDuringReplay() { $concurrentMessage = new GenericEventMessage(new Payload("Concurrent MSG")); $self = $this; \Phake::when($this->mockEventStore)->visitEvents(\Phake::anyParameters())->thenGetReturnByLambda(function ($visitor, $criteria) use($concurrentMessage, $self) { $self->assertTrue($self->testSubject->isInReplayMode()); $self->testSubject->publish(array($concurrentMessage)); foreach ($self->messages as $message) { $visitor->doWithEvent($message); } }); $listener = \Phake::mock(ReplayAwareListenerInterface::class); $this->testSubject->getEventListenerRegistry()->subscribe($listener); $this->testSubject->startReplay(); \Phake::inOrder(\Phake::verify($this->mockMessageHandler)->prepareForReplay(\Phake::anyParameters()), \Phake::verify($listener)->beforeReplay(), \Phake::verify($this->mockEventStore)->visitEvents(\Phake::anyParameters()), \Phake::verify($this->mockMessageHandler)->onIncomingMessages(\Phake::anyParameters()), \Phake::verify($this->delegate, \Phake::times(10))->publish(\Phake::anyParameters()), \Phake::verify($listener)->afterReplay(), \Phake::verify($this->mockMessageHandler)->processBacklog(\Phake::anyParameters())); \Phake::verify($this->delegate, \Phake::never())->publish($concurrentMessage); // \Phake::verify($this->delegate)->subscribe($listener); }