WordPress.org

Make WordPress Core

Ticket #34699: 34699-unit-tests.diff

File 34699-unit-tests.diff, 1.2 KB (added by andizer, 3 years ago)

Unit tests

  • new file tests/phpunit/tests/functions/getQueryArg.php

    diff --git tests/phpunit/tests/functions/getQueryArg.php tests/phpunit/tests/functions/getQueryArg.php
    new file mode 100644
    index 000000000..6f9a8952f
    - +  
     1<?php
     2/**
     3 * @group functions.php
     4 */
     5class Tests_Functions_GetQueryArg extends WP_UnitTestCase {
     6
     7        /**
     8         * @ticket 34699
     9         */
     10        public function test_get_query_arg() {
     11                $this->assertSame( 'value2', get_query_arg( 'param2', '?param=test&param2=value2' ) );
     12                $this->assertNotSame( 'value2', get_query_arg( 'param3', '?param=test&param2=value2&param3=value3' ) );
     13
     14                // When the key is an array
     15                $this->assertEquals(
     16                        array( 'param2' => 'value2', 'param3' => 'value3', 'param4' => null ),
     17                        get_query_arg( array( 'param2', 'param3', 'param4' ), '?param=test&param2=value2&param3=value3' )
     18                );
     19
     20                // When arg doesn't exists.
     21                $this->assertNull( get_query_arg( 'param2', '?param=test' ) );
     22
     23                // When no query is present.
     24                $this->assertSame( array( 'param' => null ), get_query_arg( array( 'param' ), '' ) );
     25                $this->assertNull( get_query_arg( 'value', '' ) );
     26
     27                // Fallback on REQUEST_URI.
     28                $this->assertNull( get_query_arg( 'param' ) );
     29        }
     30
     31}
     32 No newline at end of file