Make WordPress Core

Ticket #30942: 30942_unittests.diff

File 30942_unittests.diff, 3.8 KB (added by gitlost, 9 years ago)

Unit tests for patch.

  • tests/qunit/fixtures/quicktags.js

     
     1var quicktagsCanvas = jQuery( '<div id="quicktags-test-parent"><div id="quicktags-test"></div></div>' );
     2quicktagsCanvas.css( { position: 'absolute', top: -1000 } ); // remove from view
     3jQuery( document.body ).append( quicktagsCanvas );
     4
     5window.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","fullscreen":"fullscreen","toggleFullscreen":"Toggle fullscreen mode","textdirection":"text direction","toggleTextdirection":"Toggle Editor Text Direction","dfw":"Distraction-free writing mode"};
  • tests/qunit/index.html

     
    2525    <div id="qunit-fixture">
    2626      <script src="fixtures/customize-header.js"></script>
    2727      <script src="fixtures/customize-settings.js"></script>
     28      <script src="fixtures/quicktags.js"></script>
    2829    </div>
    2930    <p><a href="editor">TinyMCE tests</a></p>
    3031
     
    3435    <script src="../../src/wp-includes/js/customize-models.js"></script>
    3536    <script src="../../src/wp-includes/js/shortcode.js"></script>
    3637    <script src="../../src/wp-admin/js/customize-controls.js"></script>
     38    <script src="../../src/wp-includes/js/quicktags.js"></script>
    3739
    3840    <!-- Unit tests -->
    3941    <script src="wp-admin/js/password-strength-meter.js"></script>
     
    4244    <script src="wp-includes/js/shortcode.js"></script>
    4345    <script src="wp-admin/js/customize-controls.js"></script>
    4446    <script src="wp-admin/js/customize-controls-utils.js"></script>
     47    <script src="wp-includes/js/quicktags.js"></script>
    4548  </div>
    4649</body>
    4750</html>
  • tests/qunit/wp-includes/js/quicktags.js

     
     1/* global wp, jQuery, quicktagsL10n */
     2jQuery( function() {
     3        module( 'quicktags' );
     4
     5        test( 'settings.buttons zero', function() {
     6                var settings = {
     7                        id: 'quicktags-test',
     8                        buttons: ''
     9                };
     10                var qinst = quicktags( settings );
     11                var expected = {};
     12
     13                QTags._buttonsInit(); // Call manually to make sure theButtons exists (#26183).
     14
     15                deepEqual( qinst.theButtons, expected, 'buttons not blank on zero-length string' );
     16        });
     17
     18        test( 'settings.buttons false', function() {
     19                var settings = {
     20                        id: 'quicktags-test',
     21                        buttons: false
     22                };
     23                var qinst = quicktags( settings );
     24                var expected = {};
     25
     26                QTags._buttonsInit(); // Call manually to make sure theButtons exists (#26183).
     27
     28                deepEqual( qinst.theButtons, expected, 'buttons not blank on false' );
     29        });
     30
     31        test( 'settings.buttons one', function() {
     32                var settings = {
     33                        id: 'quicktags-test',
     34                        buttons: 'em'
     35                };
     36                var qinst = quicktags( settings );
     37                var expected = { 'em' : new QTags.TagButton('em','i','<em>','</em>') };
     38
     39                QTags._buttonsInit(); // Call manually to make sure theButtons exists (#26183).
     40
     41                deepEqual( qinst.theButtons, expected, 'buttons not one' );
     42        });
     43
     44        test( 'settings.buttons two', function() {
     45                var settings = {
     46                        id: 'quicktags-test',
     47                        buttons: 'em,ul'
     48                };
     49                var qinst = quicktags( settings );
     50                var expected = {
     51                        'em' : new QTags.TagButton('em','i','<em>','</em>'),
     52                        'ul' : new QTags.TagButton('ul','ul','<ul>\n','</ul>\n\n')
     53                };
     54
     55                QTags._buttonsInit(); // Call manually to make sure theButtons exists (#26183).
     56
     57                deepEqual( qinst.theButtons, expected, 'buttons not two' );
     58        });
     59});