Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/phpunit/tests/general/wpEnqueueCodeEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
Comment thread
shail-mehta marked this conversation as resolved.
Resolved

/**
* Tests for the `wp_enqueue_code_editor()` function.
*
* @group general
* @group dependencies
*
* @covers ::wp_enqueue_code_editor
*/
class Tests_General_WpEnqueueCodeEditor extends WP_UnitTestCase {

/**
* Tests that a logged-in user with syntax highlighting disabled gets false.
*
* @ticket 66828
*/
public function test_wp_enqueue_code_editor_returns_false_when_syntax_highlighting_disabled() {
$user_id = self::factory()->user->create();
wp_set_current_user( $user_id );
wp_get_current_user()->syntax_highlighting = 'false';

$this->assertFalse(
wp_enqueue_code_editor(
array(
'type' => 'text/css',
)
)
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other early return, for empty filtered settings, isn't covered anywhere. When I removed the empty( $settings ) || empty( $settings['codemirror'] ) check, the existing code editor, script and widget tests all still passed. This test covers it, and it fails with that check removed:

Suggested change
}
}
/**
* Tests that nothing is enqueued when the filtered settings have no CodeMirror settings.
*
* @ticket 66757
*/
public function test_wp_enqueue_code_editor_returns_false_when_settings_are_empty() {
add_filter( 'wp_code_editor_settings', '__return_false' );
$this->assertFalse( wp_enqueue_code_editor( array( 'type' => 'text/css' ) ), 'The function should return false.' );
$this->assertFalse( wp_script_is( 'code-editor', 'enqueued' ), 'The code editor script should not be enqueued.' );
$this->assertFalse( wp_style_is( 'code-editor', 'enqueued' ), 'The code editor style should not be enqueued.' );
}

}
Loading