Making WordPress.org

Changeset 11082


Ignore:
Timestamp:
06/30/2021 06:01:19 PM (4 years ago)
Author:
iandunn
Message:

Patterns API: Test that results are limited to requested locale.

See https://github.com/WordPress/pattern-directory/issues/244

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php

    r10630 r11082  
    1818
    1919        $this->assertSame( 200, $response->status_code );
     20        $this->assertGreaterThan( 0, count( $patterns ) );
    2021        $this->assertIsString( $patterns[0]->title->rendered );
    2122        $this->assertIsInt( $patterns[0]->meta->wpop_viewport_width );
     
    7677     * @covers ::main()
    7778     *
     79     * @dataProvider data_results_limited_to_requested_locale
     80     *
     81     * @group e2e
     82     *
     83     * @param string $locale
     84     */
     85    public function test_results_limited_to_requested_locale( $expected_locale ) : void {
     86        /*
     87         * Use Core patterns since they should always have translated versions.
     88         *
     89         * Fetch 100 to reduce chances of a false-positive/negative due to way results are paginated.
     90         * e.g., the 'none' case may return a mix of locales, but the first page of results may only
     91         * have `en_US` ones.
     92         */
     93        $query_args = '/patterns/1.0/?pattern-keywords=11&per_page=100';
     94
     95        if ( $expected_locale ) {
     96            $query_args .= "&locale=$expected_locale";
     97        }
     98
     99        $response = send_request( $query_args );
     100
     101        $this->assertResponseHasPattern( $response );
     102
     103        $patterns      = json_decode( $response->body );
     104        $found_locales = array_column( $patterns, 'meta' );
     105        $found_locales = array_column( $found_locales, 'wpop_locale' );
     106
     107        $this->assertSame( 200, $response->status_code );
     108
     109        if ( $expected_locale ) {
     110            $this->assertSame( array( $expected_locale ), array_unique( $found_locales ) );
     111        } else {
     112            $this->assertGreaterThan( 1, count( array_unique( $found_locales ) ) );
     113        }
     114    }
     115
     116    public function data_results_limited_to_requested_locale() {
     117        return array(
     118            'none' => array(
     119                'locale' => '',
     120            ),
     121
     122            'american english' => array(
     123                'locale' => 'en_US',
     124            ),
     125
     126            /*
     127             * This is expected to fail until the translated patterns are added to the database.
     128             *
     129             * @link https://github.com/WordPress/pattern-directory/issues/223
     130             * @link https://github.com/WordPress/pattern-directory/issues/224
     131             */
     132            'mexican spanish' => array(
     133                'locale' => 'es_MX',
     134            ),
     135        );
     136    }
     137
     138    /**
     139     * @covers ::main()
     140     *
    78141     * @dataProvider data_search_patterns
    79142     *
Note: See TracChangeset for help on using the changeset viewer.