Make WordPress Core


Ignore:
Timestamp:
05/24/2021 12:24:14 PM (4 years ago)
Author:
SergeyBiryukov
Message:

General: Some documentation and test improvements for the _wp_array_set():

  • Update the function DocBlock per the documentation standards.
  • Move the unit tests to a more appropriate place.
  • Rename and reorder the tests for consistency with _wp_array_get() tests.

Follow-up to [50958], [50962], [50964].

See #53175, #52625.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/wpArraySet.php

    r50964 r50965  
    11<?php
    2 /**
    3  * _wp_array_set.
    4  *
    5  * @package WordPress
    6  */
    72
    83/**
    9  * Test _wp_array_set function.
     4 * Tests for the _wp_array_get() function
    105 *
    11  * @package WordPress
     6 * @since 5.8.0
     7 *
     8 * @group functions.php
     9 * @covers ::_wp_array_get
    1210 */
    13 class WP_Array_Set_Test extends WP_UnitTestCase {
     11class Tests_Functions_wpArraySet extends WP_UnitTestCase {
     12
    1413    /**
    15      * Test _wp_array_set() with simple non subtree path.
     14     * Test _wp_array_set() with invalid parameters.
    1615     *
    1716     * @ticket 53175
    1817     */
    19     public function test_simple_not_subtree_set() {
     18    public function test_wp_array_set_invalid_parameters() {
     19        $test = 3;
     20        _wp_array_set( $test, array( 'a' ), 1 );
     21        $this->assertSame(
     22            $test,
     23            3
     24        );
     25
     26        $test_array = array( 'a' => 2 );
     27        _wp_array_set( $test_array, 'a', 3 );
     28        $this->assertSame(
     29            $test_array,
     30            array( 'a' => 2 )
     31        );
     32
     33        $test_array = array( 'a' => 2 );
     34        _wp_array_set( $test_array, null, 3 );
     35        $this->assertSame(
     36            $test_array,
     37            array( 'a' => 2 )
     38        );
     39
     40        $test_array = array( 'a' => 2 );
     41        _wp_array_set( $test_array, array(), 3 );
     42        $this->assertSame(
     43            $test_array,
     44            array( 'a' => 2 )
     45        );
     46
     47        $test_array = array( 'a' => 2 );
     48        _wp_array_set( $test_array, array( 'a', array() ), 3 );
     49        $this->assertSame(
     50            $test_array,
     51            array( 'a' => 2 )
     52        );
     53    }
     54
     55    /**
     56     * Test _wp_array_set() with simple non-subtree path.
     57     *
     58     * @ticket 53175
     59     */
     60    public function test_wp_array_set_simple_non_subtree() {
    2061        $test_array = array();
    2162        _wp_array_set( $test_array, array( 'a' ), 1 );
     
    4889     * @ticket 53175
    4990     */
    50     public function test_subtree_set() {
     91    public function test_wp_array_set_subtree() {
    5192        $test_array = array();
    5293        _wp_array_set( $test_array, array( 'a', 'b', 'c' ), 1 );
     
    92133        );
    93134    }
    94 
    95     /**
    96      * Test _wp_array_set() with invalid parameters.
    97      *
    98      * @ticket 53175
    99      */
    100     public function test_invalid_parameters_set() {
    101         $test = 3;
    102         _wp_array_set( $test, array( 'a' ), 1 );
    103         $this->assertSame(
    104             $test,
    105             3
    106         );
    107 
    108         $test_array = array( 'a' => 2 );
    109         _wp_array_set( $test_array, 'a', 3 );
    110         $this->assertSame(
    111             $test_array,
    112             array( 'a' => 2 )
    113         );
    114 
    115         $test_array = array( 'a' => 2 );
    116         _wp_array_set( $test_array, null, 3 );
    117         $this->assertSame(
    118             $test_array,
    119             array( 'a' => 2 )
    120         );
    121 
    122         $test_array = array( 'a' => 2 );
    123         _wp_array_set( $test_array, array(), 3 );
    124         $this->assertSame(
    125             $test_array,
    126             array( 'a' => 2 )
    127         );
    128 
    129         $test_array = array( 'a' => 2 );
    130         _wp_array_set( $test_array, array( 'a', array() ), 3 );
    131         $this->assertSame(
    132             $test_array,
    133             array( 'a' => 2 )
    134         );
    135     }
    136135}
Note: See TracChangeset for help on using the changeset viewer.