@@ -39,10 +39,10 @@ protected function set_up() {
3939 private function stub_conditionals ( $ true_conditionals = array () ) {
4040 $ wp_conditionals = array (
4141 'is_front_page ' ,
42- 'is_single ' ,
4342 'is_page ' ,
4443 'is_category ' ,
4544 'is_tag ' ,
45+ 'is_tax ' ,
4646 'is_author ' ,
4747 'is_date ' ,
4848 'is_archive ' ,
@@ -55,6 +55,16 @@ private function stub_conditionals( $true_conditionals = array() ) {
5555 Functions \when ( $ func )->justReturn ( $ return );
5656 }
5757
58+ Functions \when ( 'is_singular ' )->alias (
59+ function ( $ post_types = '' ) use ( $ true_conditionals ) {
60+ if ( 'post ' === $ post_types ) {
61+ return in_array ( 'is_singular_post ' , $ true_conditionals , true );
62+ }
63+
64+ return in_array ( 'is_singular ' , $ true_conditionals , true );
65+ }
66+ );
67+
5868 Functions \when ( 'apply_filters ' )->alias ( function () {
5969 $ args = func_get_args ();
6070 return $ args [1 ];
@@ -73,40 +83,56 @@ public function test_detects_home_page() {
7383 * Test detection of single post.
7484 */
7585 public function test_detects_single_post () {
76- $ this ->stub_conditionals ( array ( 'is_single ' ) );
86+ $ this ->stub_conditionals ( array ( 'is_singular_post ' , ' is_singular ' ) );
7787 $ this ->assertSame ( 'post ' , $ this ->detector ->detect () );
7888 }
7989
8090 /**
8191 * Test detection of page.
8292 */
8393 public function test_detects_page () {
84- $ this ->stub_conditionals ( array ( 'is_page ' ) );
94+ $ this ->stub_conditionals ( array ( 'is_page ' , ' is_singular ' ) );
8595 $ this ->assertSame ( 'page ' , $ this ->detector ->detect () );
8696 }
8797
98+ /**
99+ * Test detection of a custom post type.
100+ */
101+ public function test_detects_custom_post () {
102+ $ this ->stub_conditionals ( array ( 'is_singular ' ) );
103+ $ this ->assertSame ( 'custom_post ' , $ this ->detector ->detect () );
104+ }
105+
88106 /**
89107 * Test detection of category archive.
90108 */
91109 public function test_detects_category () {
92110 $ this ->stub_conditionals ( array ( 'is_category ' ) );
93- $ this ->assertSame ( 'category ' , $ this ->detector ->detect () );
111+ $ this ->assertSame ( 'category_archive ' , $ this ->detector ->detect () );
94112 }
95113
96114 /**
97115 * Test detection of tag archive.
98116 */
99117 public function test_detects_tag () {
100118 $ this ->stub_conditionals ( array ( 'is_tag ' ) );
101- $ this ->assertSame ( 'tag ' , $ this ->detector ->detect () );
119+ $ this ->assertSame ( 'tag_archive ' , $ this ->detector ->detect () );
120+ }
121+
122+ /**
123+ * Test detection of a custom taxonomy archive.
124+ */
125+ public function test_detects_taxonomy_archive () {
126+ $ this ->stub_conditionals ( array ( 'is_tax ' ) );
127+ $ this ->assertSame ( 'taxonomy_archive ' , $ this ->detector ->detect () );
102128 }
103129
104130 /**
105131 * Test detection of author archive.
106132 */
107133 public function test_detects_author () {
108134 $ this ->stub_conditionals ( array ( 'is_author ' ) );
109- $ this ->assertSame ( 'author ' , $ this ->detector ->detect () );
135+ $ this ->assertSame ( 'author_archive ' , $ this ->detector ->detect () );
110136 }
111137
112138 /**
@@ -170,8 +196,8 @@ public function test_returns_unknown_when_nothing_matches() {
170196 */
171197 public function test_page_type_filter_is_applied () {
172198 $ wp_conditionals = array (
173- 'is_front_page ' , 'is_single ' , 'is_page ' , 'is_category ' ,
174- 'is_tag ' , 'is_author ' , 'is_date ' , 'is_archive ' , 'is_search ' , 'is_404 ' ,
199+ 'is_front_page ' , 'is_singular ' , 'is_page ' , 'is_category ' ,
200+ 'is_tag ' , 'is_tax ' , ' is_author ' , 'is_date ' , 'is_archive ' , 'is_search ' , 'is_404 ' ,
175201 );
176202 foreach ( $ wp_conditionals as $ func ) {
177203 Functions \when ( $ func )->justReturn ( false );
@@ -197,8 +223,8 @@ public function test_page_type_filter_is_applied() {
197223 private function stub_woocommerce_conditionals ( $ true_conditionals = array () ) {
198224 // Standard WP conditionals - all false.
199225 $ wp_conditionals = array (
200- 'is_front_page ' , 'is_single ' , 'is_page ' , 'is_category ' ,
201- 'is_tag ' , 'is_author ' , 'is_date ' , 'is_archive ' , 'is_search ' , 'is_404 ' ,
226+ 'is_front_page ' , 'is_singular ' , 'is_page ' , 'is_category ' ,
227+ 'is_tag ' , 'is_tax ' , ' is_author ' , 'is_date ' , 'is_archive ' , 'is_search ' , 'is_404 ' ,
202228 );
203229 foreach ( $ wp_conditionals as $ func ) {
204230 Functions \when ( $ func )->justReturn ( false );
@@ -293,9 +319,9 @@ public function test_detects_woocommerce_account() {
293319 * Test WooCommerce types take priority over WP types.
294320 */
295321 public function test_woocommerce_takes_priority_over_wordpress () {
296- $ this ->stub_woocommerce_conditionals ( array ( 'is_product ' , ' is_single ' ) );
297- // is_single would normally return 'post', but WooCommerce product should win.
298- Functions \when ( 'is_single ' )->justReturn ( true );
322+ $ this ->stub_woocommerce_conditionals ( array ( 'is_product ' ) );
323+ // A singular post would normally return 'post', but WooCommerce should win.
324+ Functions \when ( 'is_singular ' )->justReturn ( true );
299325 $ this ->assertSame ( 'product ' , $ this ->detector ->detect () );
300326 }
301327}
0 commit comments