@@ -3808,6 +3808,178 @@ public function test_gallery_shortcode_when_is_feed_true() {
38083808 $ this ->assertStringNotContainsString ( '<a ' , $ actual );
38093809 }
38103810
3811+ /**
3812+ * @ticket 12799
3813+ *
3814+ * @dataProvider data_gallery_shortcode_limit
3815+ */
3816+ public function test_gallery_shortcode_limit ( $ limit , $ expected_count ) {
3817+ $ post_id = self ::factory ()->post ->create (
3818+ array (
3819+ 'post_status ' => 'publish ' ,
3820+ )
3821+ );
3822+
3823+ $ attachment_ids = array ();
3824+ for ( $ i = 0 ; $ i < 5 ; $ i ++ ) {
3825+ $ attachment_ids [] = self ::factory ()->attachment ->create_object (
3826+ array (
3827+ 'post_parent ' => $ post_id ,
3828+ 'post_status ' => 'inherit ' ,
3829+ 'post_type ' => 'attachment ' ,
3830+ 'post_mime_type ' => 'image/jpeg ' ,
3831+ )
3832+ );
3833+ }
3834+
3835+ $ actual = gallery_shortcode (
3836+ array (
3837+ 'id ' => $ post_id ,
3838+ 'limit ' => $ limit ,
3839+ )
3840+ );
3841+
3842+ $ count = substr_count ( $ actual , '<figure ' ) + substr_count ( $ actual , '<dl ' );
3843+ $ this ->assertSame ( $ expected_count , $ count );
3844+ }
3845+
3846+ /**
3847+ * @ticket 12799
3848+ */
3849+ public function test_gallery_shortcode_limit_with_ids () {
3850+ $ attachment_ids = array ();
3851+ for ( $ i = 0 ; $ i < 5 ; $ i ++ ) {
3852+ $ attachment_ids [] = self ::factory ()->attachment ->create_object (
3853+ array (
3854+ 'post_status ' => 'inherit ' ,
3855+ 'post_type ' => 'attachment ' ,
3856+ 'post_mime_type ' => 'image/jpeg ' ,
3857+ )
3858+ );
3859+ }
3860+
3861+ $ actual = gallery_shortcode (
3862+ array (
3863+ 'ids ' => implode ( ', ' , $ attachment_ids ),
3864+ 'limit ' => 2 ,
3865+ )
3866+ );
3867+
3868+ $ count = substr_count ( $ actual , '<figure ' ) + substr_count ( $ actual , '<dl ' );
3869+ $ this ->assertSame ( 2 , $ count );
3870+ }
3871+
3872+ /**
3873+ * @ticket 12799
3874+ */
3875+ public function test_gallery_shortcode_limit_with_include () {
3876+ $ post_id = self ::factory ()->post ->create (
3877+ array (
3878+ 'post_status ' => 'publish ' ,
3879+ )
3880+ );
3881+
3882+ $ attachment_ids = array ();
3883+ for ( $ i = 0 ; $ i < 5 ; $ i ++ ) {
3884+ $ attachment_ids [] = self ::factory ()->attachment ->create_object (
3885+ array (
3886+ 'post_parent ' => $ post_id ,
3887+ 'post_status ' => 'inherit ' ,
3888+ 'post_type ' => 'attachment ' ,
3889+ 'post_mime_type ' => 'image/jpeg ' ,
3890+ )
3891+ );
3892+ }
3893+
3894+ $ actual = gallery_shortcode (
3895+ array (
3896+ 'id ' => $ post_id ,
3897+ 'include ' => implode ( ', ' , $ attachment_ids ),
3898+ 'limit ' => 3 ,
3899+ )
3900+ );
3901+
3902+ $ count = substr_count ( $ actual , '<figure ' ) + substr_count ( $ actual , '<dl ' );
3903+ $ this ->assertSame ( 3 , $ count );
3904+ }
3905+
3906+ /**
3907+ * @ticket 12799
3908+ */
3909+ public function test_gallery_shortcode_limit_with_exclude () {
3910+ $ post_id = self ::factory ()->post ->create (
3911+ array (
3912+ 'post_status ' => 'publish ' ,
3913+ )
3914+ );
3915+
3916+ $ attachment_ids = array ();
3917+ for ( $ i = 0 ; $ i < 5 ; $ i ++ ) {
3918+ $ attachment_ids [] = self ::factory ()->attachment ->create_object (
3919+ array (
3920+ 'post_parent ' => $ post_id ,
3921+ 'post_status ' => 'inherit ' ,
3922+ 'post_type ' => 'attachment ' ,
3923+ 'post_mime_type ' => 'image/jpeg ' ,
3924+ )
3925+ );
3926+ }
3927+
3928+ $ actual = gallery_shortcode (
3929+ array (
3930+ 'id ' => $ post_id ,
3931+ 'exclude ' => $ attachment_ids [0 ],
3932+ 'limit ' => 2 ,
3933+ )
3934+ );
3935+
3936+ $ count = substr_count ( $ actual , '<figure ' ) + substr_count ( $ actual , '<dl ' );
3937+ $ this ->assertSame ( 2 , $ count );
3938+ }
3939+
3940+ /**
3941+ * @ticket 12799
3942+ */
3943+ public function test_gallery_shortcode_limit_with_orderby_rand () {
3944+ $ post_id = self ::factory ()->post ->create (
3945+ array (
3946+ 'post_status ' => 'publish ' ,
3947+ )
3948+ );
3949+
3950+ for ( $ i = 0 ; $ i < 5 ; $ i ++ ) {
3951+ self ::factory ()->attachment ->create_object (
3952+ array (
3953+ 'post_parent ' => $ post_id ,
3954+ 'post_status ' => 'inherit ' ,
3955+ 'post_type ' => 'attachment ' ,
3956+ 'post_mime_type ' => 'image/jpeg ' ,
3957+ )
3958+ );
3959+ }
3960+
3961+ $ actual = gallery_shortcode (
3962+ array (
3963+ 'id ' => $ post_id ,
3964+ 'limit ' => 2 ,
3965+ 'orderby ' => 'rand ' ,
3966+ )
3967+ );
3968+
3969+ $ count = substr_count ( $ actual , '<figure ' ) + substr_count ( $ actual , '<dl ' );
3970+ $ this ->assertSame ( 2 , $ count );
3971+ }
3972+
3973+ public static function data_gallery_shortcode_limit () {
3974+ return array (
3975+ 'default no limit ' => array ( -1 , 5 ),
3976+ 'zero means no limit ' => array ( 0 , 5 ),
3977+ 'limit of 2 ' => array ( 2 , 2 ),
3978+ 'limit of 5 same as total ' => array ( 5 , 5 ),
3979+ 'limit greater than total ' => array ( 10 , 5 ),
3980+ );
3981+ }
3982+
38113983 /**
38123984 * Test attachment permalinks based on parent post status.
38133985 *
0 commit comments