Skip to content

Commit

Permalink
Fix: Editor - Not loading with some 3rd party plugins [ED-6882] (elem…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevoss authored Mar 23, 2022
1 parent a9d745c commit 379c62d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
10 changes: 8 additions & 2 deletions core/logger/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ public function rest_error_handler( $error_number, $error_message, $error_file,
return false;
}

$is_an_error = in_array( // It can be notice or warning
$error_number,
[ E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR ],
true
);

$error_data = $error->get_error_data();

// TODO: This part should be modular, temporary hard-coded.
// Notify $e.data.
if ( ! headers_sent() ) {
if ( $is_an_error && ! headers_sent() ) {
header( 'Content-Type: application/json; charset=UTF-8' );

http_response_code( 500 );
Expand All @@ -89,7 +95,7 @@ public function rest_error_handler( $error_number, $error_message, $error_file,
}
}

$this->shutdown( $error_data, true );
$this->shutdown( $error_data, $is_an_error );
}

public function register_error_handler() {
Expand Down
2 changes: 1 addition & 1 deletion data/v2/base/base-route.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function base_callback( $methods, $request, $is_multi = false, $args = []
}

$args = wp_parse_args( $args, [
'is_debug' => defined( 'WP_DEBUG' ),
'is_debug' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
] );

$result = new \WP_Error( 'invalid_methods', 'route not supported.' );
Expand Down
41 changes: 28 additions & 13 deletions tests/phpunit/elementor/core/logger/test-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,46 @@ class Test_Manager extends Elementor_Test_Base {
public function setUp() {
// Mock 'shutdown' method to avoid exit.
$this->mock_manager = $this->getMockBuilder( \Elementor\Core\Logger\Manager::class )
->setMethods( [ 'shutdown' ] )
->getMock();
->setMethods( [ 'shutdown' ] )
->getMock();
}

public function test_rest_error_handler__error_in_elementor_path() {
/**
* @dataProvider rest_error_handler_data_providers_error_numbers
*/
public function test_rest_error_handler__error_in_elementor_path( $error_number, $should_exit ) {
// Assert (Expect).
$this->mock_manager->expects( $this->once() )
->method( 'shutdown' )
->with( [
'type' => 1,
'message' => 0,
'file' => __FILE__,
'line' => 0,
] );
->method( 'shutdown' )
->with( [
'type' => $error_number,
'message' => 0,
'file' => __FILE__,
'line' => 0,
], $should_exit );

// Act.
$this->mock_manager->rest_error_handler( 1, 0, __FILE__, 0 );
$this->mock_manager->rest_error_handler( $error_number, 0, __FILE__, 0 );
}

public function rest_error_handler_data_providers_error_numbers() {
return [
[ E_ERROR, true ],
[ E_USER_ERROR, true ],
[ E_CORE_ERROR, true ],
[ E_NOTICE, false ],
[ E_USER_NOTICE, false ],
[ E_DEPRECATED, false ],
[ E_USER_DEPRECATED, false ],
];
}

public function test_rest_error_handler__error_in_non_elementor_path() {
// Assert (Expect).
$this->mock_manager->expects( $this->never() )
->method( 'shutdown' );
->method( 'shutdown' );

// Act.
$this->mock_manager->rest_error_handler( 1, 0, 'elementor/experts/files/test', 0 );
$this->mock_manager->rest_error_handler( E_ERROR, 0, 'elementor/experts/files/test', 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function test_should_return_css_wrapper_selector() {

public function test_should_register_controls() {
$page_reflection = new \ReflectionClass( 'Elementor\Modules\Library\Documents\Page' );
$method = $page_reflection->getMethod( '_register_controls' );
$method = $page_reflection->getMethod( 'register_controls' );
$method->setAccessible( true );

$method->invokeArgs( self::$page, [] );
Expand Down

0 comments on commit 379c62d

Please sign in to comment.