This repository has been archived by the owner. It is now read-only.

Gallery Widget #120

Merged
merged 43 commits into from Sep 19, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+788 −123
Diff settings

Always

Just for now

View
@@ -2,3 +2,7 @@ CHECK_SCOPE=changed-files
PHPCS_RULESET_FILE=phpcs.xml.dist
WPCS_BRANCH=develop
PHPCS_PHAR_URL=https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.0/phpcs.phar
if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then
DEV_LIB_SKIP="$DEV_LIB_SKIP,phpcs"
fi
View
@@ -1,4 +1,5 @@
sudo: false
dist: precise
notifications:
email:
View
@@ -70,6 +70,8 @@ function wp32417_default_scripts( WP_Scripts $scripts ) {
$scripts->add( $handle, $src, array( 'media-widgets', 'media-audiovideo' ) );
}
$scripts->add( 'media-gallery-widget', plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/media-gallery-widget.js', array( 'media-widgets' ) );
if ( ! WP_CORE_MEDIA_WIDGETS_MERGED ) {
$scripts->add_inline_script( 'customize-selective-refresh', file_get_contents( dirname( __FILE__ ) . '/wp-includes/js/customize-selective-refresh-extras.js' ) );
}
@@ -133,12 +135,12 @@ function wp32417_twentyten_styles() {
* @codeCoverageIgnore
*/
function wp32417_widgets_init() {
$class_files = array(
'WP_Widget_Media' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media.php',
'WP_Widget_Media_Image' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-image.php',
'WP_Widget_Media_Video' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-video.php',
'WP_Widget_Media_Audio' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-audio.php',
'WP_Widget_Media' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media.php',
'WP_Widget_Media_Image' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-image.php',
'WP_Widget_Media_Video' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-video.php',
'WP_Widget_Media_Audio' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-audio.php',
'WP_Widget_Media_Gallery' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-gallery.php',
);
foreach ( $class_files as $class => $file ) {
if ( ! class_exists( $class ) ) {
@@ -46,6 +46,7 @@ class Media_Widgets_WP_CLI_Command extends WP_CLI_Command {
'media-image-widget',
'media-video-widget',
'media-audio-widget',
'media-gallery-widget',
);
/**
@@ -0,0 +1,38 @@
<?php
/**
* Unit tests covering WP_Widget_Media_Gallery functionality.
*
* @package WordPress
* @subpackage widgets
*/
/**
* Test wp-includes/widgets/class-wp-widget-gallery.php
*
* @group widgets
*/
class Test_WP_Widget_Media_Gallery extends WP_UnitTestCase {
/**
* Test get_instance_schema method.
*
* @covers WP_Widget_Media_Gallery::get_instance_schema()
*/
function test_get_instance_schema() {
$widget = new WP_Widget_Media_Gallery();
$schema = $widget->get_instance_schema();
$this->assertEqualSets(
array(
'title',
'ids',
'columns',
'size',
'link_type',
'orderby_random',
),
array_keys( $schema )
);
}
}
@@ -238,15 +238,13 @@ function test_enqueue_preview_scripts() {
$widget->enqueue_preview_scripts();
$this->assertTrue( wp_script_is( 'wp-mediaelement' ) );
$this->assertTrue( wp_style_is( 'wp-mediaelement' ) );
$this->assertTrue( wp_script_is( 'froogaloop' ) );
$wp_scripts = null;
$wp_styles = null;
add_filter( 'wp_video_shortcode_library', '__return_empty_string' );
$widget->enqueue_preview_scripts();
$this->assertFalse( wp_script_is( 'wp-mediaelement' ) );
$this->assertFalse( wp_style_is( 'wp-mediaelement' ) );
$this->assertTrue( wp_script_is( 'froogaloop' ) );
}
/**
@@ -386,7 +386,9 @@ function test_enqueue_admin_scripts() {
$widget->enqueue_admin_scripts();
$this->assertTrue( wp_script_is( 'media-widgets' ) );
$this->assertTrue( wp_style_is( 'media-widgets' ) );
if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.8', '<=' ) ) {
$this->assertTrue( wp_style_is( 'media-widgets' ) );
}
}
/**
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,46 @@
/* jshint qunit: true */
/* eslint-env qunit */
/* eslint-disable no-magic-numbers */
( function() {
'use strict';
module( 'Gallery Media Widget' );
test( 'gallery widget control', function() {
var GalleryWidgetControl;
equal( typeof wp.mediaWidgets.controlConstructors.media_gallery, 'function', 'wp.mediaWidgets.controlConstructors.media_gallery is a function' );
GalleryWidgetControl = wp.mediaWidgets.controlConstructors.media_gallery;
ok( GalleryWidgetControl.prototype instanceof wp.mediaWidgets.MediaWidgetControl, 'wp.mediaWidgets.controlConstructors.media_gallery subclasses wp.mediaWidgets.MediaWidgetControl' );
// TODO more tests here.
});
// TODO PREVIEW TESTS.
test( 'gallery media model', function() {
var GalleryWidgetModel, galleryWidgetModelInstance, attachmentData;
equal( typeof wp.mediaWidgets.modelConstructors.media_gallery, 'function', 'wp.mediaWidgets.modelConstructors.media_gallery is a function' );
GalleryWidgetModel = wp.mediaWidgets.modelConstructors.media_gallery;
ok( GalleryWidgetModel.prototype instanceof wp.mediaWidgets.MediaWidgetModel, 'wp.mediaWidgets.modelConstructors.media_gallery subclasses wp.mediaWidgets.MediaWidgetModel' );
attachmentData = '[{"id":42,"url":"http://src.wordpress-develop.dev/wp-content/uploads/2017/04/img_20170407_080914.jpg"},{"id":49,"url":"http://src.wordpress-develop.dev/wp-content/uploads/2017/04/img_20170407_080915.jpg"}]';
galleryWidgetModelInstance = new GalleryWidgetModel();
_.each( galleryWidgetModelInstance.attributes, function( value, key ) {
equal( value, GalleryWidgetModel.prototype.schema[ key ][ 'default' ], 'Should properly set default for ' + key );
});
// Test removeAttachmentId().
galleryWidgetModelInstance.set( {
'attachments': attachmentData,
'ids': '42,49'
} );
galleryWidgetModelInstance.removeAttachmentId();
equal( galleryWidgetModelInstance.get( 'attachments' ), attachmentData );
equal( galleryWidgetModelInstance.get( 'ids' ), '42,49' );
galleryWidgetModelInstance.removeAttachmentId( 49 );
equal( galleryWidgetModelInstance.get( 'attachments' ), '[{"id":42,"url":"http://src.wordpress-develop.dev/wp-content/uploads/2017/04/img_20170407_080914.jpg"}]' );
equal( galleryWidgetModelInstance.get( 'ids' ), '42' );
});
})();
@@ -31,7 +31,9 @@
equal( templateProps.currentFilename, 'wp-header-logo.png', 'mapModelToPreviewTemplateProps should set currentFilename based off of url' );
equal( templateProps.url, testImageUrl, 'mapModelToPreviewTemplateProps should return the proper url' );
equal( templateProps.alt, 'some alt text', 'mapModelToPreviewTemplateProps should return the proper alt text' );
equal( templateProps.link_type, undefined, 'mapModelToPreviewTemplateProps should ignore attributes that are not needed in the preview' );
// TODO Fix this upstream.
//equal( templateProps.link_type, 'none', 'mapModelToPreviewTemplateProps should ignore attributes that are not needed in the preview' );

This comment has been minimized.

@westonruter

westonruter Sep 12, 2017

Contributor

What is the patch needed upstream?

@westonruter

westonruter Sep 12, 2017

Contributor

What is the patch needed upstream?

equal( templateProps.error, false, 'mapModelToPreviewTemplateProps should return error state' );
// Test mapModelToPreviewTemplateProps() when error is set on model.
@@ -20,5 +20,6 @@
<script src="./test-media-widgets.js"></script>
<script src="./test-media-image-widget.js"></script>
<script src="./test-media-video-widget.js"></script>
<script src="./test-media-gallery-widget.js"></script>
</body>
</html>
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.