|
16 | 16 |
|
17 | 17 | $compiled = $this->compile($directive); |
18 | 18 |
|
19 | | - expect($compiled)->toBe("<?php if (empty(\$query)) : ?><?php global \$wp_query; ?><?php \$query = \$wp_query; ?><?php endif; ?> <?php if (\$query->have_posts()) : ?><?php \$__currentLoopData = range(1, \$query->post_count); \$__env->addLoop(\$__currentLoopData); while (\$query->have_posts()) : \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); \$query->the_post(); ?>"); |
| 19 | + expect($compiled)->toBe('<?php if (empty($query)) : ?><?php global $wp_query; ?><?php $query = $wp_query; ?><?php endif; ?> <?php if ($query->have_posts()) : ?><?php $__currentLoopData = range(1, $query->post_count); $__env->addLoop($__currentLoopData); while ($query->have_posts()) : $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $query->the_post(); ?>'); |
20 | 20 | }); |
21 | 21 |
|
22 | 22 | it('compiles correctly with post ID', function () { |
23 | | - $directive = "@posts(1)"; |
| 23 | + $directive = '@posts(1)'; |
24 | 24 |
|
25 | 25 | $compiled = $this->compile($directive); |
26 | 26 |
|
27 | 27 | expect($compiled)->toBe("<?php \$posts = collect(); ?><?php if (is_a(1, 'WP_Post') || is_numeric(1)) : ?><?php \$posts->put('p', is_a(1, 'WP_Post') ? (1)->ID : 1); ?><?php endif; ?><?php if (is_array(1)) : ?><?php \$posts ->put('ignore_sticky_posts', true) ->put('posts_per_page', -1) ->put('post__in', collect(1) ->map(function (\$post) { return is_a(\$post, 'WP_Post') ? \$post->ID : \$post; })->all()) ->put('orderby', 'post__in'); ?><?php endif; ?><?php \$query = \$posts->isNotEmpty() ? new WP_Query(\$posts->all()) : 1; ?><?php if (\$query->have_posts()) : \$__currentLoopData = range(1, \$query->post_count); \$__env->addLoop(\$__currentLoopData); while (\$query->have_posts()) : \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); \$query->the_post(); ?>"); |
28 | 28 | }); |
29 | 29 |
|
| 30 | + it('compiles correctly with post object', function () { |
| 31 | + $directive = '@posts(get_post(1))'; |
| 32 | + |
| 33 | + $compiled = $this->compile($directive); |
| 34 | + |
| 35 | + expect($compiled)->toBe("<?php \$posts = collect(); ?><?php if (is_a(get_post(1), 'WP_Post') || is_numeric(get_post(1))) : ?><?php \$posts->put('p', is_a(get_post(1), 'WP_Post') ? (get_post(1))->ID : get_post(1)); ?><?php endif; ?><?php if (is_array(get_post(1))) : ?><?php \$posts ->put('ignore_sticky_posts', true) ->put('posts_per_page', -1) ->put('post__in', collect(get_post(1)) ->map(function (\$post) { return is_a(\$post, 'WP_Post') ? \$post->ID : \$post; })->all()) ->put('orderby', 'post__in'); ?><?php endif; ?><?php \$query = \$posts->isNotEmpty() ? new WP_Query(\$posts->all()) : get_post(1); ?><?php if (\$query->have_posts()) : \$__currentLoopData = range(1, \$query->post_count); \$__env->addLoop(\$__currentLoopData); while (\$query->have_posts()) : \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); \$query->the_post(); ?>"); |
| 36 | + }); |
| 37 | + |
30 | 38 | it('compiles correctly with post ID array', function () { |
31 | | - $directive = "@posts([1, 2, 3])"; |
| 39 | + $directive = '@posts([1, 2, 3])'; |
32 | 40 |
|
33 | 41 | $compiled = $this->compile($directive); |
34 | 42 |
|
35 | 43 | expect($compiled)->toBe("<?php \$posts = collect(); ?><?php if (is_a([1, 2, 3], 'WP_Post') || is_numeric([1, 2, 3])) : ?><?php \$posts->put('p', is_a([1, 2, 3], 'WP_Post') ? ([1, 2, 3])->ID : [1, 2, 3]); ?><?php endif; ?><?php if (is_array([1, 2, 3])) : ?><?php \$posts ->put('ignore_sticky_posts', true) ->put('posts_per_page', -1) ->put('post__in', collect([1, 2, 3]) ->map(function (\$post) { return is_a(\$post, 'WP_Post') ? \$post->ID : \$post; })->all()) ->put('orderby', 'post__in'); ?><?php endif; ?><?php \$query = \$posts->isNotEmpty() ? new WP_Query(\$posts->all()) : [1, 2, 3]; ?><?php if (\$query->have_posts()) : \$__currentLoopData = range(1, \$query->post_count); \$__env->addLoop(\$__currentLoopData); while (\$query->have_posts()) : \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); \$query->the_post(); ?>"); |
36 | 44 | }); |
| 45 | + |
| 46 | + it('compiles correctly with post ID array containing object', function () { |
| 47 | + $directive = '@posts([1, get_post(2), 3])'; |
| 48 | + |
| 49 | + $compiled = $this->compile($directive); |
| 50 | + |
| 51 | + expect($compiled)->toBe("<?php \$posts = collect(); ?><?php if (is_a([1, get_post(2), 3], 'WP_Post') || is_numeric([1, get_post(2), 3])) : ?><?php \$posts->put('p', is_a([1, get_post(2), 3], 'WP_Post') ? ([1, get_post(2), 3])->ID : [1, get_post(2), 3]); ?><?php endif; ?><?php if (is_array([1, get_post(2), 3])) : ?><?php \$posts ->put('ignore_sticky_posts', true) ->put('posts_per_page', -1) ->put('post__in', collect([1, get_post(2), 3]) ->map(function (\$post) { return is_a(\$post, 'WP_Post') ? \$post->ID : \$post; })->all()) ->put('orderby', 'post__in'); ?><?php endif; ?><?php \$query = \$posts->isNotEmpty() ? new WP_Query(\$posts->all()) : [1, get_post(2), 3]; ?><?php if (\$query->have_posts()) : \$__currentLoopData = range(1, \$query->post_count); \$__env->addLoop(\$__currentLoopData); while (\$query->have_posts()) : \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); \$query->the_post(); ?>"); |
| 52 | + }); |
37 | 53 | }); |
38 | 54 |
|
39 | 55 | describe('@endposts', function () { |
|
0 commit comments