Make WordPress Core

Ticket #30522: 30522.diff

File 30522.diff, 6.3 KB (added by pento, 10 years ago)
  • tests/phpunit/includes/testcase.php

     
    262262        }
    263263
    264264        function assertEqualSets( $expected, $actual ) {
    265                 $this->assertEquals( array(), array_diff( $expected, $actual ) );
    266                 $this->assertEquals( array(), array_diff( $actual, $expected ) );
     265                sort( $expected );
     266                sort( $actual );
     267                $this->assertEquals( $expected, $actual );
    267268        }
    268269
     270        function assertEqualSetsWithIndex( $expected, $actual ) {
     271                ksort( $expected );
     272                ksort( $actual );
     273                $this->assertEquals( $expected, $actual );
     274        }
     275
    269276        function go_to( $url ) {
    270277                // note: the WP and WP_Query classes like to silently fetch parameters
    271278                // from all over the place (globals, GET, etc), which makes it tricky
  • tests/phpunit/tests/testhelpers.php

     
     1<?php
     2
     3/**
     4 * @group phpunit
     5 */
     6class Tests_TestHelpers extends WP_UnitTestCase {
     7        /**
     8         * @ticket 30522
     9         */
     10        function test_ordered_equal_sets() {
     11                $this->assertEqualSets( array( 1, 2, 3 ), array( 1, 2, 3 ) );
     12        }
     13
     14        /**
     15         * @ticket 30522
     16         */
     17        function test_unordered_equal_sets() {
     18                $this->assertEqualSets( array( 1, 2, 3 ), array( 2, 3, 1 ) );
     19        }
     20
     21        /**
     22         * @ticket 30522
     23         */
     24        function test_ordered_unequal_sets() {
     25                $passed = true;
     26                try {
     27                        $this->assertEqualSets( array( 1, 2, 3 ), array( 1, 2, 3, 4 ) );
     28                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     29                        // assertEqualSets failed, as we want it to
     30                        $passed = false;
     31                }
     32
     33                try {
     34                        $this->assertEqualSets( array( 1, 2, 3, 4 ), array( 1, 2, 3 ) );
     35                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     36                        $passed = false;
     37                }
     38
     39                if ( $passed ) {
     40                        $this->fail();
     41                }
     42        }
     43
     44        /**
     45         * @ticket 30522
     46         */
     47        function test_unordered_unequal_sets() {
     48                try {
     49                        $this->assertEqualSets( array( 1, 2, 3 ), array( 3, 4, 2, 1 ) );
     50                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     51                        return;
     52                }
     53
     54                $this->fail();
     55        }
     56
     57        /**
     58         * @ticket 30522
     59         */
     60        function test_ordered_sets_with_repeated_values() {
     61                try {
     62                        $this->assertEqualSets( array( 1, 2, 3 ), array( 1, 2, 3, 3 ) );
     63                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     64                        return;
     65                }
     66
     67                $this->fail();
     68        }
     69
     70        /**
     71         * @ticket 30522
     72         */
     73        function test_unordered_sets_with_repeated_values() {
     74                try {
     75                        $this->assertEqualSets( array( 1, 2, 3 ), array( 2, 3, 1, 3 ) );
     76                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     77                        return;
     78                }
     79
     80                $this->fail();
     81        }
     82
     83        /**
     84         * @ticket 30522
     85         */
     86        function test_ordered_equal_sets_with_index() {
     87                $this->assertEqualSetsWithIndex( array( 1, 2, 3 ), array( 1, 2, 3 ) );
     88                $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3 ), array( 'a' => 1, 'b' => 2, 'c' => 3 ) );
     89        }
     90
     91        /**
     92         * @ticket 30522
     93         */
     94        function test_unordered_equal_sets_with_index() {
     95                $passed = true;
     96                try {
     97                        $this->assertEqualSetsWithIndex( array( 1, 2, 3 ), array( 2, 3, 1 ) );
     98                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     99                        $passed = false;
     100                }
     101
     102                $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3 ), array( 'b' => 2, 'c' => 3, 'a' => 1 ) );
     103
     104                if ( $passed ) {
     105                        $this->fail();
     106                }
     107        }
     108
     109        /**
     110         * @ticket 30522
     111         */
     112        function test_ordered_unequal_sets_with_index() {
     113                $passed = true;
     114                try {
     115                        $this->assertEqualSetsWithIndex( array( 1, 2, 3 ), array( 1, 2, 3, 4 ) );
     116                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     117                        $passed = false;
     118                }
     119
     120                try {
     121                        $this->assertEqualSetsWithIndex( array( 1, 2, 3, 4 ), array( 1, 2, 3 ) );
     122                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     123                        $passed = false;
     124                }
     125                try {
     126                        $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3 ), array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 ) );
     127                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     128                        $passed = false;
     129                }
     130
     131                try {
     132                        $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 ), array( 'a' => 1, 'b' => 2, 'c' => 3 ) );
     133                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     134                        $passed = false;
     135                }
     136
     137                if ( $passed ) {
     138                        $this->fail();
     139                }
     140        }
     141
     142        /**
     143         * @ticket 30522
     144         */
     145        function test_unordered_unequal_sets_with_index() {
     146                $passed = true;
     147                try {
     148                        $this->assertEqualSetsWithIndex( array( 1, 2, 3 ), array( 3, 4, 2, 1 ) );
     149                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     150                        $passed = false;
     151                }
     152                try {
     153                        $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3 ), array( 'c' => 3, 'b' => 2, 'd' => 4, 'a' => 1 ) );
     154                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     155                        $passed = false;
     156                }
     157
     158                if ( $passed ) {
     159                        $this->fail();
     160                }
     161        }
     162
     163        /**
     164         * @ticket 30522
     165         */
     166        function test_ordered_sets_with_repeated_values_with_index() {
     167                $passed = true;
     168                try {
     169                        $this->assertEqualSetsWithIndex( array( 1, 2, 3 ), array( 1, 2, 3, 3 ) );
     170                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     171                        $passed = false;
     172                }
     173                try {
     174                        $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3 ), array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 3 ) );
     175                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     176                        $passed = false;
     177                }
     178
     179                if ( $passed ) {
     180                        $this->fail();
     181                }
     182        }
     183
     184        /**
     185         * @ticket 30522
     186         */
     187        function test_unordered_sets_with_repeated_values_with_index() {
     188                $passed = true;
     189                try {
     190                        $this->assertEqualSetsWithIndex( array( 1, 2, 3 ), array( 2, 3, 1, 3 ) );
     191                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     192                        $passed = false;
     193                }
     194                try {
     195                        $this->assertEqualSetsWithIndex( array( 'a' => 1, 'b' => 2, 'c' => 3 ), array( 'c' => 3, 'b' => 2, 'd' => 3, 'a' => 1 ) );
     196                } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
     197                        $passed = false;
     198                }
     199
     200                if ( $passed ) {
     201                        $this->fail();
     202                }
     203        }
     204}