Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/js/_enqueues/lib/quicktags.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ window.edToolbar = function(){};
use = '';

// Set buttons.
if ( settings.buttons ) {
if ( settings.buttons || '' === settings.buttons ) {
use = ','+settings.buttons+',';
}

Expand Down
5 changes: 5 additions & 0 deletions tests/qunit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
<script src="../../build/wp-includes/js/customize-base.js"></script>
<script src="../../build/wp-includes/js/customize-models.js"></script>
<script src="../../build/wp-includes/js/shortcode.js"></script>
<script>
window.quicktagsL10n = {"closeAllOpenTags":"Close all open tags","closeTags":"close tags","enterURL":"Enter the URL","enterImageURL":"Enter the URL of the image","enterImageDescription":"Enter a description of the image","textdirection":"text direction","toggleTextdirection":"Switch Editor Text Direction","dfw":"Distraction-free writing mode","strong":"Bold","strongClose":"Close bold tag","em":"Italic","emClose":"Close italic tag","link":"Insert link","blockquote":"Blockquote","blockquoteClose":"Close blockquote tag","del":"Deleted text (strikethrough)","delClose":"Close deleted text tag","ins":"Inserted text","insClose":"Close inserted text tag","image":"Insert image","ul":"Bulleted list","ulClose":"Close bulleted list tag","ol":"Numbered list","olClose":"Close numbered list tag","li":"List item","liClose":"Close list item tag","code":"Code","codeClose":"Close code tag","more":"Insert Read More tag"};
</script>
<script src="../../build/wp-includes/js/quicktags.js"></script>
<script src="../../build/wp-includes/js/wp-sanitize.js"></script>
<script src="../../build/wp-admin/js/updates.js"></script>
<script>
Expand Down Expand Up @@ -187,6 +191,7 @@
<script src="wp-admin/js/dashboard.js"></script>
<script src="wp-admin/js/updates.js"></script>
<script src="wp-includes/js/shortcode.js"></script>
<script src="wp-includes/js/quicktags.js"></script>
<script src="wp-includes/js/media/test-media-models.js"></script>
<script src="wp-includes/js/api-request.js"></script>
<script src="wp-includes/js/jquery.js"></script>
Expand Down
71 changes: 71 additions & 0 deletions tests/qunit/wp-includes/js/quicktags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* global QTags, quicktags */

jQuery( function() {
var editors, originalButtons, originalDir, buttonsInitDone;

function createEditor( settings, clock ) {
var id = 'quicktags-test-' + editors.length, editor;
jQuery( '<textarea>', { id: id } ).appendTo( '#qunit-fixture' );
editor = quicktags( jQuery.extend( { id: id }, settings ) );
editors.push( editor );
clock.tick( 0 );
return editor;
}

QUnit.module( 'quicktags', {
beforeEach: function() {
editors = [];
originalButtons = window.edButtons;
window.edButtons = originalButtons.slice();
buttonsInitDone = QTags.buttonsInitDone;
originalDir = document.documentElement.getAttribute( 'dir' );
document.documentElement.dir = 'ltr';
},
afterEach: function() {
editors.forEach( function( editor ) { editor.remove(); } );
window.edButtons = originalButtons;
QTags.buttonsInitDone = buttonsInitDone;
if ( originalDir === null ) {
document.documentElement.removeAttribute( 'dir' );
} else {
document.documentElement.setAttribute( 'dir', originalDir );
}
}
} );

QUnit.test( 'honors an empty default-button list', function( assert ) {
var editor = createEditor( { buttons: '' }, this.clock );
assert.strictEqual( editor.toolbar.querySelectorAll( '.ed_button' ).length, 0, 'No default buttons are added' );
} );

QUnit.test( 'keeps the defaults for omitted and other falsey settings', function( assert ) {
for ( const settings of [ {}, { buttons: undefined }, { buttons: false }, { buttons: null }, { buttons: 0 } ] ) {
var editor = createEditor( settings, this.clock );
assert.ok( editor.getButtonElement( 'strong' ), 'Keeps defaults for ' + String( settings.buttons ) );
}
} );

QUnit.test( 'honors a nonempty default-button list', function( assert ) {
var editor = createEditor( { buttons: 'strong,em' }, this.clock );
assert.ok( editor.getButtonElement( 'strong' ) );
assert.ok( editor.getButtonElement( 'em' ) );
assert.strictEqual( editor.toolbar.querySelectorAll( '.ed_button' ).length, 2 );
} );

QUnit.test( 'preserves custom buttons and each list when adding a button after initialization', function( assert ) {
var empty = createEditor( { buttons: '' }, this.clock );
var defaults = createEditor( {}, this.clock );
QTags.addButton( 'quicktags_test_custom', 'Custom', '<custom>', '</custom>' );
assert.ok( empty.getButtonElement( 'quicktags_test_custom' ), 'Custom buttons remain available' );
assert.notOk( empty.getButtonElement( 'strong' ), 'Refreshing keeps the empty default list' );
assert.ok( defaults.getButtonElement( 'quicktags_test_custom' ) );
assert.ok( defaults.getButtonElement( 'strong' ), 'Other instances keep their defaults' );
} );

QUnit.test( 'preserves the separate RTL direction control', function( assert ) {
document.documentElement.dir = 'rtl';
var editor = createEditor( { buttons: '' }, this.clock );
assert.ok( editor.getButtonElement( 'textdirection' ) );
assert.notOk( editor.getButtonElement( 'strong' ) );
} );
} );
Loading