| 261 | /* |
| 262 | * Check to make sure we are rendering feed templates for the home feed. |
| 263 | * e.g.) https://example.com/feed/ |
| 264 | * |
| 265 | * @ticket 30210 |
| 266 | */ |
| 267 | function test_valid_home_feed_endpoint() { |
| 268 | // An example of a valid home feed endpoint. |
| 269 | $this->go_to( 'feed/' ); |
| 270 | |
| 271 | // Verify the query object is a feed. |
| 272 | $this->assertQueryTrue( 'is_feed' ); |
| 273 | |
| 274 | // Queries performed on valid feed endpoints should contain posts. |
| 275 | $this->assertTrue( have_posts() ); |
| 276 | |
| 277 | // Check to see if we have the expected XML output from the feed template. |
| 278 | $feed = $this->do_rss2(); |
| 279 | |
| 280 | $xml = xml_to_array( $feed ); |
| 281 | |
| 282 | // Get the <rss> child element of <xml>. |
| 283 | $rss = xml_find( $xml, 'rss' ); |
| 284 | |
| 285 | // There should only be one <rss> child element. |
| 286 | $this->assertEquals( 1, count( $rss ) ); |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Check to make sure we are rendering feed templates for the taxonomy feeds. |
| 291 | * e.g.) https://example.com/category/foo/feed/ |
| 292 | * |
| 293 | * @ticket 30210 |
| 294 | */ |
| 295 | function test_valid_taxonomy_feed_endpoint() { |
| 296 | // An example of an valid taxonomy feed endpoint. |
| 297 | $this->go_to( 'category/foo/feed/' ); |
| 298 | |
| 299 | // Verify the query object is a feed. |
| 300 | $this->assertQueryTrue( 'is_feed', 'is_archive', 'is_category' ); |
| 301 | |
| 302 | // Queries performed on valid feed endpoints should contain posts. |
| 303 | $this->assertTrue( have_posts() ); |
| 304 | |
| 305 | // Check to see if we have the expected XML output from the feed template. |
| 306 | $feed = $this->do_rss2(); |
| 307 | |
| 308 | // Check to see if we have the expected XML output from the feed template. |
| 309 | $xml = xml_to_array( $feed ); |
| 310 | |
| 311 | // Get the <rss> child element of <xml>. |
| 312 | $rss = xml_find( $xml, 'rss' ); |
| 313 | |
| 314 | // There should only be one <rss> child element. |
| 315 | $this->assertEquals( 1, count( $rss ) ); |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Check to make sure we are rendering feed templates for the main comment feed. |
| 320 | * e.g.) https://example.com/comments/feed/ |
| 321 | * |
| 322 | * @ticket 30210 |
| 323 | */ |
| 324 | function test_valid_main_comment_feed_endpoint() { |
| 325 | // Assign a category to those posts |
| 326 | foreach ( self::$posts as $post ) { |
| 327 | self::factory()->comment->create_post_comments( $post, 3 ); |
| 328 | } |
| 329 | |
| 330 | // An example of an valid main comment feed endpoint. |
| 331 | $this->go_to( 'comments/feed/' ); |
| 332 | |
| 333 | // Verify the query object is a feed. |
| 334 | $this->assertQueryTrue( 'is_feed', 'is_comment_feed' ); |
| 335 | |
| 336 | // Queries performed on valid feed endpoints should contain comments. |
| 337 | $this->assertTrue( have_comments() ); |
| 338 | |
| 339 | // Check to see if we have the expected XML output from the feed template. |
| 340 | $feed = $this->do_rss2(); |
| 341 | |
| 342 | // Check to see if we have the expected XML output from the feed template. |
| 343 | $xml = xml_to_array( $feed ); |
| 344 | |
| 345 | // Get the <rss> child element of <xml>. |
| 346 | $rss = xml_find( $xml, 'rss' ); |
| 347 | |
| 348 | // There should only be one <rss> child element. |
| 349 | $this->assertEquals( 1, count( $rss ) ); |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * Check to make sure we are rendering feed templates for the date archive feeds. |
| 354 | * e.g.) https://example.com/2003/05/27/feed/ |
| 355 | * |
| 356 | * @ticket 30210 |
| 357 | */ |
| 358 | function test_valid_archive_feed_endpoint() { |
| 359 | // An example of an valid date archive feed endpoint. |
| 360 | $this->go_to( '2003/05/27/feed/' ); |
| 361 | |
| 362 | // Verify the query object is a feed. |
| 363 | $this->assertQueryTrue( 'is_feed', 'is_archive', 'is_day', 'is_date' ); |
| 364 | |
| 365 | // Queries performed on valid feed endpoints should contain posts. |
| 366 | $this->assertTrue( have_posts() ); |
| 367 | |
| 368 | // Check to see if we have the expected XML output from the feed template. |
| 369 | $feed = $this->do_rss2(); |
| 370 | |
| 371 | // Check to see if we have the expected XML output from the feed template. |
| 372 | $xml = xml_to_array( $feed ); |
| 373 | |
| 374 | // Get the <rss> child element of <xml>. |
| 375 | $rss = xml_find( $xml, 'rss' ); |
| 376 | |
| 377 | // There should only be one <rss> child element. |
| 378 | $this->assertEquals( 1, count( $rss ) ); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | /* |
| 383 | * Check to make sure we are rendering feed templates for the search archive feeds. |
| 384 | * e.g.) https://example.com/?s=Lorem&feed=rss |
| 385 | * |
| 386 | * @ticket 30210 |
| 387 | */ |
| 388 | function test_valid_search_feed_endpoint() { |
| 389 | // An example of an valid search feed endpoint |
| 390 | $this->go_to( '?s=Lorem&feed=rss' ); |
| 391 | |
| 392 | // Verify the query object is a feed. |
| 393 | $this->assertQueryTrue( 'is_feed', 'is_search' ); |
| 394 | |
| 395 | // Queries performed on valid feed endpoints should contain posts. |
| 396 | $this->assertTrue( have_posts() ); |
| 397 | |
| 398 | // Check to see if we have the expected XML output from the feed template. |
| 399 | $feed = $this->do_rss2(); |
| 400 | |
| 401 | // Check to see if we have the expected XML output from the feed template. |
| 402 | $xml = xml_to_array( $feed ); |
| 403 | |
| 404 | // Get the <rss> child element of <xml>. |
| 405 | $rss = xml_find( $xml, 'rss' ); |
| 406 | |
| 407 | // There should only be one <rss> child element. |
| 408 | $this->assertEquals( 1, count( $rss ) ); |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * Check to make sure we are not rendering feed templates for invalid feed endpoints. |
| 413 | * e.g.) https://example.com/wp-content/feed/ |
| 414 | * |
| 415 | * @ticket 30210 |
| 416 | */ |
| 417 | function test_invalid_feed_endpoint() { |
| 418 | // An example of an invalid feed endpoint |
| 419 | $this->go_to( 'wp-content/feed/' ); |
| 420 | |
| 421 | // Queries performed on invalid feed endpoints should never contain posts. |
| 422 | $this->assertFalse( have_posts() ); |
| 423 | |
| 424 | // This is the assertion. Once the exception is thrown in do_feed, execution stops, preventing futher assertions. |
| 425 | $this->setExpectedException( 'WPDieException', 'ERROR: This is not a valid feed.' ); |
| 426 | do_feed(); |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Make sure the requested feed is registered before rendering the requested template. |
| 431 | * |
| 432 | * @ticket 30210 |
| 433 | */ |
| 434 | function test_nonexistent_feeds() { |
| 435 | global $wp_rewrite; |
| 436 | $feedname = 'badfeed'; |
| 437 | |
| 438 | // Unregister the feed if it exists |
| 439 | if ( in_array( $feedname, $wp_rewrite->feeds ) ) { |
| 440 | unset( $wp_rewrite->feeds->feedname ); |
| 441 | $hook = 'do_feed_' . $feedname; |
| 442 | // Remove default function hook |
| 443 | remove_action( $hook, $hook ); |
| 444 | } |
| 445 | |
| 446 | $this->go_to( '/?feed=' . $feedname ); |
| 447 | |
| 448 | // This is the assertion. Once the exception is thrown in do_feed, execution stops, preventing futher assertions. |
| 449 | $this->setExpectedException( 'WPDieException', 'ERROR: This is not a valid feed template.' ); |
| 450 | do_feed(); |
| 451 | } |
| 452 | |