login = new WP_Auth0_LoginManager( new WP_Auth0_UsersRepo( self::$opts ), self::$opts ); add_filter( 'wp_die_handler', [ 'TestLoginManagerInitAuth0', 'wp_die_handler' ] ); } /** * Runs after each test method. */ public function tearDown() { parent::tearDown(); remove_filter( 'wp_die_handler', [ 'TestLoginManagerInitAuth0', 'wp_die_handler' ] ); } /** * Provide the function to handle wp_die. * * @return array */ public static function wp_die_handler() { return [ 'TestLoginManagerInitAuth0', 'wp_die_die' ]; } /** * Handle wp_die. * * @param string $html - Passed-in HTML to display. * * @throws \Exception - Always. */ public static function wp_die_die( $html ) { throw new Exception( $html ); } /** * Test that Auth0 is not initialized if the plugin is not ready or if the callback URL is not correct. */ public function testThatNothingHappensIfNotReady() { $this->assertFalse( $this->login->init_auth0() ); $_REQUEST['auth0'] = 1; $this->assertFalse( $this->login->init_auth0() ); self::auth0Ready( true ); unset( $_REQUEST['auth0'] ); $this->assertFalse( $this->login->init_auth0() ); $output = ''; try { $_REQUEST['auth0'] = 1; $this->login->init_auth0(); } catch ( Exception $e ) { $output = $e->getMessage(); } $this->assertNotEmpty( $output ); } /** * Test that an error in the URL parameter stops the callback with an error. */ public function testThatErrorInUrlStopsCallback() { self::$opts->set( 'domain', 'test.auth0.com' ); self::$opts->set( 'client_id', '__test_client_id__' ); self::$opts->set( 'client_secret', uniqid() ); $_REQUEST['auth0'] = 1; $_REQUEST['error'] = '__test_error_code__'; $_REQUEST['error_description'] = '__test_error_description__'; $output = ''; try { $this->login->init_auth0(); } catch ( Exception $e ) { $output = $e->getMessage(); } $this->assertContains( 'There was a problem with your log in', $output ); $this->assertContains( '__test_error_description__', $output ); $this->assertContains( 'error code', $output ); $this->assertContains( '__test_error_code__', $output ); $this->assertContains( '