2020-03-27 01:16:58 +01:00
|
|
|
/* global JSON, wp */
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
|
|
|
|
wp.customize.settingConstructor.abbreviation = wp.customize.Setting.extend({
|
|
|
|
validate: function( value ) {
|
|
|
|
return value.toUpperCase();
|
|
|
|
}
|
|
|
|
});
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
jQuery( window ).load( function() {
|
2014-12-16 20:43:22 +01:00
|
|
|
'use strict';
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
var controlId, controlLabel, controlType, controlContent, controlDescription, controlData, mockControl,
|
|
|
|
mockControlInstance, controlExpectedValues, sectionId, sectionContent, sectionData, mockSection,
|
|
|
|
sectionInstance, sectionExpectedValues, panelId, panelTitle, panelDescription, panelContent, panelData,
|
2014-12-16 20:43:22 +01:00
|
|
|
mockPanel, panelExpectedValues, testCustomizerModel, settingId, settingValue, mockSetting;
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
testCustomizerModel = function( model, expectedValues ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
if ( ! expectedValues.type || ! wp.customize[ expectedValues.type ] ) {
|
|
|
|
throw new Error( 'Must pass value type in expectedValues.' );
|
|
|
|
}
|
|
|
|
var type = expectedValues.type;
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Model extends proper type', function( assert ) {
|
|
|
|
assert.ok( model.extended( wp.customize[ type ] ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
if ( expectedValues.hasOwnProperty( 'id' ) ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right id', function( assert ) {
|
|
|
|
assert.equal( model.id, expectedValues.id );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'title') ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right title.', function( assert ) {
|
|
|
|
assert.equal( model.params.title, expectedValues.title );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'description' ) ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right description.', function( assert ) {
|
|
|
|
assert.equal( model.params.description, expectedValues.description );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'content' ) ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right content.', function( assert ) {
|
|
|
|
assert.equal( model.params.content, expectedValues.content );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'priority' ) ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right priority.', function( assert ) {
|
|
|
|
assert.equal( model.priority(), expectedValues.priority );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
2014-12-16 20:43:22 +01:00
|
|
|
if ( expectedValues.hasOwnProperty( 'active' ) ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right active state.', function( assert ) {
|
|
|
|
assert.equal( model.active(), expectedValues.active );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2014-12-16 20:43:22 +01:00
|
|
|
}
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' can be deactivated', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
model.activate();
|
|
|
|
model.deactivate();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( model.active(), false );
|
2014-12-16 20:43:22 +01:00
|
|
|
model.activate();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( model.active(), true );
|
|
|
|
assert.ok(true);
|
2014-12-16 20:43:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if ( type === 'Panel' || type === 'Section' ) {
|
|
|
|
if ( expectedValues.hasOwnProperty( 'expanded' ) ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance has the right expanded state.', function( assert ) {
|
|
|
|
assert.equal( model.expanded(), expectedValues.expanded );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
|
|
|
}
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance is collapsed after calling .collapse()', function( assert ) {
|
2014-12-02 23:55:48 +01:00
|
|
|
model.collapse();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! model.expanded() );
|
2014-12-16 20:43:22 +01:00
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( type + ' instance is expanded after calling .expand()', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
model.expand();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( model.expanded() );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer notifications collection' );
|
|
|
|
QUnit.test( 'Notifications collection exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.notifications );
|
|
|
|
assert.equal( wp.customize.notifications.defaultConstructor, wp.customize.Notification );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Notification objects are rendered as part of notifications collection', function( assert ) {
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
var container = jQuery( '#customize-notifications-test' ), items, collection;
|
|
|
|
|
|
|
|
collection = new wp.customize.Notifications({
|
|
|
|
container: container
|
|
|
|
});
|
2019-10-04 23:19:17 +02:00
|
|
|
collection.add( 'mycode-1', new wp.customize.Notification( 'mycode-1', { message: 'My message 1' } ) );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
collection.render();
|
|
|
|
items = collection.container.find( 'li' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( items.length, 1 );
|
|
|
|
assert.equal( items.first().data( 'code' ), 'mycode-1' );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
|
|
|
|
collection.add( 'mycode-2', new wp.customize.Notification( 'mycode-2', {
|
2019-10-04 23:19:17 +02:00
|
|
|
message: 'My message 2',
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
dismissible: true
|
|
|
|
} ) );
|
|
|
|
collection.render();
|
|
|
|
items = collection.container.find( 'li' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( items.length, 2 );
|
|
|
|
assert.equal( items.first().data( 'code' ), 'mycode-2' );
|
|
|
|
assert.equal( items.last().data( 'code' ), 'mycode-1' );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( items.first().find( '.notice-dismiss' ).length, 1 );
|
|
|
|
assert.equal( items.last().find( '.notice-dismiss' ).length, 0 );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
|
|
|
|
collection.remove( 'mycode-2' );
|
|
|
|
collection.render();
|
|
|
|
items = collection.container.find( 'li' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( items.length, 1 );
|
|
|
|
assert.equal( items.first().data( 'code' ), 'mycode-1' );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
|
|
|
|
collection.remove( 'mycode-1' );
|
|
|
|
collection.render();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( collection.container.is( ':hidden' ), 'Notifications area is hidden.' );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Previewed Device' );
|
|
|
|
QUnit.test( 'Previewed device defaults to desktop.', function( assert ) {
|
|
|
|
assert.equal( wp.customize.previewedDevice.get(), 'desktop' );
|
2016-02-16 02:56:13 +01:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Setting in Fixture' );
|
|
|
|
QUnit.test( 'Setting has fixture value', function( assert ) {
|
|
|
|
assert.equal( wp.customize( 'fixture-setting' )(), 'Lorem Ipsum' );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Setting has notifications', function( assert ) {
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
var setting = wp.customize( 'fixture-setting' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( setting.notifications.extended( wp.customize.Values ) );
|
|
|
|
assert.equal( wp.customize.Notification, setting.notifications.prototype.constructor.defaultConstructor );
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Setting has findControls method', function( assert ) {
|
2016-06-14 21:16:54 +02:00
|
|
|
var controls, setting = wp.customize( 'fixture-setting' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( 'function', typeof setting.findControls );
|
2016-06-14 21:16:54 +02:00
|
|
|
controls = setting.findControls();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( 1, controls.length );
|
|
|
|
assert.equal( 'fixture-control', controls[0].id );
|
2016-06-14 21:16:54 +02:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Setting constructor object exists', function( assert ) {
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
assert.ok( _.isObject( wp.customize.settingConstructor ) );
|
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Custom setting constructor is used', function( assert ) {
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
var setting = wp.customize( 'fixture-setting-abbr' );
|
|
|
|
assert.ok( setting.extended( wp.customize.settingConstructor.abbreviation ) );
|
|
|
|
setting.set( 'usa' );
|
|
|
|
assert.equal( 'USA', setting.get() );
|
|
|
|
} );
|
2014-12-16 20:43:22 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Control in Fixture' );
|
|
|
|
QUnit.test( 'Control exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.control.has( 'fixture-control' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control has the fixture setting', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var control = wp.customize.control( 'fixture-control' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( control.setting(), 'Lorem Ipsum' );
|
|
|
|
assert.equal( control.setting.id, 'fixture-setting' );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control has the section fixture section ID', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var control = wp.customize.control( 'fixture-control' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( control.section(), 'fixture-section' );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control has notifications', function ( assert ) {
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
var control = wp.customize.control( 'fixture-control' ), settingNotification, controlOnlyNotification, doneEmbedded;
|
|
|
|
assert.ok( control.notifications.extended( wp.customize.Values ) );
|
|
|
|
assert.equal( wp.customize.Notification, control.notifications.prototype.constructor.defaultConstructor );
|
|
|
|
assert.ok( _.isFunction( control.getNotificationsContainerElement ) );
|
|
|
|
assert.ok( _.isFunction( control.renderNotifications ) );
|
|
|
|
|
|
|
|
doneEmbedded = assert.async();
|
|
|
|
control.deferred.embedded.done( function() {
|
|
|
|
var notificationContainerElement;
|
|
|
|
|
|
|
|
assert.equal( 0, _.size( control.notifications._value ) );
|
|
|
|
assert.equal( 0, _.size( control.settings['default'].notifications._value ) );
|
|
|
|
|
|
|
|
notificationContainerElement = control.getNotificationsContainerElement();
|
|
|
|
assert.equal( 1, notificationContainerElement.length );
|
|
|
|
assert.ok( notificationContainerElement.is( '.customize-control-notifications-container' ) );
|
|
|
|
assert.equal( 0, notificationContainerElement.find( '> ul > li' ).length );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
assert.equal( 0, notificationContainerElement.height() );
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
|
2019-10-04 23:19:17 +02:00
|
|
|
settingNotification = new wp.customize.Notification( 'setting_invalidity', { message: 'Invalid setting' } );
|
|
|
|
controlOnlyNotification = new wp.customize.Notification( 'control_invalidity', { message: 'Invalid control' } );
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
control.settings['default'].notifications.add( settingNotification.code, settingNotification );
|
|
|
|
control.notifications.add( controlOnlyNotification.code, controlOnlyNotification );
|
|
|
|
|
|
|
|
// Note that renderNotifications is being called manually here since rendering normally happens asynchronously.
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
control.notifications.render();
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
|
|
|
|
assert.equal( 2, notificationContainerElement.find( '> ul > li' ).length );
|
|
|
|
assert.notEqual( 'none', notificationContainerElement.css( 'display' ) );
|
|
|
|
assert.equal( 2, _.size( control.notifications._value ) );
|
|
|
|
assert.equal( 1, _.size( control.settings['default'].notifications._value ) );
|
|
|
|
|
|
|
|
control.notifications.remove( controlOnlyNotification.code );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
control.notifications.render();
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
assert.equal( 1, notificationContainerElement.find( '> ul > li' ).length );
|
|
|
|
assert.notEqual( 'none', notificationContainerElement.css( 'display' ) );
|
|
|
|
|
|
|
|
control.settings['default'].notifications.remove( settingNotification.code );
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
git-svn-id: https://develop.svn.wordpress.org/trunk@41374 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-12 09:02:49 +02:00
|
|
|
control.notifications.render();
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 23:09:40 +02:00
|
|
|
assert.equal( 0, notificationContainerElement.find( '> ul > li' ).length );
|
|
|
|
notificationContainerElement.stop().hide(); // Clean up.
|
|
|
|
|
|
|
|
doneEmbedded();
|
|
|
|
} );
|
|
|
|
} );
|
2014-12-16 20:43:22 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer control without associated settings' );
|
|
|
|
QUnit.test( 'Control can be created without settings', function( assert ) {
|
2016-02-24 19:27:45 +01:00
|
|
|
var control = new wp.customize.Control( 'settingless', {
|
|
|
|
params: {
|
|
|
|
content: jQuery( '<li class="settingless">Hello World</li>' ),
|
|
|
|
section: 'fixture-section'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
wp.customize.control.add( control.id, control );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( control.deferred.embedded.state(), 'resolved' );
|
|
|
|
assert.ok( null === control.setting );
|
|
|
|
assert.ok( jQuery.isEmptyObject( control.settings ) );
|
2016-02-24 19:27:45 +01:00
|
|
|
} );
|
|
|
|
|
2015-05-30 02:02:13 +02:00
|
|
|
// Begin sections.
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Section in Fixture' );
|
|
|
|
QUnit.test( 'Fixture section exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.section.has( 'fixture-section' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Fixture section has control among controls()', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var section = wp.customize.section( 'fixture-section' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( -1 !== _.pluck( section.controls(), 'id' ).indexOf( 'fixture-control' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Fixture section has has expected panel', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var section = wp.customize.section( 'fixture-section' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( section.panel(), 'fixture-panel' );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Default Section with Template in Fixture' );
|
|
|
|
QUnit.test( 'Fixture section exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.section.has( 'fixture-section-default-templated' ) );
|
2015-05-30 02:02:13 +02:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Fixture section has expected content', function( assert ) {
|
2015-05-30 02:02:13 +02:00
|
|
|
var id = 'fixture-section-default-templated', section;
|
|
|
|
section = wp.customize.section( id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! section.params.content );
|
|
|
|
assert.ok( !! section.container );
|
|
|
|
assert.ok( !! section.headContainer );
|
|
|
|
assert.ok( !! section.contentContainer );
|
|
|
|
assert.ok( section.container.has( section.headContainer ) );
|
|
|
|
assert.ok( section.container.has( section.contentContainer ) );
|
|
|
|
assert.ok( section.headContainer.is( '.control-section.control-section-default' ) );
|
|
|
|
assert.ok( 1 === section.headContainer.find( '> .accordion-section-title' ).length );
|
|
|
|
assert.ok( section.contentContainer.is( '.accordion-section-content' ) );
|
|
|
|
assert.equal( section.headContainer.attr( 'aria-owns' ), section.contentContainer.attr( 'id' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.module( 'Customizer Custom Type (titleless) Section with Template in Fixture' );
|
|
|
|
QUnit.test( 'Fixture section exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.section.has( 'fixture-section-titleless-templated' ) );
|
|
|
|
} );
|
|
|
|
QUnit.test( 'Fixture section has expected content', function( assert ) {
|
2015-05-30 02:02:13 +02:00
|
|
|
var id = 'fixture-section-titleless-templated', section;
|
|
|
|
section = wp.customize.section( id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! section.params.content );
|
|
|
|
assert.ok( !! section.container );
|
|
|
|
assert.ok( !! section.headContainer );
|
|
|
|
assert.ok( !! section.contentContainer );
|
|
|
|
assert.ok( section.container.has( section.headContainer ) );
|
|
|
|
assert.ok( section.container.has( section.contentContainer ) );
|
|
|
|
assert.ok( section.container.is( '.control-section.control-section-titleless' ) );
|
|
|
|
assert.ok( 0 === section.headContainer.find( '> .accordion-section-title' ).length );
|
|
|
|
assert.ok( section.contentContainer.is( '.accordion-section-content' ) );
|
|
|
|
assert.equal( section.headContainer.attr( 'aria-owns' ), section.contentContainer.attr( 'id' ) );
|
|
|
|
} );
|
|
|
|
QUnit.module( 'Customizer Custom Type Section Lacking Specific Template' );
|
|
|
|
QUnit.test( 'Fixture section has expected content', function( assert ) {
|
2015-06-02 00:46:56 +02:00
|
|
|
var id = 'fixture-section-reusing-default-template', section;
|
|
|
|
section = wp.customize.section( id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! section.params.content );
|
|
|
|
assert.ok( !! section.container );
|
|
|
|
assert.ok( !! section.headContainer );
|
|
|
|
assert.ok( !! section.contentContainer );
|
|
|
|
assert.ok( section.container.has( section.headContainer ) );
|
|
|
|
assert.ok( section.container.has( section.contentContainer ) );
|
|
|
|
assert.ok( section.headContainer.is( '.control-section.control-section-' + section.params.type ) );
|
|
|
|
assert.ok( 1 === section.headContainer.find( '> .accordion-section-title' ).length );
|
|
|
|
assert.ok( section.contentContainer.is( '.accordion-section-content' ) );
|
|
|
|
assert.equal( section.headContainer.attr( 'aria-owns' ), section.contentContainer.attr( 'id' ) );
|
|
|
|
} );
|
|
|
|
QUnit.module( 'Customizer Section lacking any params' );
|
|
|
|
QUnit.test( 'Fixture section has default params supplied', function( assert ) {
|
2015-06-02 00:46:56 +02:00
|
|
|
var id = 'fixture-section-without-params', section, defaultParams;
|
|
|
|
section = wp.customize.section( id );
|
|
|
|
defaultParams = {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
priority: 100,
|
|
|
|
panel: null,
|
|
|
|
type: 'default',
|
|
|
|
content: null,
|
|
|
|
active: true,
|
|
|
|
customizeAction: ''
|
|
|
|
};
|
|
|
|
jQuery.each( defaultParams, function ( key, value ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( 'undefined' !== typeof section.params[ key ] );
|
|
|
|
assert.equal( value, section.params[ key ] );
|
2015-06-02 00:46:56 +02:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( _.isNumber( section.params.instanceNumber ) );
|
2015-06-02 00:46:56 +02:00
|
|
|
} );
|
|
|
|
|
2015-05-30 02:02:13 +02:00
|
|
|
|
|
|
|
// Begin panels.
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Panel in Fixture' );
|
|
|
|
QUnit.test( 'Fixture panel exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.panel.has( 'fixture-panel' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Fixture panel has content', function( assert ) {
|
2015-05-30 02:02:13 +02:00
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( !! panel.params.content );
|
|
|
|
assert.ok( !! panel.container );
|
|
|
|
assert.ok( !! panel.headContainer );
|
|
|
|
assert.ok( !! panel.contentContainer );
|
|
|
|
assert.ok( panel.container.has( panel.headContainer ) );
|
|
|
|
assert.ok( panel.container.has( panel.contentContainer ) );
|
|
|
|
} );
|
|
|
|
QUnit.test( 'Fixture panel has section among its sections()', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( -1 !== _.pluck( panel.sections(), 'id' ).indexOf( 'fixture-section' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Panel is not expanded by default', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! panel.expanded() );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Panel is not expanded by default', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! panel.expanded() );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Focusing on a control will expand the panel and section', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
var panel, section, control;
|
|
|
|
panel = wp.customize.panel( 'fixture-panel' );
|
|
|
|
section = wp.customize.section( 'fixture-section' );
|
|
|
|
control = wp.customize.control( 'fixture-control' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! panel.expanded() );
|
|
|
|
assert.ok( ! section.expanded() );
|
2014-12-16 20:43:22 +01:00
|
|
|
control.focus();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( section.expanded() );
|
|
|
|
assert.ok( panel.expanded() );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customizer Default Panel with Template in Fixture' );
|
|
|
|
QUnit.test( 'Fixture section exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.panel.has( 'fixture-panel-default-templated' ) );
|
2015-05-30 02:02:13 +02:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Fixture panel has expected content', function( assert ) {
|
2015-05-30 02:02:13 +02:00
|
|
|
var id = 'fixture-panel-default-templated', panel;
|
|
|
|
panel = wp.customize.panel( id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! panel.params.content );
|
|
|
|
assert.ok( !! panel.container );
|
|
|
|
assert.ok( !! panel.headContainer );
|
|
|
|
assert.ok( !! panel.contentContainer );
|
|
|
|
assert.ok( panel.container.has( panel.headContainer ) );
|
|
|
|
assert.ok( panel.container.has( panel.contentContainer ) );
|
|
|
|
assert.ok( panel.headContainer.is( '.control-panel.control-panel-default' ) );
|
|
|
|
assert.ok( 1 === panel.headContainer.find( '> .accordion-section-title' ).length );
|
|
|
|
assert.ok( panel.contentContainer.is( '.control-panel-content' ) );
|
|
|
|
assert.equal( panel.headContainer.attr( 'aria-owns' ), panel.contentContainer.attr( 'id' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.module( 'Customizer Custom Type Panel (titleless) with Template in Fixture' );
|
|
|
|
QUnit.test( 'Fixture panel exists', function( assert ) {
|
|
|
|
assert.ok( wp.customize.panel.has( 'fixture-panel-titleless-templated' ) );
|
|
|
|
} );
|
|
|
|
QUnit.test( 'Fixture panel has expected content', function( assert ) {
|
2015-05-30 02:02:13 +02:00
|
|
|
var id = 'fixture-panel-titleless-templated', panel;
|
|
|
|
panel = wp.customize.panel( id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! panel.params.content );
|
|
|
|
assert.ok( !! panel.container );
|
|
|
|
assert.ok( !! panel.headContainer );
|
|
|
|
assert.ok( !! panel.contentContainer );
|
|
|
|
assert.ok( panel.container.has( panel.headContainer ) );
|
|
|
|
assert.ok( panel.container.has( panel.contentContainer ) );
|
|
|
|
assert.ok( panel.headContainer.is( '.control-panel.control-panel-titleless' ) );
|
|
|
|
assert.ok( 0 === panel.headContainer.find( '> .accordion-section-title' ).length );
|
|
|
|
assert.ok( panel.contentContainer.is( '.control-panel-content' ) );
|
|
|
|
assert.equal( panel.headContainer.attr( 'aria-owns' ), panel.contentContainer.attr( 'id' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.module( 'Customizer Custom Type Panel Lacking Specific Template' );
|
|
|
|
QUnit.test( 'Fixture panel has expected content', function( assert ) {
|
2015-06-02 00:46:56 +02:00
|
|
|
var id = 'fixture-panel-reusing-default-template', panel;
|
|
|
|
panel = wp.customize.panel( id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! panel.params.content );
|
|
|
|
assert.ok( !! panel.container );
|
|
|
|
assert.ok( !! panel.headContainer );
|
|
|
|
assert.ok( !! panel.contentContainer );
|
|
|
|
assert.ok( panel.container.has( panel.headContainer ) );
|
|
|
|
assert.ok( panel.container.has( panel.contentContainer ) );
|
|
|
|
assert.ok( panel.headContainer.is( '.control-panel.control-panel-' + panel.params.type ) );
|
|
|
|
assert.ok( 1 === panel.headContainer.find( '> .accordion-section-title' ).length );
|
|
|
|
assert.ok( panel.contentContainer.is( '.control-panel-content' ) );
|
|
|
|
assert.equal( panel.headContainer.attr( 'aria-owns' ), panel.contentContainer.attr( 'id' ) );
|
|
|
|
} );
|
|
|
|
QUnit.module( 'Customizer Panel lacking any params' );
|
|
|
|
QUnit.test( 'Fixture panel has default params supplied', function( assert ) {
|
2015-06-02 00:46:56 +02:00
|
|
|
var id = 'fixture-panel-without-params', panel, defaultParams;
|
|
|
|
panel = wp.customize.panel( id );
|
|
|
|
defaultParams = {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
priority: 100,
|
|
|
|
type: 'default',
|
|
|
|
content: null,
|
2017-10-04 08:47:37 +02:00
|
|
|
active: true
|
2015-06-02 00:46:56 +02:00
|
|
|
};
|
|
|
|
jQuery.each( defaultParams, function ( key, value ) {
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( 'undefined' !== typeof panel.params[ key ] );
|
|
|
|
assert.equal( value, panel.params[ key ] );
|
2015-06-02 00:46:56 +02:00
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( _.isNumber( panel.params.instanceNumber ) );
|
2015-06-02 00:46:56 +02:00
|
|
|
} );
|
2014-12-16 20:43:22 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Dynamically-created Customizer Setting Model' );
|
2014-12-16 20:43:22 +01:00
|
|
|
settingId = 'new_blogname';
|
|
|
|
settingValue = 'Hello World';
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Create a new setting', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
mockSetting = wp.customize.create(
|
|
|
|
settingId,
|
|
|
|
settingId,
|
|
|
|
settingValue,
|
|
|
|
{
|
|
|
|
transport: 'refresh',
|
|
|
|
previewer: wp.customize.previewer
|
|
|
|
}
|
|
|
|
);
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( mockSetting(), settingValue );
|
|
|
|
assert.equal( mockSetting.id, settingId );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Dynamically-created Customizer Section Model' );
|
2014-12-16 20:43:22 +01:00
|
|
|
|
|
|
|
sectionId = 'mock_title_tagline';
|
2015-05-30 02:02:13 +02:00
|
|
|
sectionContent = '<li id="accordion-section-mock_title_tagline" class="accordion-section control-section control-section-default"> <h3 class="accordion-section-title" tabindex="0"> Section Fixture <span class="screen-reader-text">Press return or enter to open</span> </h3> <ul class="accordion-section-content"> <li class="customize-section-description-container"> <div class="customize-section-title"> <button class="customize-section-back" tabindex="-1"> <span class="screen-reader-text">Back</span> </button> <h3> <span class="customize-action">Customizing ▸ Fixture Panel</span> Section Fixture </h3> </div> </li> </ul> </li>';
|
2014-12-16 20:43:22 +01:00
|
|
|
sectionData = {
|
|
|
|
content: sectionContent,
|
2015-05-30 02:02:13 +02:00
|
|
|
active: true,
|
|
|
|
type: 'default'
|
2014-12-16 20:43:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mockSection = new wp.customize.Section( sectionId, { params: sectionData } );
|
|
|
|
|
|
|
|
sectionExpectedValues = {
|
|
|
|
type: 'Section',
|
|
|
|
id: sectionId,
|
|
|
|
content: sectionContent,
|
|
|
|
priority: 100,
|
2020-01-29 01:43:23 +01:00
|
|
|
active: true // @todo This should default to true.
|
2014-12-16 20:43:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
testCustomizerModel( mockSection, sectionExpectedValues );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Section has been embedded', function( assert ) {
|
|
|
|
assert.equal( mockSection.deferred.embedded.state(), 'resolved' );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
wp.customize.section.add( sectionId, mockSection );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Section instance added to the wp.customize.section object', function( assert ) {
|
|
|
|
assert.ok( wp.customize.section.has( sectionId ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
sectionInstance = wp.customize.section( sectionId );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Section instance has right content when accessed from wp.customize.section()', function( assert ) {
|
|
|
|
assert.equal( sectionInstance.params.content, sectionContent );
|
2014-12-16 20:43:22 +01:00
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Section instance has no children yet', function( assert ) {
|
|
|
|
assert.equal( sectionInstance.controls().length, 0 );
|
2014-12-16 20:43:22 +01:00
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Dynamically-created Customizer Control Model' );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
controlId = 'new_blogname';
|
|
|
|
controlLabel = 'Site Title';
|
|
|
|
controlType = 'text';
|
|
|
|
controlContent = '<li id="customize-control-blogname" class="customize-control customize-control-text"></li>';
|
|
|
|
controlDescription = 'Test control description';
|
|
|
|
|
|
|
|
controlData = {
|
2014-12-16 20:43:22 +01:00
|
|
|
content: controlContent,
|
|
|
|
description: controlDescription,
|
|
|
|
label: controlLabel,
|
|
|
|
settings: { 'default': 'new_blogname' },
|
|
|
|
type: controlType,
|
2020-01-29 01:43:23 +01:00
|
|
|
active: true // @todo This should default to true.
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
mockControl = new wp.customize.Control( controlId, {
|
|
|
|
params: controlData,
|
|
|
|
previewer: wp.customize.previewer
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
controlExpectedValues = {
|
2014-12-16 20:43:22 +01:00
|
|
|
type: 'Control',
|
|
|
|
content: controlContent,
|
|
|
|
description: controlDescription,
|
|
|
|
label: controlLabel,
|
|
|
|
id: controlId,
|
|
|
|
priority: 10
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
testCustomizerModel( mockControl, controlExpectedValues );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control instance does not yet belong to a section.', function( assert ) {
|
|
|
|
assert.equal( mockControl.section(), undefined );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control has not been embedded yet', function( assert ) {
|
|
|
|
assert.equal( mockControl.deferred.embedded.state(), 'pending' );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control instance has the right selector.', function( assert ) {
|
|
|
|
assert.equal( mockControl.selector, '#customize-control-new_blogname' );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
wp.customize.control.add( controlId, mockControl );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control instance was added to the control class.', function( assert ) {
|
|
|
|
assert.ok( wp.customize.control.has( controlId ) );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
mockControlInstance = wp.customize.control( controlId );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control instance has the right id when accessed from api.control().', function( assert ) {
|
|
|
|
assert.equal( mockControlInstance.id, controlId );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control section can be set as expected', function( assert ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
mockControl.section( mockSection.id );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( mockControl.section(), mockSection.id );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Associating a control with a section allows it to be embedded', function( assert ) {
|
|
|
|
assert.equal( mockControl.deferred.embedded.state(), 'resolved' );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Control is now available on section.controls()', function( assert ) {
|
|
|
|
assert.equal( sectionInstance.controls().length, 1 );
|
|
|
|
assert.equal( sectionInstance.controls()[0], mockControl );
|
2014-12-16 20:43:22 +01:00
|
|
|
});
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Dynamically-created Customizer Panel Model' );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
panelId = 'mockPanelId';
|
|
|
|
panelTitle = 'Mock Panel Title';
|
|
|
|
panelDescription = 'Mock panel description';
|
2015-10-17 01:47:56 +02:00
|
|
|
panelContent = '<li id="accordion-panel-mockPanelId" class="accordion-section control-section control-panel control-panel-default"> <h3 class="accordion-section-title" tabindex="0"> Fixture Panel <span class="screen-reader-text">Press return or enter to open this panel</span> </h3> <ul class="accordion-sub-container control-panel-content"> <li class="panel-meta customize-info accordion-section cannot-expand"> <button class="customize-panel-back" tabindex="-1"><span class="screen-reader-text">Back</span></button> <div class="accordion-section-title"> <span class="preview-notice">You are customizing <strong class="panel-title">Fixture Panel</strong></span> <button class="customize-help-toggle dashicons dashicons-editor-help" tabindex="0" aria-expanded="false"><span class="screen-reader-text">Help</span></button> </div> </li> </ul> </li>';
|
2014-12-02 23:55:48 +01:00
|
|
|
panelData = {
|
2014-12-16 20:43:22 +01:00
|
|
|
content: panelContent,
|
|
|
|
title: panelTitle,
|
|
|
|
description: panelDescription,
|
2020-01-29 01:43:23 +01:00
|
|
|
active: true, // @todo This should default to true.
|
2015-05-30 02:02:13 +02:00
|
|
|
type: 'default'
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
mockPanel = new wp.customize.Panel( panelId, { params: panelData } );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
panelExpectedValues = {
|
2014-12-16 20:43:22 +01:00
|
|
|
type: 'Panel',
|
|
|
|
id: panelId,
|
|
|
|
title: panelTitle,
|
|
|
|
description: panelDescription,
|
|
|
|
content: panelContent,
|
|
|
|
priority: 100,
|
|
|
|
active: true
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
testCustomizerModel( mockPanel, panelExpectedValues );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'Panel instance is not contextuallyActive', function( assert ) {
|
|
|
|
assert.equal( mockPanel.isContextuallyActive(), false );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2016-06-14 21:16:54 +02:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Test wp.customize.findControlsForSettings' );
|
|
|
|
QUnit.test( 'findControlsForSettings(blogname)', function( assert ) {
|
2016-06-14 21:16:54 +02:00
|
|
|
var controlsForSettings, settingId = 'fixture-setting', controlId = 'fixture-control';
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( wp.customize.control.has( controlId ) );
|
|
|
|
assert.ok( wp.customize.has( settingId ) );
|
2016-06-14 21:16:54 +02:00
|
|
|
controlsForSettings = wp.customize.findControlsForSettings( [ settingId ] );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( _.isObject( controlsForSettings ), 'Response is object' );
|
|
|
|
assert.ok( _.isArray( controlsForSettings['fixture-setting'] ), 'Response has a fixture-setting array' );
|
|
|
|
assert.equal( 1, controlsForSettings['fixture-setting'].length );
|
|
|
|
assert.equal( wp.customize.control( controlId ), controlsForSettings['fixture-setting'][0] );
|
2016-06-14 21:16:54 +02:00
|
|
|
} );
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-18 22:04:36 +02:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Controls wp.customize.dirtyValues' );
|
|
|
|
QUnit.test( 'dirtyValues() returns expected values', function( assert ) {
|
2016-10-28 05:28:07 +02:00
|
|
|
wp.customize.state( 'changesetStatus' ).set( 'auto-draft' );
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-18 22:04:36 +02:00
|
|
|
wp.customize.each( function( setting ) {
|
|
|
|
setting._dirty = false;
|
|
|
|
} );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( _.isEmpty( wp.customize.dirtyValues() ) );
|
|
|
|
assert.ok( _.isEmpty( wp.customize.dirtyValues( { unsaved: false } ) ) );
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-18 22:04:36 +02:00
|
|
|
|
|
|
|
wp.customize( 'fixture-setting' )._dirty = true;
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! _.isEmpty( wp.customize.dirtyValues() ) );
|
|
|
|
assert.ok( _.isEmpty( wp.customize.dirtyValues( { unsaved: true } ) ) );
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-18 22:04:36 +02:00
|
|
|
|
|
|
|
wp.customize( 'fixture-setting' ).set( 'Modified' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! _.isEmpty( wp.customize.dirtyValues() ) );
|
|
|
|
assert.ok( ! _.isEmpty( wp.customize.dirtyValues( { unsaved: true } ) ) );
|
|
|
|
assert.equal( 'Modified', wp.customize.dirtyValues()['fixture-setting'] );
|
2016-10-28 05:28:07 +02:00
|
|
|
|
|
|
|
// When the changeset does not exist, all dirty settings are necessarily unsaved.
|
|
|
|
wp.customize.state( 'changesetStatus' ).set( '' );
|
|
|
|
wp.customize( 'fixture-setting' )._dirty = true;
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( ! _.isEmpty( wp.customize.dirtyValues() ) );
|
|
|
|
assert.ok( ! _.isEmpty( wp.customize.dirtyValues( { unsaved: true } ) ) );
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-18 22:04:36 +02:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Controls: wp.customize.requestChangesetUpdate()' );
|
|
|
|
QUnit.test( 'requestChangesetUpdate makes request and returns promise', function( assert ) {
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-18 22:04:36 +02:00
|
|
|
var request, originalBeforeSetup = jQuery.ajaxSettings.beforeSend;
|
|
|
|
|
|
|
|
jQuery.ajaxSetup( {
|
|
|
|
beforeSend: function( e, data ) {
|
|
|
|
var queryParams, changesetData;
|
|
|
|
queryParams = wp.customize.utils.parseQueryString( data.data );
|
|
|
|
|
|
|
|
assert.equal( 'customize_save', queryParams.action );
|
|
|
|
assert.ok( ! _.isUndefined( queryParams.customize_changeset_data ) );
|
|
|
|
assert.ok( ! _.isUndefined( queryParams.nonce ) );
|
|
|
|
assert.ok( ! _.isUndefined( queryParams.customize_theme ) );
|
|
|
|
assert.equal( wp.customize.settings.changeset.uuid, queryParams.customize_changeset_uuid );
|
|
|
|
assert.equal( 'on', queryParams.wp_customize );
|
|
|
|
|
|
|
|
changesetData = JSON.parse( queryParams.customize_changeset_data );
|
|
|
|
assert.ok( ! _.isUndefined( changesetData.additionalSetting ) );
|
|
|
|
assert.ok( ! _.isUndefined( changesetData['fixture-setting'] ) );
|
|
|
|
|
|
|
|
assert.equal( 'additionalValue', changesetData.additionalSetting.value );
|
|
|
|
assert.equal( 'requestChangesetUpdate', changesetData['fixture-setting'].value );
|
|
|
|
|
|
|
|
// Prevent Ajax request from completing.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.customize.each( function( setting ) {
|
|
|
|
setting._dirty = false;
|
|
|
|
} );
|
|
|
|
|
|
|
|
request = wp.customize.requestChangesetUpdate();
|
|
|
|
assert.equal( 'resolved', request.state());
|
|
|
|
request.done( function( data ) {
|
|
|
|
assert.ok( _.isEqual( {}, data ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.customize( 'fixture-setting' ).set( 'requestChangesetUpdate' );
|
|
|
|
|
|
|
|
request = wp.customize.requestChangesetUpdate( {
|
|
|
|
additionalSetting: {
|
|
|
|
value: 'additionalValue'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
request.always( function( data ) {
|
|
|
|
assert.equal( 'canceled', data.statusText );
|
|
|
|
jQuery.ajaxSetup( { beforeSend: originalBeforeSetup } );
|
|
|
|
} );
|
|
|
|
} );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Utils: wp.customize.utils.getRemainingTime()' );
|
|
|
|
QUnit.test( 'utils.getRemainingTime calculates time correctly', function( assert ) {
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
var datetime = '2599-08-06 12:12:13', timeRemaining, timeRemainingWithDateInstance, timeRemaingingWithTimestamp;
|
|
|
|
|
|
|
|
timeRemaining = wp.customize.utils.getRemainingTime( datetime );
|
|
|
|
timeRemainingWithDateInstance = wp.customize.utils.getRemainingTime( new Date( datetime.replace( /-/g, '/' ) ) );
|
|
|
|
timeRemaingingWithTimestamp = wp.customize.utils.getRemainingTime( ( new Date( datetime.replace( /-/g, '/' ) ) ).getTime() );
|
|
|
|
|
|
|
|
assert.equal( typeof timeRemaining, 'number', timeRemaining );
|
|
|
|
assert.equal( typeof timeRemainingWithDateInstance, 'number', timeRemaining );
|
|
|
|
assert.equal( typeof timeRemaingingWithTimestamp, 'number', timeRemaining );
|
|
|
|
assert.deepEqual( timeRemaining, timeRemainingWithDateInstance );
|
|
|
|
assert.deepEqual( timeRemaining, timeRemaingingWithTimestamp );
|
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Utils: wp.customize.utils.getCurrentTimestamp()' );
|
|
|
|
QUnit.test( 'utils.getCurrentTimestamp returns timestamp', function( assert ) {
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
var currentTimeStamp;
|
|
|
|
currentTimeStamp = wp.customize.utils.getCurrentTimestamp();
|
|
|
|
assert.equal( typeof currentTimeStamp, 'number' );
|
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Controls: wp.customize.DateTimeControl' );
|
|
|
|
QUnit.test( 'Test DateTimeControl creation and its methods', function( assert ) {
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
var control, controlId = 'date_time', section, sectionId = 'fixture-section',
|
|
|
|
datetime = '2599-08-06 18:12:13', dateTimeArray, dateTimeArrayInampm, timeString,
|
2017-10-02 06:11:50 +02:00
|
|
|
day, year, month, minute, meridian, hour;
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
|
|
|
section = wp.customize.section( sectionId );
|
|
|
|
|
|
|
|
control = new wp.customize.DateTimeControl( controlId, {
|
|
|
|
params: {
|
|
|
|
section: section.id,
|
|
|
|
type: 'date_time',
|
Customize: Allow controls to be created with pre-instantiated `Setting` object(s), or even with plain `Value` object(s).
* Allow passing settings in keyed object (e.g. `settings: { default: 'id' } ), or as an array (e.g. `settings: [ 'id' ]`) with first being default; again, `Setting`/`Value` objects may be supplied instead of IDs.
* Allow a single setting to be supplied with just a single `setting` param, either a string or a `Setting`/`Value` object.
* Update `changeset_status` and `scheduled_changeset_date` to be added dynamically with JS and simply passing of `api.state()` instances as `setting`.
* Introduce a `data-customize-setting-key-link` attribute which, unlike `data-customize-setting-link`, allows passing the setting key (e.g. `default`) as opposed to the setting ID.
* Allow `WP_Customize_Control::get_link()` to return `data-customize-setting-key-link` when setting is not registered.
* Eliminate `default_value` from `WP_Customize_Date_Time_Control` since now comes from supplied `Value`.
* Export status choices as `wp.customize.settings.changeset.statusChoices`.
* Export date and time formats as `wp.customize.settings.dateFormat` and `wp.customize.settings.timeFormat` respectively.
Props westonruter, sayedwp.
See #39896, #30738, #30741, #42083.
Fixes #37964, #36167.
git-svn-id: https://develop.svn.wordpress.org/trunk@41750 602fd350-edb4-49c9-b593-d223f7449a82
2017-10-04 22:01:12 +02:00
|
|
|
setting: new wp.customize.Value( datetime ),
|
2017-10-02 06:11:50 +02:00
|
|
|
includeTime: true,
|
Customize: Allow controls to be created with pre-instantiated `Setting` object(s), or even with plain `Value` object(s).
* Allow passing settings in keyed object (e.g. `settings: { default: 'id' } ), or as an array (e.g. `settings: [ 'id' ]`) with first being default; again, `Setting`/`Value` objects may be supplied instead of IDs.
* Allow a single setting to be supplied with just a single `setting` param, either a string or a `Setting`/`Value` object.
* Update `changeset_status` and `scheduled_changeset_date` to be added dynamically with JS and simply passing of `api.state()` instances as `setting`.
* Introduce a `data-customize-setting-key-link` attribute which, unlike `data-customize-setting-link`, allows passing the setting key (e.g. `default`) as opposed to the setting ID.
* Allow `WP_Customize_Control::get_link()` to return `data-customize-setting-key-link` when setting is not registered.
* Eliminate `default_value` from `WP_Customize_Date_Time_Control` since now comes from supplied `Value`.
* Export status choices as `wp.customize.settings.changeset.statusChoices`.
* Export date and time formats as `wp.customize.settings.dateFormat` and `wp.customize.settings.timeFormat` respectively.
Props westonruter, sayedwp.
See #39896, #30738, #30741, #42083.
Fixes #37964, #36167.
git-svn-id: https://develop.svn.wordpress.org/trunk@41750 602fd350-edb4-49c9-b593-d223f7449a82
2017-10-04 22:01:12 +02:00
|
|
|
content: '<li id="customize-control-' + controlId + '" class="customize-control"></li>'
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.customize.control.add( controlId, control );
|
|
|
|
|
|
|
|
// Test control creations.
|
|
|
|
assert.ok( control.templateSelector, '#customize-control-date_time-content' );
|
|
|
|
assert.ok( control.section(), sectionId );
|
|
|
|
assert.equal( _.size( control.inputElements ), control.elements.length );
|
|
|
|
assert.ok( control.setting(), datetime );
|
|
|
|
|
|
|
|
day = control.inputElements.day;
|
|
|
|
month = control.inputElements.month;
|
|
|
|
year = control.inputElements.year;
|
|
|
|
minute = control.inputElements.minute;
|
|
|
|
hour = control.inputElements.hour;
|
2017-10-02 06:11:50 +02:00
|
|
|
meridian = control.inputElements.meridian;
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
|
|
|
year( '23' );
|
2017-10-30 17:39:06 +01:00
|
|
|
assert.ok( control.invalidDate );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
2017-10-30 17:39:06 +01:00
|
|
|
year( '2100' );
|
2017-10-02 06:11:50 +02:00
|
|
|
month( '8' );
|
2017-10-30 17:39:06 +01:00
|
|
|
assert.ok( ! control.invalidDate );
|
|
|
|
day( 'test' );
|
|
|
|
assert.ok( control.invalidDate );
|
|
|
|
day( '3' );
|
|
|
|
assert.ok( ! control.invalidDate );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Test control.parseDateTime().
|
2017-10-02 06:11:50 +02:00
|
|
|
control.params.twelveHourFormat = false;
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
dateTimeArray = control.parseDateTime( datetime );
|
|
|
|
assert.deepEqual( dateTimeArray, {
|
|
|
|
year: '2599',
|
|
|
|
month: '08',
|
|
|
|
hour: '18',
|
|
|
|
minute: '12',
|
|
|
|
second: '13',
|
|
|
|
day: '06'
|
|
|
|
} );
|
|
|
|
|
2017-10-02 06:11:50 +02:00
|
|
|
control.params.twelveHourFormat = true;
|
|
|
|
dateTimeArrayInampm = control.parseDateTime( datetime );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
assert.deepEqual( dateTimeArrayInampm, {
|
|
|
|
year: '2599',
|
|
|
|
month: '08',
|
|
|
|
hour: '6',
|
|
|
|
minute: '12',
|
2017-10-02 06:11:50 +02:00
|
|
|
meridian: 'pm',
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
day: '06'
|
|
|
|
} );
|
|
|
|
|
|
|
|
year( '2010' );
|
|
|
|
month( '12' );
|
|
|
|
day( '18' );
|
|
|
|
hour( '3' );
|
|
|
|
minute( '44' );
|
2017-10-02 06:11:50 +02:00
|
|
|
meridian( 'am' );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
|
|
|
// Test control.convertInputDateToString().
|
|
|
|
timeString = control.convertInputDateToString();
|
|
|
|
assert.equal( timeString, '2010-12-18 03:44:00' );
|
|
|
|
|
2017-10-02 06:11:50 +02:00
|
|
|
meridian( 'pm' );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
timeString = control.convertInputDateToString();
|
|
|
|
assert.equal( timeString, '2010-12-18 15:44:00' );
|
|
|
|
|
2017-10-02 06:11:50 +02:00
|
|
|
control.params.includeTime = false;
|
|
|
|
timeString = control.convertInputDateToString();
|
|
|
|
assert.equal( timeString, '2010-12-18' );
|
|
|
|
control.params.includeTime = true;
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Test control.updateDaysForMonth().
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
year( 2017 );
|
|
|
|
month( 2 );
|
2017-10-30 17:39:06 +01:00
|
|
|
day( 28 );
|
|
|
|
assert.ok( ! control.invalidDate );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
day( 31 );
|
2017-10-30 17:39:06 +01:00
|
|
|
assert.ok( control.invalidDate );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
|
|
|
day( 20 );
|
2017-10-30 17:39:06 +01:00
|
|
|
assert.equal( day(), 20, 'Should not update if its less the correct number of days' );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
|
|
|
// Test control.convertHourToTwentyFourHourFormat().
|
|
|
|
assert.equal( control.convertHourToTwentyFourHourFormat( 11, 'pm' ), 23 );
|
|
|
|
assert.equal( control.convertHourToTwentyFourHourFormat( 12, 'pm' ), 12 );
|
|
|
|
assert.equal( control.convertHourToTwentyFourHourFormat( 12, 'am' ), 0 );
|
|
|
|
assert.equal( control.convertHourToTwentyFourHourFormat( 11, 'am' ), 11 );
|
|
|
|
|
|
|
|
// Test control.toggleFutureDateNotification().
|
|
|
|
assert.deepEqual( control.toggleFutureDateNotification(), control );
|
|
|
|
control.toggleFutureDateNotification( true );
|
|
|
|
assert.ok( control.notifications.has( 'not_future_date' ) );
|
|
|
|
control.toggleFutureDateNotification( false );
|
|
|
|
assert.notOk( control.notifications.has( 'not_future_date' ) );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Test control.populateDateInputs().
|
2017-10-02 06:11:50 +02:00
|
|
|
control.setting._value = '2000-12-30 12:34:56';
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
control.populateDateInputs();
|
2017-10-02 06:11:50 +02:00
|
|
|
assert.equal( '2000', control.inputElements.year.get() );
|
|
|
|
assert.equal( '12', control.inputElements.month.get() );
|
|
|
|
assert.equal( '30', control.inputElements.day.get() );
|
|
|
|
assert.equal( '12', control.inputElements.hour.get() );
|
|
|
|
assert.equal( '34', control.inputElements.minute.get() );
|
|
|
|
assert.equal( 'pm', control.inputElements.meridian.get() );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Test control.validateInputs().
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
hour( 33 );
|
|
|
|
assert.ok( control.validateInputs() );
|
|
|
|
hour( 10 );
|
|
|
|
assert.notOk( control.validateInputs() );
|
|
|
|
minute( 123 );
|
|
|
|
assert.ok( control.validateInputs() );
|
|
|
|
minute( 20 );
|
|
|
|
assert.notOk( control.validateInputs() );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Test control.populateSetting().
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
day( 2 );
|
|
|
|
month( 11 );
|
|
|
|
year( 2018 );
|
|
|
|
hour( 4 );
|
|
|
|
minute( 20 );
|
2017-10-02 06:11:50 +02:00
|
|
|
meridian( 'pm' );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
control.populateSetting();
|
|
|
|
assert.equal( control.setting(), '2018-11-02 16:20:00' );
|
|
|
|
|
|
|
|
hour( 123 );
|
|
|
|
control.populateSetting();
|
|
|
|
assert.equal( control.setting(), '2018-11-02 16:20:00' ); // Should not update if invalid hour.
|
|
|
|
|
|
|
|
hour( 5 );
|
|
|
|
control.populateSetting();
|
|
|
|
assert.equal( control.setting(), '2018-11-02 17:20:00' );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Test control.isFutureDate().
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
day( 2 );
|
|
|
|
month( 11 );
|
|
|
|
year( 2318 );
|
|
|
|
hour( 4 );
|
|
|
|
minute( 20 );
|
2017-10-02 06:11:50 +02:00
|
|
|
meridian( 'pm' );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
assert.ok( control.isFutureDate() );
|
|
|
|
|
|
|
|
year( 2016 );
|
|
|
|
assert.notOk( control.isFutureDate() );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Tear down.
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
wp.customize.control.remove( controlId );
|
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Sections: wp.customize.OuterSection' );
|
|
|
|
QUnit.test( 'Test OuterSection', function( assert ) {
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
var section, sectionId = 'test_outer_section', body = jQuery( 'body' ),
|
|
|
|
defaultSection, defaultSectionId = 'fixture-section';
|
|
|
|
|
|
|
|
defaultSection = wp.customize.section( defaultSectionId );
|
|
|
|
|
|
|
|
section = new wp.customize.OuterSection( sectionId, {
|
|
|
|
params: {
|
|
|
|
content: defaultSection.params.content,
|
|
|
|
type: 'outer'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.customize.section.add( sectionId, section );
|
|
|
|
wp.customize.section.add( defaultSectionId, section );
|
|
|
|
|
|
|
|
assert.equal( section.containerPaneParent, '.customize-outer-pane-parent' );
|
|
|
|
assert.equal( section.containerParent.selector, '#customize-outer-theme-controls' );
|
|
|
|
|
|
|
|
defaultSection.expand();
|
|
|
|
section.expand();
|
|
|
|
assert.ok( body.hasClass( 'outer-section-open' ) );
|
|
|
|
assert.ok( section.container.hasClass( 'open' ) );
|
|
|
|
assert.ok( defaultSection.expanded() ); // Ensure it does not affect other sections state.
|
|
|
|
|
|
|
|
section.collapse();
|
|
|
|
assert.notOk( body.hasClass( 'outer-section-open' ) );
|
|
|
|
assert.notOk( section.container.hasClass( 'open' ) ); // Ensure it does not affect other sections state.
|
|
|
|
assert.ok( defaultSection.expanded() );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Tear down.
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
wp.customize.section.remove( sectionId );
|
|
|
|
});
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.module( 'Customize Controls: PreviewLinkControl' );
|
|
|
|
QUnit.test( 'Test PreviewLinkControl creation and its methods', function( assert ) {
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
var section, sectionId = 'publish_settings', newLink;
|
|
|
|
|
|
|
|
section = wp.customize.section( sectionId );
|
|
|
|
section.deferred.embedded.resolve();
|
|
|
|
|
|
|
|
assert.expect( 9 );
|
|
|
|
section.deferred.embedded.done( function() {
|
|
|
|
_.each( section.controls(), function( control ) {
|
|
|
|
if ( 'changeset_preview_link' === control.id ) {
|
|
|
|
assert.equal( control.templateSelector, 'customize-preview-link-control' );
|
|
|
|
assert.equal( _.size( control.previewElements ), control.elements.length );
|
|
|
|
|
|
|
|
// Test control.ready().
|
|
|
|
newLink = 'http://example.org?' + wp.customize.settings.changeset.uuid;
|
|
|
|
control.setting.set( newLink );
|
|
|
|
|
|
|
|
assert.equal( control.previewElements.input(), newLink );
|
2017-10-02 06:11:50 +02:00
|
|
|
assert.equal( control.previewElements.url(), newLink );
|
|
|
|
assert.equal( control.previewElements.url.element.parent().attr( 'href' ), newLink );
|
|
|
|
assert.equal( control.previewElements.url.element.parent().attr( 'target' ), wp.customize.settings.changeset.uuid );
|
Customize: Introduce drafting and scheduling for Customizer changesets.
* Incorporates code from the Customize Snapshots and Customize Posts feature plugins.
* Adds a new Publish Settings section for managing the changeset status, scheduled date, and frontend preview link.
* Updates Publish button to reflect the status selected in the Publish Settings (including Save Draft and Schedule).
* Deactivates the Themes section when a non-publish status selected, and deactivates the Publish Settings section when previewing a theme switch.
* Introduces an `outer` section type (`wp.customize.OuterSection` in JS) for the Publish Settings section to use and for available widgets and available nav menu panels to use in the future. These sections can be expanded while other sections are expanded.
* Introduces `WP_Customize_Date_Time_Control` in PHP and `wp.customize.DateTimeControl` in JS for managing a date/time value.
* Keeps track of scheduled time and proactively publish from the client when the time arrives, as opposed to waiting for WP Cron.
* Auto-publishes a scheduled changeset when attempting to access one that missed its schedule.
* Starts a new changeset if attempting to save a changeset that was previously publish.
* Adds `force` arg to `requestChangesetUpdate()` to force an update request even when there are no pending changes.
* Adds utils methods for `getCurrentTimestamp` and `getRemainingTime`.
* Adds new state values for `selectedChangesetStatus`, `changesetDate`, `selectedChangesetDate`.
* Fixes logic for when to short-circuit check to close Customizer when there are unsaved changes.
* Adds getter methods for `autosaved` and `branching` parameters, with the latter applying the `customize_changeset_branching` filter.
* Call to `establish_loaded_changeset` on the fly when `changeset_uuid()` is called if no changeset UUID was specififed.
* De-duplicates logic for dismissing auto-draft changesets.
* Includes unit tests.
Builds on [41597].
Props sayedwp, westonruter, melchoyce, JoshuaWold, folletto, stubgo, karmatosed, dlh, paaljoachim, afercia, johnregan3, utkarshpatel, valendesigns.
See #30937.
Fixes #39896, #28721, #39275.
git-svn-id: https://develop.svn.wordpress.org/trunk@41626 602fd350-edb4-49c9-b593-d223f7449a82
2017-09-28 00:24:37 +02:00
|
|
|
|
|
|
|
// Test control.toggleSaveNotification().
|
|
|
|
control.toggleSaveNotification( true );
|
|
|
|
assert.ok( control.notifications.has( 'changes_not_saved' ) );
|
|
|
|
control.toggleSaveNotification( false );
|
|
|
|
assert.notOk( control.notifications.has( 'changes_not_saved' ) );
|
|
|
|
|
|
|
|
// Test control.updatePreviewLink().
|
|
|
|
control.updatePreviewLink();
|
|
|
|
assert.equal( control.setting.get(), wp.customize.previewer.getFrontendPreviewUrl() );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
});
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|