Make WordPress Core

Ticket #22300: 22300-tests.diff

File 22300-tests.diff, 2.6 KB (added by boonebgorges, 11 years ago)

Unit tests, previously in the repo but removed as per #30284.

  • new file tests/phpunit/tests/formatting/MapDeep.php

    diff --git tests/phpunit/tests/formatting/MapDeep.php tests/phpunit/tests/formatting/MapDeep.php
    new file mode 100644
    index 0000000..7ed88fe
    - +  
     1<?php
     2/**
     3 * @group formatting
     4 * @ticket 22300
     5 */
     6class Tests_Formatting_MapDeep extends WP_UnitTestCase {
     7        function setUp() {
     8                if ( ! function_exists( 'map_deep' ) ) {
     9                        $this->markTestSkipped( "map_deep function doesn't exist" );
     10                }
     11
     12                parent::setUp();
     13        }
     14
     15        function test_map_deep_with_any_function_over_empty_array_should_return_empty_array() {
     16                $this->assertEquals( array(), map_deep( array( $this, 'return_baba' ), array() ) );
     17        }
     18
     19        function test_map_deep_should_map_each_element_of_array_one_level_deep() {
     20                $this->assertEquals( array( 'ababa', 'xbaba' ), map_deep( array( $this, 'append_baba' ), array( 'a', 'x' ) ) );
     21        }
     22
     23        function test_map_deep_should_map_each_element_of_array_two_levels_deep() {
     24                $this->assertEquals( array( 'ababa', array( 'xbaba' ) ), map_deep( array( $this, 'append_baba' ), array( 'a', array( 'x' ) ) ) );
     25        }
     26
     27        function test_map_deep_should_map_each_object_element_of_an_array() {
     28                $this->assertEquals( array( 'var0' => 'ababa', 'var1' => (object)array( 'xbaba' ) ),
     29                        map_deep( array( $this, 'append_baba' ), array( 'var0' => 'a', 'var1' => (object)array( 'x' ) ) ) );
     30        }
     31
     32        function test_map_deep_should_apply_the_function_to_a_string() {
     33                $this->assertEquals( 'xbaba', map_deep( array( $this, 'append_baba' ), 'x' ) );
     34        }
     35
     36        function test_map_deep_should_apply_the_function_to_an_integer() {
     37                $this->assertEquals( '5baba' , map_deep( array( $this, 'append_baba' ), 5 ) );
     38        }
     39
     40        function test_map_deep_should_map_each_property_of_an_object() {
     41                $this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => 'xbaba' ),
     42                        map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => 'x' ) ) );
     43        }
     44
     45        function test_map_deep_should_map_each_array_property_of_an_object() {
     46                $this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => array( 'xbaba' ) ),
     47                        map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => array( 'x' ) ) ) );
     48        }
     49
     50        function test_map_deep_should_map_each_object_property_of_an_object() {
     51                $this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => (object)array( 'xbaba' ) ),
     52                        map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => (object)array( 'x' ) ) ) );
     53        }
     54
     55        function return_baba( $value ) {
     56                return 'baba';
     57        }
     58
     59        function append_baba( $value ) {
     60                return $value . 'baba';
     61        }
     62}
     63