Make WordPress Core


Ignore:
Timestamp:
08/08/2022 02:38:08 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Improve the test for not throwing a warning on malformed date queries.

  • Make it specifically about wp_resolve_numeric_slug_conflicts(), the function that was throwing an Undefined array key "year" PHP warning for malformed date requests.
  • Move the test under the rewrite component and make its name a bit more descriptive.
  • Check the return result of the function instead of performing a dummy assertion.
  • Use named array keys in the data provider for clarity.
  • Add missing @covers tag.

Follow-up to [32648], [53857].

Props costdev, peterwilsoncc, 1naveengiri, mukesh27, SergeyBiryukov.
See #52252, #45513.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query.php

    r53857 r53861  
    22
    33class Tests_Query extends WP_UnitTestCase {
    4 
    5     /**
    6      * Fixed date post ID.
    7      *
    8      * @var int
    9      */
    10     public static $post_with_date;
    114
    125    public function set_up() {
     
    158        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    169        create_initial_taxonomies();
    17     }
    18 
    19     public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    20         self::$post_with_date = $factory->post->create(
    21             array(
    22                 'post_date' => '2020-01-05 12:00:00',
    23                 'post_name' => 'post-with-date',
    24             )
    25         );
    2610    }
    2711
     
    715699
    716700    /**
    717      * @ticket 52252
    718      * @dataProvider data_malformed_date_queries
    719      *
    720      * @param string $permalink_structure Permalink structure.
    721      * @param array $query_vars Querystring parameteres.
    722      */
    723     public function test_malformed_date_queries( $permalink_structure, $query_vars ) {
    724         $this->set_permalink_structure( $permalink_structure );
    725         $this->go_to( add_query_arg( $query_vars, home_url() ) );
    726 
    727         /*
    728          * Ticket 52252 was to prevent notices from being thrown
    729          * if the date query is malformed.
    730          *
    731          * The test will automatically fail if the function triggers a notice,
    732          * so this dummy assertion is just for accurate stats.
    733          */
    734         $this->assertTrue( true );
    735     }
    736 
    737     /**
    738      * Data provider for test_malformed_date_queries.
    739      *
    740      * @return array Test data.
    741      */
    742     public function data_malformed_date_queries() {
    743         return array(
    744             '/%postname%/ with missing year'         => array(
    745                 '/%postname%/',
    746                 array(
    747                     'monthnum' => 1,
    748                     'day'      => 15,
    749                 ),
    750             ),
    751             '/%postname%/ with month only'           => array(
    752                 '/%postname%/',
    753                 array(
    754                     'monthnum' => 1,
    755                 ),
    756             ),
    757             '/%year%/%postname%/ with missing month' => array(
    758                 '/%year%/%postname%/',
    759                 array(
    760                     'year' => 2020,
    761                     'day'  => 15,
    762                 ),
    763             ),
    764         );
    765     }
    766 
    767     /**
    768701     * @ticket 55100
    769702     */
Note: See TracChangeset for help on using the changeset viewer.