mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-06 12:51:58 +00:00
Check bad dates and redirect, instead of 404ing, as necessary and appropriate.
Adds query, conditional, and canonical Unit Tests. Props kovshenin, SergeyBiryukov, DrewAPicture. Fixes #10935. git-svn-id: https://develop.svn.wordpress.org/trunk@25280 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -239,6 +239,9 @@ class Tests_Canonical extends WP_UnitTestCase {
|
||||
|
||||
array( '/?year=2008', '/2008/'),
|
||||
|
||||
array( '/2012/13/', '/2012/'),
|
||||
array( '/2012/11/51/', '/2012/11/'),
|
||||
|
||||
// Authors
|
||||
array( '/?author=%d', '/author/canonical-author/' ),
|
||||
// array( '/?author=%d&year=2008', '/2008/?author=3'),
|
||||
|
||||
@@ -629,4 +629,12 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
|
||||
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
|
||||
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
|
||||
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
|
||||
|
||||
function test_bad_dates() {
|
||||
$this->go_to( '/2013/13/13/' );
|
||||
$this->assertQueryTrue( 'is_404' );
|
||||
|
||||
$this->go_to( '/2013/11/41/' );
|
||||
$this->assertQueryTrue( 'is_404' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,4 +486,51 @@ class Tests_Query_Results extends WP_UnitTestCase {
|
||||
$author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) );
|
||||
$this->assertEqualSets( array( $author_1 ), $author_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 10935
|
||||
*/
|
||||
function test_query_is_date() {
|
||||
$this->q->query( array(
|
||||
'year' => '2007',
|
||||
'monthnum' => '01',
|
||||
'day' => '01',
|
||||
) );
|
||||
|
||||
$this->assertTrue( $this->q->is_date );
|
||||
$this->assertTrue( $this->q->is_day );
|
||||
$this->assertFalse( $this->q->is_month );
|
||||
$this->assertFalse( $this->q->is_year );
|
||||
|
||||
$this->q->query( array(
|
||||
'year' => '2007',
|
||||
'monthnum' => '01',
|
||||
) );
|
||||
|
||||
$this->assertTrue( $this->q->is_date );
|
||||
$this->assertFalse( $this->q->is_day );
|
||||
$this->assertTrue( $this->q->is_month );
|
||||
$this->assertFalse( $this->q->is_year );
|
||||
|
||||
$this->q->query( array(
|
||||
'year' => '2007',
|
||||
) );
|
||||
|
||||
$this->assertTrue( $this->q->is_date );
|
||||
$this->assertFalse( $this->q->is_day );
|
||||
$this->assertFalse( $this->q->is_month );
|
||||
$this->assertTrue( $this->q->is_year );
|
||||
|
||||
$this->q->query( array(
|
||||
'year' => '2007',
|
||||
'monthnum' => '01',
|
||||
'day' => '50',
|
||||
) );
|
||||
|
||||
$this->assertTrue( $this->q->is_404 );
|
||||
$this->assertFalse( $this->q->is_date );
|
||||
$this->assertFalse( $this->q->is_day );
|
||||
$this->assertFalse( $this->q->is_month );
|
||||
$this->assertFalse( $this->q->is_year );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user