Make WordPress Core

Changeset 47338


Ignore:
Timestamp:
02/21/2020 01:05:39 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Fix the Travis CI build for the 3.8 branch.

Among other fixes, this backports [26871], [26909-26910], [26940], [27086], [27168], [28799], [28873], [28943], [28961], [28964], [28966-28967], [29120], [29251], [29503], [29860], [29869], [29954], [30001], [30160], [30282], [30285], [30289-30291], [30513-30514], [30516-30521], [30524], [30526], [30529-30530], [31253-31254], [31257-31259], [31622], [40241], [40255], [40257], [40259], [40269], [40271], [40446], [40449], [40457], [40604], [40538], [40833], [41082], [41303], [41306], [44993].

See #49485.

Location:
branches/3.8
Files:
1 added
7 deleted
57 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

  • branches/3.8/.travis.yml

    r40625 r47338  
     1# Travis CI Configuration File
     2sudo: false
     3dist: trusty
    14language: php
     5cache:
     6  directories:
     7    - $HOME/.npm
     8    - vendor
     9    - $HOME/.composer/cache
    210
    3 php:
    4     - "5.5"
    5     - "5.2"
     11# Build matrix options
     12matrix:
     13  include:
     14    - php: 5.5
     15      env: WP_TRAVISCI=travis:js
     16    - php: 5.5
     17      env: WP_TRAVISCI=travis:phpunit
     18    - php: 5.2
     19      env: WP_TRAVISCI=travis:phpunit
     20      dist: precise
     21  fast_finish: true
    622
     23# Before install, failures in this section will result in build status 'errored'
     24before_install:
     25  - WP_CORE_DIR=/tmp/wordpress/
     26  - >
     27    if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
     28        mysql -e "CREATE DATABASE wordpress_tests;" -uroot
     29        cp wp-tests-config-sample.php wp-tests-config.php
     30        sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
     31        sed -i "s/yourusernamehere/travis/" wp-tests-config.php
     32        sed -i "s/yourpasswordhere//" wp-tests-config.php
     33        svn checkout https://plugins.svn.wordpress.org/wordpress-importer/trunk tests/phpunit/data/plugins/wordpress-importer
     34    fi
     35
     36# Before script, failures in this section will result in build status 'failed'
    737before_script:
    8     - |
    9       stable='^[0-9\.]+$';
    10       if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then
    11           phpenv config-rm xdebug.ini
    12       fi
    13     - mysql -e "CREATE DATABASE wordpress_tests;" -uroot
    14     - cp wp-tests-config-sample.php wp-tests-config.php
    15     - sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
    16     - sed -i "s/yourusernamehere/travis/" wp-tests-config.php
    17     - sed -i "s/yourpasswordhere//" wp-tests-config.php
    18     - svn checkout https://plugins.svn.wordpress.org/wordpress-importer/trunk tests/phpunit/data/plugins/wordpress-importer
    19     - npm install -g grunt-cli
    20     - npm install
    21     - php --version
    22 
    23 script: grunt test
     38- |
     39  # Remove Xdebug for a huge performance increase, but not from nightly:
     40  stable='^[0-9\.]+$'
     41  if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then
     42    phpenv config-rm xdebug.ini
     43  fi
     44- |
     45  # Export Composer's global bin dir to PATH, but not on PHP 5.2:
     46  if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then
     47    composer config --list --global
     48    export PATH=`composer config --list --global | grep '\[home\]' | { read a; echo "${a#* }/vendor/bin:$PATH"; }`
     49  fi
     50- |
     51  # Install the specified version of PHPUnit depending on the PHP version:
     52  if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
     53    case "$TRAVIS_PHP_VERSION" in
     54      7.1|7.0|nightly)
     55        echo "Using PHPUnit 5.x"
     56        composer global require "phpunit/phpunit:^5"
     57        ;;
     58      5.6|5.5|5.4|5.3)
     59        echo "Using PHPUnit 4.x"
     60        composer global require "phpunit/phpunit:^4"
     61        ;;
     62      5.2)
     63        # Do nothing, use default PHPUnit 3.6.x
     64        echo "Using default PHPUnit, hopefully 3.6"
     65        ;;
     66      *)
     67        echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION"
     68        exit 1
     69        ;;
     70    esac
     71  fi
     72- npm --version
     73- node --version
     74- nvm install 0.10.48
     75- npm install -g grunt-cli
     76- npm install
     77- npm prune
     78- php --version
     79- php -m
     80- npm --version
     81- node --version
     82- which phpunit
     83- phpunit --version
     84- curl --version
     85- grunt --version
     86- git --version
     87- svn --version
     88script: grunt $WP_TRAVISCI
    2489notifications:
    2590  slack:
     
    2994    on_failure: always
    3095    on_success: change
    31     on_pull_requests: false
  • branches/3.8/Gruntfile.js

    r26771 r47338  
    360360    // Register tasks.
    361361
     362    // RTL task.
     363    grunt.registerTask('rtl', ['cssjanus:core', 'cssjanus:colors']);
     364
     365    // Color schemes task.
     366    grunt.registerTask('colors', ['sass:colors']);
     367
     368    // JSHint task.
     369    grunt.registerTask('jshint:corejs', ['jshint:grunt', 'jshint:tests', 'jshint:themes', 'jshint:core']);
     370
    362371    // Copy task.
    363372    grunt.registerTask('copy:all', ['copy:files', 'copy:version']);
    364 
    365     // RTL task.
    366     grunt.registerTask('rtl', ['cssjanus:core', 'cssjanus:colors']);
    367 
    368     // Color schemes task.
    369     grunt.registerTask('colors', ['sass:colors']);
    370373
    371374    // Build task.
     
    384387    grunt.registerTask('qunit:compiled', 'Runs QUnit tests on compiled as well as uncompiled scripts.',
    385388        ['build', 'copy:qunit', 'qunit']);
     389
    386390    grunt.registerTask('test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit']);
     391
     392    // Travis CI tasks.
     393    grunt.registerTask('travis:js', 'Runs Javascript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]);
     394    grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', 'phpunit');
    387395
    388396    // Default task.
  • branches/3.8/package.json

    r46935 r47338  
    1212    "grunt": "~0.4.1",
    1313    "grunt-contrib-clean": "~0.5.0",
     14    "grunt-contrib-compress": "~0.5.2",
     15    "grunt-contrib-concat": "~0.3.0",
    1416    "grunt-contrib-copy": "~0.4.1",
    1517    "grunt-contrib-cssmin": "~0.6.1",
     18    "grunt-contrib-jshint": "~0.10.0",
    1619    "grunt-contrib-qunit": "~0.2.2",
    1720    "grunt-contrib-uglify": "~0.2.2",
    1821    "grunt-contrib-watch": "~0.5.1",
    19     "grunt-contrib-compress": "~0.5.2",
    20     "grunt-contrib-concat": "~0.3.0",
    21     "grunt-contrib-jshint": "~0.7.0",
    2222    "grunt-cssjanus": "git://github.com/yoavf/grunt-cssjanus.git#e0158f4087d1c4bb5a8d1648a63ef133338b5879",
    23     "grunt-sass": "~1.0.0",
     23    "grunt-sass": "~0.16.0",
    2424    "matchdep": "~0.1.2"
    2525  }
  • branches/3.8/phpunit.xml.dist

    r25165 r47338  
    2626        <log type="junit" target="tests/phpunit/build/logs/junit.xml" logIncompleteSkipped="false"/>
    2727    </logging>
     28    <php>
     29        <const name="WP_RUN_CORE_TESTS" value="1" />
     30    </php>
    2831</phpunit>
  • branches/3.8/tests/phpunit/includes/bootstrap.php

    r25415 r47338  
    9696 * A child class of the PHP test runner.
    9797 *
    98  * Not actually used as a runner. Rather, used to access the protected
    99  * longOptions property, to parse the arguments passed to the script.
     98 * Used to access the protected longOptions property, to parse the arguments
     99 * passed to the script.
    100100 *
    101101 * If it is determined that phpunit was called with a --group that corresponds
     
    106106 * how you call phpunit has no effect.
    107107 */
    108 class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command {
     108class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
     109    protected $longOptions = array(
     110      'exclude-group=',
     111      'group=',
     112    );
    109113    function __construct( $argv ) {
    110         $options = PHPUnit_Util_Getopt::getopt(
    111             $argv,
    112             'd:c:hv',
    113             array_keys( $this->longOptions )
    114         );
     114        array_shift( $argv );
     115        $options = array();
     116        while ( list( $i, $arg ) = each( $argv ) ) {
     117            try {
     118                if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {
     119                    PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );
     120                }
     121            }
     122            catch ( PHPUnit_Framework_Exception $e ) {
     123                // Enforcing recognized arguments or correctly formed arguments is
     124                // not really the concern here.
     125                continue;
     126            }
     127        }
     128
    115129        $ajax_message = true;
    116         foreach ( $options[0] as $option ) {
     130        foreach ( $options as $option ) {
    117131            switch ( $option[0] ) {
    118132                case '--exclude-group' :
     
    122136                    $groups = explode( ',', $option[1] );
    123137                    foreach ( $groups as $group ) {
    124                         if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) )
     138                        if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) {
    125139                            WP_UnitTestCase::forceTicket( $group );
     140                        }
    126141                    }
    127142                    $ajax_message = ! in_array( 'ajax', $groups );
     
    129144            }
    130145        }
    131         if ( $ajax_message )
     146        if ( $ajax_message ) {
    132147            echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL;
     148        }
    133149    }
    134150}
    135 new WP_PHPUnit_TextUI_Command( $_SERVER['argv'] );
     151new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );
  • branches/3.8/tests/phpunit/includes/testcase.php

    r42067 r47338  
    1212    protected $caught_doing_it_wrong = array();
    1313
     14    protected static $hooks_saved = array();
     15    protected static $ignore_files;
     16
    1417    /**
    1518     * @var WP_UnitTest_Factory
     
    1922    function setUp() {
    2023        set_time_limit(0);
     24
     25        if ( ! self::$ignore_files ) {
     26            self::$ignore_files = $this->scan_user_uploads();
     27        }
     28
     29        if ( ! self::$hooks_saved ) {
     30            $this->_backup_hooks();
     31        }
    2132
    2233        global $wpdb;
     
    2738        $this->factory = new WP_UnitTest_Factory;
    2839        $this->clean_up_global_scope();
     40
     41        /*
     42         * When running core tests, ensure that post types and taxonomies
     43         * are reset for each test. We skip this step for non-core tests,
     44         * given the large number of plugins that register post types and
     45         * taxonomies at 'init'.
     46         */
     47        if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
     48            $this->reset_post_types();
     49            $this->reset_taxonomies();
     50        }
     51
    2952        $this->start_transaction();
    3053        $this->expectDeprecated();
    3154        add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     55    }
     56
     57    /**
     58     * Unregister existing post types and register defaults.
     59     *
     60     * Run before each test in order to clean up the global scope, in case
     61     * a test forgets to unregister a post type on its own, or fails before
     62     * it has a chance to do so.
     63     */
     64    protected function reset_post_types() {
     65        foreach ( get_post_types() as $pt ) {
     66            _unregister_post_type( $pt );
     67        }
     68        create_initial_post_types();
     69    }
     70
     71    /**
     72     * Unregister existing taxonomies and register defaults.
     73     *
     74     * Run before each test in order to clean up the global scope, in case
     75     * a test forgets to unregister a taxonomy on its own, or fails before
     76     * it has a chance to do so.
     77     */
     78    protected function reset_taxonomies() {
     79        foreach ( get_taxonomies() as $tax ) {
     80            _unregister_taxonomy( $tax );
     81        }
     82        create_initial_taxonomies();
    3283    }
    3384
     
    3687        $this->expectedDeprecated();
    3788        $wpdb->query( 'ROLLBACK' );
    38         remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
     89        if ( is_multisite() ) {
     90            while ( ms_is_switched() ) {
     91                restore_current_blog();
     92            }
     93        }
     94        remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
    3995        remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    4096        remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     97        $this->_restore_hooks();
     98        wp_set_current_user( 0 );
    4199    }
    42100
     
    47105    }
    48106
     107    /**
     108     * Allow tests to be skipped on some automated runs
     109     *
     110     * For test runs on Travis for something other than trunk/master
     111     * we want to skip tests that only need to run for master.
     112     */
     113    public function skipOnAutomatedBranches() {
     114        // gentenv can be disabled
     115        if ( ! function_exists( 'getenv' ) ) {
     116            return false;
     117        }
     118
     119        // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
     120        $travis_branch       = getenv( 'TRAVIS_BRANCH' );
     121        $travis_pull_request = getenv( 'TRAVIS_PULL_REQUEST' );
     122
     123        if ( false !== $travis_pull_request && 'master' !== $travis_branch ) {
     124            $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
     125        }
     126    }
     127
     128    /**
     129     * Saves the action and filter-related globals so they can be restored later.
     130     *
     131     * Stores $merged_filters, $wp_actions, $wp_current_filter, and $wp_filter
     132     * on a class variable so they can be restored on tearDown() using _restore_hooks().
     133     *
     134     * @global array $merged_filters
     135     * @global array $wp_actions
     136     * @global array $wp_current_filter
     137     * @global array $wp_filter
     138     * @return void
     139     */
     140    protected function _backup_hooks() {
     141        $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
     142        foreach ( $globals as $key ) {
     143            self::$hooks_saved[ $key ] = $GLOBALS[ $key ];
     144        }
     145    }
     146
     147    /**
     148     * Restores the hook-related globals to their state at setUp()
     149     * so that future tests aren't affected by hooks set during this last test.
     150     *
     151     * @global array $merged_filters
     152     * @global array $wp_actions
     153     * @global array $wp_current_filter
     154     * @global array $wp_filter
     155     * @return void
     156     */
     157    protected function _restore_hooks() {
     158        $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
     159        foreach ( $globals as $key ) {
     160            if ( isset( self::$hooks_saved[ $key ] ) ) {
     161                $GLOBALS[ $key ] = self::$hooks_saved[ $key ];
     162            }
     163        }
     164    }
     165   
    49166    function flush_cache() {
    50167        global $wp_object_cache;
     
    65182        $wpdb->query( 'SET autocommit = 0;' );
    66183        $wpdb->query( 'START TRANSACTION;' );
    67         add_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
     184        add_filter( 'query', array( $this, '_create_temporary_tables' ) );
    68185        add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    69186    }
    70187
    71     function _create_temporary_tables( $queries ) {
    72         return str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $queries );
     188    function _create_temporary_tables( $query ) {
     189        if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) )
     190            return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 );
     191        return $query;
    73192    }
    74193
    75194    function _drop_temporary_tables( $query ) {
    76         if ( 'DROP TABLE' === substr( $query, 0, 10 ) )
    77             return 'DROP TEMPORARY TABLE ' . substr( $query, 10 );
     195        if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) )
     196            return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 );
    78197        return $query;
    79198    }
     
    206325    protected function checkRequirements() {
    207326        parent::checkRequirements();
     327
     328        // Core tests no longer check against open Trac tickets, but others using WP_UnitTestCase may do so.
     329        if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
     330            return;
     331        }
     332
    208333        if ( WP_TESTS_FORCE_KNOWN_BUGS )
    209334            return;
     
    230355        if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) )
    231356            return;
    232         if ( ! TracTickets::isTracTicketClosed( 'http://core.trac.wordpress.org', $ticket_id ) )
     357        if ( ! TracTickets::isTracTicketClosed( 'https://core.trac.wordpress.org', $ticket_id ) )
    233358            $this->markTestSkipped( sprintf( 'WordPress Ticket #%d is not fixed', $ticket_id ) );
    234359    }
     
    240365        if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'UT' . $ticket_id, self::$forced_tickets ) )
    241366            return;
    242         if ( ! TracTickets::isTracTicketClosed( 'http://unit-tests.trac.wordpress.org', $ticket_id ) )
     367        if ( ! TracTickets::isTracTicketClosed( 'https://unit-tests.trac.wordpress.org', $ticket_id ) )
    243368            $this->markTestSkipped( sprintf( 'Unit Tests Ticket #%d is not fixed', $ticket_id ) );
    244369    }
     
    250375        if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) )
    251376            return;
    252         if ( ! TracTickets::isTracTicketClosed( 'http://plugins.trac.wordpress.org', $ticket_id ) )
     377        if ( ! TracTickets::isTracTicketClosed( 'https://plugins.trac.wordpress.org', $ticket_id ) )
    253378            $this->markTestSkipped( sprintf( 'WordPress Plugin Ticket #%d is not fixed', $ticket_id ) );
    254379    }
     
    328453        $this->assertTrue( $passed, $message );
    329454    }
     455
     456    function unlink( $file ) {
     457        $exists = is_file( $file );
     458        if ( $exists && ! in_array( $file, self::$ignore_files ) ) {
     459            //error_log( $file );
     460            unlink( $file );
     461        } elseif ( ! $exists ) {
     462            $this->fail( "Trying to delete a file that doesn't exist: $file" );
     463        }
     464    }
     465
     466    function rmdir( $path ) {
     467        $files = $this->files_in_dir( $path );
     468        foreach ( $files as $file ) {
     469            if ( ! in_array( $file, self::$ignore_files ) ) {
     470                $this->unlink( $file );
     471            }
     472        }
     473    }
     474
     475    function remove_added_uploads() {
     476        // Remove all uploads.
     477        $uploads = wp_upload_dir();
     478        $this->rmdir( $uploads['basedir'] );
     479    }
     480
     481    function files_in_dir( $dir ) {
     482        $files = array();
     483
     484        $iterator = new RecursiveDirectoryIterator( $dir );
     485        $objects = new RecursiveIteratorIterator( $iterator );
     486        foreach ( $objects as $name => $object ) {
     487            if ( is_file( $name ) ) {
     488                $files[] = $name;
     489            }
     490        }
     491
     492        return $files;
     493    }
     494
     495    function scan_user_uploads() {
     496        static $files = array();
     497        if ( ! empty( $files ) ) {
     498            return $files;
     499        }
     500
     501        $uploads = wp_upload_dir();
     502        $files = $this->files_in_dir( $uploads['basedir'] );
     503        return $files;
     504    }
    330505}
  • branches/3.8/tests/phpunit/includes/trac.php

    r25002 r47338  
    1515     */
    1616    public static function isTracTicketClosed( $trac_url, $ticket_id ) {
     17        if ( ! extension_loaded( 'openssl' ) ) {
     18            $trac_url = preg_replace( "/^https:/", "http:", $trac_url );
     19        }
     20
    1721        if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) {
    1822            // In case you're running the tests offline, keep track of open tickets.
  • branches/3.8/tests/phpunit/includes/utils.php

    r32186 r47338  
    335335}
    336336
    337 function _rmdir( $path ) {
    338     if ( in_array(basename( $path ), array( '.', '..' ) ) ) {
    339         return;
    340     } elseif ( is_file( $path ) ) {
    341         unlink( $path );
    342     } elseif ( is_dir( $path ) ) {
    343         foreach ( scandir( $path ) as $file )
    344             _rmdir( $path . '/' . $file );
    345         rmdir( $path );
    346     }
    347 }
    348 
    349337/**
    350338 * Removes the post type and its taxonomy associations.
  • branches/3.8/tests/phpunit/multisite.xml

    r25294 r47338  
    2626        </exclude>
    2727    </groups>
     28    <php>
     29        <const name="WP_RUN_CORE_TESTS" value="1" />
     30    </php>
    2831</phpunit>
  • branches/3.8/tests/phpunit/tests/ajax/DeleteComment.php

    r25002 r47338  
    2727    public function setUp() {
    2828        parent::setUp();
    29         $post_id = $this->factory->post->create();
     29        add_filter( 'comment_notification_recipients', '__return_empty_array' );
     30        $user_id = $this->factory->user->create();
     31        $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) );
    3032        $this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 );
    3133        $this->_comments = array_map( 'get_comment', $this->_comments );
  • branches/3.8/tests/phpunit/tests/ajax/DimComment.php

    r25002 r47338  
    2727    public function setUp() {
    2828        parent::setUp();
    29         $post_id = $this->factory->post->create();
     29        add_filter( 'comment_notification_recipients', '__return_empty_array' );
     30        $user_id = $this->factory->user->create();
     31        $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) );
    3032        $this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 );
    3133        $this->_comments = array_map( 'get_comment', $this->_comments );
  • branches/3.8/tests/phpunit/tests/ajax/MediaEdit.php

    r26088 r47338  
    3333    public function tearDown() {
    3434        // Cleanup
    35         foreach ($this->_ids as $id){
    36             wp_delete_attachment($id, true);
     35        foreach ( $this->_ids as $id ) {
     36            wp_delete_attachment( $id, true );
    3737        }
    38 
    39         $uploads = wp_upload_dir();
    40         foreach ( scandir( $uploads['basedir'] ) as $file )
    41             _rmdir( $uploads['basedir'] . '/' . $file );
    4238
    4339        parent::tearDown();
  • branches/3.8/tests/phpunit/tests/ajax/ReplytoComment.php

    r25433 r47338  
    3333    public function setUp() {
    3434        parent::setUp();
    35         $post_id = $this->factory->post->create();
     35        add_filter( 'comment_notification_recipients', '__return_empty_array' );
     36        $user_id = $this->factory->user->create();
     37        $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) );
    3638        $this->factory->comment->create_post_comments( $post_id, 5 );
    3739        $this->_comment_post = get_post( $post_id );
  • branches/3.8/tests/phpunit/tests/basic.php

    r42098 r47338  
    2121    function test_true() {
    2222        $this->assertTrue($this->val);
     23    }
     24
     25    function test_license() {
     26        // This test is designed to only run on trunk/master
     27        $this->skipOnAutomatedBranches();
     28
     29        $license = file_get_contents( ABSPATH . 'license.txt' );
     30        preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
     31        $this_year = date( 'Y' );
     32        $this->assertEquals( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
     33    }
     34
     35    function test_package_json() {
     36        $package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
     37        $package_json = json_decode( $package_json, true );
     38        list( $version ) = explode( '-', $GLOBALS['wp_version'] );
     39        // package.json uses x.y.z, so fill cleaned $wp_version for .0 releases
     40        if ( 1 == substr_count( $version, '.' ) ) {
     41            $version .= '.0';
     42        }
     43        $this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
    2344    }
    2445
  • branches/3.8/tests/phpunit/tests/canonical.php

    r32150 r47338  
    2020
    2121    function setUp() {
     22        global $wp_rewrite;
     23
    2224        parent::setUp();
    2325
     
    2628        update_option( 'posts_per_page', 5 );
    2729
    28         update_option( 'permalink_structure', $this->structure );
     30        $wp_rewrite->init();
     31        $wp_rewrite->set_permalink_structure( $this->structure );
     32
    2933        create_initial_taxonomies();
    30         $GLOBALS['wp_rewrite']->init();
    31         flush_rewrite_rules();
     34
     35        $wp_rewrite->flush_rules();
    3236
    3337        $this->old_current_user = get_current_user_id();
     
    8185
    8286    function tearDown() {
     87        global $wp_rewrite;
    8388        wp_set_current_user( $this->old_current_user );
    8489
    85         $GLOBALS['wp_rewrite']->init();
     90        $wp_rewrite->init();
    8691        parent::tearDown();
    8792    }
     
    176181            array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
    177182            array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
    178             array( '/category/child-1/', '/category/parent/child-1/', 18734 ),
    179             array( '/category/foo/child-1/', '/category/parent/child-1/', 18734 ),
    180183
    181184            // Categories & Intersections with other vars
     
    187190
    188191            // Categories with Dates
    189             array( '/category/uncategorized/?paged=2&year=2008', array( 'url' => '/category/uncategorized/page/2/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2, 'year' => 2008) ), 17661 ),
    190 //          array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    191             array( '/2008/04/?cat=1', array( 'url' => '/category/uncategorized/?year=2008&monthnum=04', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
     192            array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
    192193//          array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
    193             array( '/2008/?category_name=cat-a', array( 'url' => '/category/cat-a/?year=2008', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 20386 ),
    194 //          array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    195             array( '/category/uncategorized/?year=2008', array( 'url' => '/category/uncategorized/?year=2008', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
    196194
    197195            // Pages
    198             array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
    199             array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
    200196            array( '/child-page-1/', '/parent-page/child-page-1/'),
    201197            array( '/?page_id=144', '/parent-page/child-page-1/'),
     
    217213
    218214            array( '/2008/09/03/images-test/3/', array( 'url' => '/2008/09/03/images-test/3/', 'qv' => array( 'name' => 'images-test', 'year' => '2008', 'monthnum' => '09', 'day' => '03', 'page' => '/3' ) ) ), // page = /3 ?!
    219             array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/', 11694 ), // post with 4 pages
    220215            array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
    221216            array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
     
    223218            // Comments
    224219            array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/' ),
    225             array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    226             array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
    227220
    228221            // Attachments
     
    247240            array( '/?author=%d', '/author/canonical-author/' ),
    248241//          array( '/?author=%d&year=2008', '/2008/?author=3'),
    249             array( '/?author=%d&year=2008', '/author/canonical-author/?year=2008', 17661 ),
    250242//          array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
    251             array( '/author/canonical-author/?year=2008', '/author/canonical-author/?year=2008', 17661 ),
    252243
    253244            // Feeds
  • branches/3.8/tests/phpunit/tests/canonical/customRules.php

    r25002 r47338  
    3030            array( '/ccr/uncategorized/sort/asc/', array( 'url' => '/ccr/uncategorized/sort/asc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'asc' ) ) ),
    3131            array( '/ccr/uncategorized/sort/desc/', array( 'url' => '/ccr/uncategorized/sort/desc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'desc' ) ) ),
    32             array( '/ccr/uncategorized/sort/desc/?year=2008', array( 'url' => '/ccr/uncategorized/sort/desc/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'desc', 'year' => '2008' ) ), 17661 ),
    3332        );
    3433    }
  • branches/3.8/tests/phpunit/tests/canonical/pageOnFront.php

    r25002 r47338  
    1616        update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
    1717        $wp_rewrite->init();
    18         flush_rewrite_rules();
     18        $wp_rewrite->flush_rules();
     19    }
     20
     21    function tearDown() {
     22        global $wp_rewrite;
     23        $wp_rewrite->init();
     24        parent::tearDown();
    1925    }
    2026
  • branches/3.8/tests/phpunit/tests/dependencies/scripts.php

    r26370 r47338  
    8585        $wp_scripts->base_url = $base_url_backup;
    8686    }
    87 
    88     /**
    89      * @ticket 22229
    90      */
    91     function test_inline_should_not_output_script_tag_with_src() {
    92         wp_enqueue_script( 'baba-inline-0', 'inline' );
    93         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
    94     }
    95 
    96     /**
    97      * @ticket 22229
    98      */
    99     function test_json_encode_should_not_encode_special_literal_values() {
    100         if ( ! class_exists( 'WP_JS_Literal' ) ) {
    101             $this->markTestSkipped( "WP_JS_Literal class doesn't exist" );
    102         }
    103 
    104         $literal = new WP_JS_Literal( 'baba()' );
    105         $this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );
    106     }
    107 
    108     /**
    109      * @ticket 22229
    110      */
    111     function test_json_encode_should_not_encode_special_literal_values_with_dependencies() {
    112         if ( ! class_exists( 'WP_JS_Literal' ) ) {
    113             $this->markTestSkipped( "WP_JS_Literal class doesn't exist" );
    114         }
    115        
    116         $literal = new WP_JS_Literal( 'baba()', array( 'dep0', 'dep1' ) );
    117         $this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );
    118     }
    11987}
  • branches/3.8/tests/phpunit/tests/feed/rss2.php

    r25002 r47338  
    111111
    112112            // author
    113             $creator = xml_find($items[$i]['child'], 'dc:creator');
    114             $this->assertEquals($this->author->user_nicename, $creator[0]['content']);
     113            $creator = xml_find( $items[$i]['child'], 'dc:creator' );
     114            $user = new WP_User( $posts[$i]->post_author );
     115            $this->assertEquals( $user->user_login, $creator[0]['content'] );
    115116
    116117            // categories (perhaps multiple)
    117118            $categories = xml_find($items[$i]['child'], 'category');
    118             $cat_ids = wp_get_post_categories($post->ID);
     119            $cat_ids = wp_get_post_categories($posts[$i]->ID);
    119120            if (empty($cat_ids))    $cat_ids = array(1);
    120121            // should be the same number of categories
  • branches/3.8/tests/phpunit/tests/filters.php

    r25377 r47338  
    250250        return $tag;
    251251    }
    252 
    253     /**
    254      * @ticket 21169
    255      */
    256     function test_filter_removal_during_filter() {
    257         $tag = rand_str();
    258         $a = new MockAction();
    259         $b = new MockAction();
    260 
    261         add_action( $tag, array($a, 'filter_append'), 11, 1 );
    262         add_action( $tag, array($b, 'filter_append'), 12, 1 );
    263         add_action( $tag, array($this, '_self_removal'), 10, 1 );
    264 
    265         $result = apply_filters($tag, $tag);
    266         $this->assertEquals( 1, $a->get_call_count(), 'priority 11 filters should run after priority 10 empties itself' );
    267         $this->assertEquals( 1, $b->get_call_count(), 'priority 12 filters should run after priority 10 empties itself and priority 11 runs' );
    268         $this->assertEquals( $result, $tag . '_append_append', 'priority 11 and 12 filters should run after priority 10 empties itself' );
    269     }
    270252}
  • branches/3.8/tests/phpunit/tests/formatting/EscUrl.php

    r25002 r47338  
    6464
    6565    /**
    66      * @ticket 16859
    67      */
    68     function test_square_brackets() {
    69         $this->assertEquals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo[bar]=baz' ) );
    70         $this->assertEquals( 'http://example.com/?baz=bar&#038;foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) );
    71         //IPv6 addresses in urls - RFC2732
    72         $this->assertEquals( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) );
    73         $this->assertEquals( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) );
    74         $this->assertEquals( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) );
    75     }
    76 
    77     /**
    7866     * @ticket 21974
    7967     */
  • branches/3.8/tests/phpunit/tests/formatting/MakeClickable.php

    r26094 r47338  
    364364        $this->assertEquals( $in, $out );
    365365    }
    366 
    367     /**
    368      * @ticket 16859
    369      */
    370     function test_square_brackets() {
    371         $urls_before = array(
    372             'http://example.com/?foo[bar]=baz',
    373             'http://example.com/?baz=bar&foo[bar]=baz',
    374         );
    375         $urls_expected = array(
    376             '<a href="http://example.com/?foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?foo%5Bbar%5D=baz</a>',
    377             '<a href="http://example.com/?baz=bar&#038;foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?baz=bar&#038;foo%5Bbar%5D=baz</a>',
    378         );
    379         foreach ($urls_before as $key => $url) {
    380             $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
    381         }
    382     }
    383366}
  • branches/3.8/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php

    r25002 r47338  
    3434    function test_handles_non_entity_ampersands() {
    3535        $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
    36     }
    37 
    38     /**
    39      * @ticket 10823
    40      */
    41     function test_strips_entities() {
    42         $this->assertEquals("no-entities-here", sanitize_title_with_dashes("No &nbsp; Entities &ndash; Here &amp;"));
    43         $this->assertEquals("one-two", sanitize_title_with_dashes("One &amp; Two", '', 'save'));
    44         $this->assertEquals("one-two", sanitize_title_with_dashes("One &#123; Two;", '', 'save'));
    45         $this->assertEquals("one-two", sanitize_title_with_dashes("One & Two;", '', 'save'));
    46         $this->assertEquals("one-two", sanitize_title_with_dashes("One Two™;", '', 'save'));
    47         $this->assertEquals("one-two", sanitize_title_with_dashes("One &&amp; Two;", '', 'save'));
    48         $this->assertEquals("onetwo", sanitize_title_with_dashes("One&Two", '', 'save'));
    49         $this->assertEquals("onetwo-test", sanitize_title_with_dashes("One&Two Test;", '', 'save'));
    5036    }
    5137
  • branches/3.8/tests/phpunit/tests/formatting/SanitizeUser.php

    r25002 r47338  
    1010        $this->assertEquals($expected, sanitize_user($input));
    1111    }
    12     /**
    13      * @ticket 10823
    14      */
    15     function test_strips_entities() {
    16         $this->assertEquals("ATT", sanitize_user("AT&amp;T"));
    17         $this->assertEquals("ATT Test;", sanitize_user("AT&amp;T Test;"));
    18         $this->assertEquals("AT&T Test;", sanitize_user("AT&T Test;"));
    19     }
    2012    function test_strips_percent_encoded_octets() {
    2113        $expected = is_multisite() ? 'franois' : 'Franois';
  • branches/3.8/tests/phpunit/tests/functions.php

    r25313 r47338  
    132132    }
    133133
    134     /**
    135      * @ticket 9930
    136      */
    137134    function test_is_serialized() {
    138135        $cases = array(
     
    143140            serialize(25),
    144141            serialize(1.1),
    145             serialize(2.1E+200),
    146142            serialize('this string will be serialized'),
    147143            serialize("a\nb"),
     
    156152            'a string',
    157153            'garbage:a:0:garbage;',
    158             'b:4;',
    159154            's:4:test;'
    160155        );
  • branches/3.8/tests/phpunit/tests/functions/deprecated.php

    r25409 r47338  
    149149        wp_save_image_file( $file, $img, 'image/jpeg', 1 );
    150150        imagedestroy( $img );
    151         @unlink($file);
     151        unlink( $file );
    152152
    153153        // Check if the arg was deprecated
     
    170170        wp_save_image_file( $file, $img, 'image/jpeg', 1 );
    171171        unset( $img );
    172         @unlink($file);
     172        unlink( $file );
    173173
    174174        // Check if the arg was deprecated
  • branches/3.8/tests/phpunit/tests/http/base.php

    r25224 r47338  
    285285        $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
    286286    }
    287    
    288    
     287
     288
    289289}
  • branches/3.8/tests/phpunit/tests/http/functions.php

    r25002 r47338  
    66 */
    77class Tests_HTTP_Functions extends WP_UnitTestCase {
     8    public function setUp() {
     9        if ( ! extension_loaded( 'openssl' ) ) {
     10            $this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
     11        }
     12
     13        parent::setUp();
     14    }
     15
    816    function test_head_request() {
    917        // this url give a direct 200 response
    10         $url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     18        $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
    1119        $response = wp_remote_head( $url );
    1220        $headers = wp_remote_retrieve_headers( $response );
     
    2028    function test_head_redirect() {
    2129        // this url will 301 redirect
    22         $url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     30        $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    2331        $response = wp_remote_head( $url );
    2432        $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
     
    2634
    2735    function test_head_404() {
    28         $url = 'http://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     36        $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
    2937        $headers = wp_remote_head( $url );
    3038
     
    3442
    3543    function test_get_request() {
    36         $url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     44        $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
    3745        $file = tempnam('/tmp', 'testfile');
    3846
     
    5260    function test_get_redirect() {
    5361        // this will redirect to asdftestblog1.files.wordpress.com
    54         $url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     62        $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    5563        $file = tempnam('/tmp', 'testfile');
    5664
     
    7078    function test_get_redirect_limit_exceeded() {
    7179        // this will redirect to asdftestblog1.files.wordpress.com
    72         $url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     80        $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    7381        $file = tempnam('/tmp', 'testfile');
    7482        // pretend we've already redirected 5 times
  • branches/3.8/tests/phpunit/tests/image/base.php

    r25002 r47338  
    1010     */
    1111    public function setUp() {
     12        parent::setUp();
     13
    1214        if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) {
    1315            $this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) );
     
    2123     */
    2224    public function tearDown() {
     25        parent::tearDown();
     26
    2327        remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
     28        parent::tearDown();
    2429    }
    2530
     
    3439    /**
    3540     * Helper assertion for testing alpha on images
    36      * 
     41     *
    3742     * @param  string $image_path
    3843     * @param  array $point      array(x,y)
  • branches/3.8/tests/phpunit/tests/image/editor_gd.php

    r25002 r47338  
    77 * @group wp-image-editor-gd
    88 */
     9require_once( dirname( __FILE__ ) . '/base.php' );
    910
    1011class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
     
    1415        require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
    1516        require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );
     17
    1618        parent::setUp();
     19    }
     20
     21    public function tearDown() {
     22        $folder = DIR_TESTDATA . '/images/waffles-*.jpg';
     23
     24        foreach ( glob( $folder ) as $file ) {
     25            unlink( $file );
     26        }
     27
     28        $this->remove_added_uploads();
     29
     30        parent::tearDown();
    1731    }
    1832
     
    135149        $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
    136150
     151        unlink( $save_to_file );
    137152    }
    138153   
     
    154169
    155170        $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     171
     172        unlink( $save_to_file );
    156173    }
    157174
  • branches/3.8/tests/phpunit/tests/image/editor_imagick.php

    r25002 r47338  
    77 * @group wp-image-editor-imagick
    88 */
     9require_once( dirname( __FILE__ ) . '/base.php' );
    910
    1011class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
     
    2223
    2324        parent::setUp();
     25    }
     26
     27    public function tearDown() {
     28        $folder = DIR_TESTDATA . '/images/waffles-*.jpg';
     29
     30        foreach ( glob( $folder ) as $file ) {
     31            unlink( $file );
     32        }
     33
     34        $this->remove_added_uploads();
     35
     36        parent::tearDown();
    2437    }
    2538
     
    143156        $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
    144157
     158        unlink( $save_to_file );
    145159    }
    146160   
     
    158172
    159173        $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
    160        
     174
    161175        $editor->save( $save_to_file );
    162176
    163177        $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     178
     179        unlink( $save_to_file );
    164180    }
    165181}
  • branches/3.8/tests/phpunit/tests/image/functions.php

    r26705 r47338  
    8989        $files = array(
    9090            // 'test-image-cmyk.jpg', Allowed in r9727
    91             'test-image.bmp',
     91            // 'test-image.bmp', Allowed in r28589
    9292            // 'test-image-grayscale.jpg', Allowed in r9727
    9393            'test-image.pct',
     
    145145
    146146                // Clean up
    147                 @unlink( $file );
    148                 @unlink( $ret['path'] );
     147                unlink( $file );
     148                unlink( $ret['path'] );
    149149            }
    150150
     
    186186
    187187            // Clean up
    188             @unlink( $file );
    189             @unlink( $ret['path'] );
     188            unlink( $file );
     189            unlink( $ret['path'] );
    190190            unset( $img );
    191191        }
     
    232232                $this->assertNotInstanceOf( 'WP_Error', $ret );
    233233                $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) );
    234                 @unlink( $file );
    235                 @unlink( $ret['path'] );
     234                unlink( $ret['path'] );
    236235            }
    237236
     
    292291            $this->markTestSkipped( 'jpeg support unavailable' );
    293292
    294         $file = wp_crop_image( 'http://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
     293        if ( ! extension_loaded( 'openssl' ) ) {
     294            $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' );
     295        }
     296
     297        $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
    295298                              0, 0, 100, 100, 100, 100, false,
    296299                              DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
     
    312315
    313316    public function test_wp_crop_image_url_not_exist() {
    314         $file = wp_crop_image( 'http://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
     317        if ( ! extension_loaded( 'openssl' ) ) {
     318            $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' );
     319        }
     320
     321        $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
    315322                              0, 0, 100, 100, 100, 100 );
    316323        $this->assertInstanceOf( 'WP_Error', $file );
  • branches/3.8/tests/phpunit/tests/image/intermediate_size.php

    r25507 r47338  
    11<?php
    2 
    32/**
    43 * @group image
     
    76 */
    87class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
     8    function tearDown() {
     9        $this->remove_added_uploads();
     10        parent::tearDown();
     11    }
     12
    913    function test_make_intermediate_size_no_size() {
    1014        $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
  • branches/3.8/tests/phpunit/tests/image/resize.php

    r25002 r47338  
    55 * @group media
    66 * @group upload
     7 * @group resize
    78 */
     9require_once( dirname( __FILE__ ) . '/base.php' );
     10
    811abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase {
    912
     
    109112        $this->assertEquals( IMAGETYPE_JPEG, $type );
    110113
    111         unlink($image);
     114        unlink( $image );
    112115    }
    113116
     
    136139
    137140    /**
    138      * Try resizing a php file (bad image)
    139      * @ticket 6821
    140      */
    141     public function test_resize_bad_image() {
    142         $image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
    143         $this->assertInstanceOf( 'WP_Error', $image );
    144         $this->assertEquals( 'invalid_image', $image->get_error_code() );
    145     }
    146 
    147 
    148     /**
    149141     * Function to help out the tests
    150142     */
  • branches/3.8/tests/phpunit/tests/image/resize_gd.php

    r25002 r47338  
    55 * @group media
    66 * @group upload
     7 * @group resize
    78 */
     9require_once( dirname( __FILE__ ) . '/resize.php' );
     10
    811class Test_Image_Resize_GD extends WP_Tests_Image_Resize_UnitTestCase {
    912
     
    1316     */
    1417    public $editor_engine = 'WP_Image_Editor_GD';
     18
     19    public function setUp() {
     20        require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
     21        require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );
     22
     23        parent::setUp();
     24    }
     25
     26    /**
     27     * Try resizing a php file (bad image)
     28     * @ticket 6821
     29     */
     30    public function test_resize_bad_image() {
     31
     32        $image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
     33        $this->assertInstanceOf( 'WP_Error', $image );
     34        $this->assertEquals( 'invalid_image', $image->get_error_code() );
     35    }
     36
    1537}
  • branches/3.8/tests/phpunit/tests/image/resize_imagick.php

    r25002 r47338  
    55 * @group media
    66 * @group upload
     7 * @group resize
    78 */
     9require_once( dirname( __FILE__ ) . '/resize.php' );
     10
    811class Test_Image_Resize_Imagick extends WP_Tests_Image_Resize_UnitTestCase {
    912
     
    1316     */
    1417    public $editor_engine = 'WP_Image_Editor_Imagick';
     18
     19    public function setUp() {
     20        require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
     21        require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
     22
     23        parent::setUp();
     24    }
    1525}
  • branches/3.8/tests/phpunit/tests/l10n.php

    r25407 r47338  
    1717        $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
    1818    }
    19 
    20     /**
    21      * @ticket 21319
    22      */
    23     function test_is_textdomain_loaded_for_no_translations() {
    24         $this->assertFalse( load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/non-existent-file' ) );
    25         $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
    26         $this->assertInstanceOf( 'NOOP_Translations', get_translations_for_domain( 'wp-tests-domain' ) );
    27         // Ensure that we don't confuse NOOP_Translations to be a loaded text domain.
    28         $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
    29         $this->assertFalse( unload_textdomain( 'wp-tests-domain' ) );
    30     }
    3119}
  • branches/3.8/tests/phpunit/tests/link.php

    r25959 r47338  
    44 */
    55class Tests_Link extends WP_UnitTestCase {
     6
     7    function tearDown() {
     8        global $wp_rewrite;
     9        $wp_rewrite->init();
     10        parent::tearDown();
     11    }
    612
    713    function _get_pagenum_link_cb( $url ) {
     
    3036
    3137    function test_wp_get_shortlink() {
     38        global $wp_rewrite;
     39
    3240        $post_id = $this->factory->post->create();
    3341        $post_id2 = $this->factory->post->create();
     42
     43        $wp_rewrite->init();
     44        $wp_rewrite->set_permalink_structure( '' );
     45        $wp_rewrite->flush_rules();
    3446
    3547        // Basic case
     
    6072        $this->assertEquals( '', wp_get_shortlink() );
    6173
    62         global $wp_rewrite;
    63         $wp_rewrite->permalink_structure = '';
    6474        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    6575        $wp_rewrite->flush_rules();
     
    7484        $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
    7585        $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() );
    76 
    77         $wp_rewrite->set_permalink_structure( '' );
    78         $wp_rewrite->flush_rules();
    7986    }
    8087
     
    8794
    8895        global $wp_rewrite;
    89         $wp_rewrite->permalink_structure = '';
    9096        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    9197        $wp_rewrite->flush_rules();
    9298
    9399        $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    94 
    95         $wp_rewrite->set_permalink_structure( '' );
    96         $wp_rewrite->flush_rules();
    97100    }
    98101
  • branches/3.8/tests/phpunit/tests/mail.php

    r32150 r47338  
    7070        $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
    7171        $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
    72     }
    73 
    74     /**
    75      * @ticket 15448
    76      */
    77     function test_wp_mail_plain_and_html() {
    78         $to = 'user@example.com';
    79         $subject = 'Test email with plain text and html versions';
    80         $messages = array( 'text/plain' => 'Here is some plain text.',
    81                        'text/html' =>'<html><head></head><body>Here is the HTML ;-)<body></html>' );
    82 
    83         wp_mail( $to, $subject, $messages );
    84 
    85         preg_match( '/boundary="(.*)"/', $GLOBALS['phpmailer']->mock_sent[0]['header'], $matches);
    86         $boundry = $matches[1];
    87         $body = '--' . $boundry . '
    88 Content-Type: text/plain; charset = "UTF-8"
    89 Content-Transfer-Encoding: 8bit
    90 
    91 Here is some plain text.
    92 
    93 
    94 --' . $boundry . '
    95 Content-Type: text/html; charset = "UTF-8"
    96 Content-Transfer-Encoding: 8bit
    97 
    98 <html><head></head><body>Here is the HTML ;-)<body></html>
    99 
    100 
    101 
    102 --' . $boundry . '--
    103 ';
    104         // We need some better assertions here but these test the behaviour for now.
    105         $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
    10672    }
    10773
  • branches/3.8/tests/phpunit/tests/media.php

    r39718 r47338  
    367367        );
    368368
    369         $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     369        $post_id = media_handle_upload(
     370            'upload',
     371            0,
     372            array(),
     373            array(
     374                'action'               => 'test_upload_titles',
     375                'test_form'            => false,
     376                /*
     377                 * This test previously failed on WP < 4.0 due to is_uploaded_file()
     378                 * and move_uploaded_file() usage in wp_handle_upload().
     379                 *
     380                 * Since successful upload is irrelevant for the purpose of this test,
     381                 * discarding upload errors allows the test to proceed.
     382                 */
     383                'upload_error_handler' => array( $this, '_discard_upload_errors' ),
     384            )
     385        );
    370386
    371387        unset( $_FILES['upload'] );
     
    377393
    378394        $this->assertEquals( 'This is a test', $post->post_title );
     395    }
     396
     397    function _discard_upload_errors( &$file, $message ) {
     398        $uploads  = wp_upload_dir();
     399        $filename = wp_unique_filename( $uploads['path'], $file['name'] );
     400
     401        $new_file = $uploads['path'] . "/$filename";
     402        $url      = $uploads['url'] . "/$filename";
     403
     404        return array( 'file' => $new_file, 'url' => $url, 'type' => $file['type'] );
    379405    }
    380406
  • branches/3.8/tests/phpunit/tests/option/blogOption.php

    r26252 r47338  
    2020        parent::tearDown();
    2121        $wpdb->suppress_errors( $this->suppress );
    22     }
    23 
    24     function test_from_same_site() {
    25         $key = rand_str();
    26         $key2 = rand_str();
    27         $value = rand_str();
    28         $value2 = rand_str();
    29 
    30         $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
    31         $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
    32 
    33         $this->assertTrue( add_blog_option( 1, $key, $value ) );
    34         // Assert all values of $blog_id that means the current or main blog (the same here).
    35         $this->assertEquals( $value, get_blog_option( 1, $key ) );
    36         $this->assertEquals( $value, get_blog_option( null, $key ) );
    37         $this->assertEquals( $value, get_blog_option( '1', $key ) );
    38         $this->assertEquals( $value, get_option( $key ) ); // check get_option()
    39 
    40         $this->assertFalse( add_blog_option( 1, $key, $value ) );  // Already exists
    41         $this->assertFalse( update_blog_option( 1, $key, $value ) );  // Value is the same
    42         $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
    43         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    44         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    45         $this->assertFalse( add_blog_option( 1, $key, $value ) );
    46         $this->assertEquals( $value2, get_blog_option( 1, $key ) );
    47         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    48 
    49         $this->assertTrue( delete_blog_option( 1, $key ) );
    50         $this->assertFalse( get_blog_option( 1, $key ) );
    51         $this->assertFalse( get_option( $key ) ); // check get_option()
    52         $this->assertFalse( delete_blog_option( 1, $key ) );
    53         $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
    54         $this->assertEquals( $value2, get_blog_option( 1, $key2 ) );
    55         $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
    56         $this->assertTrue( delete_blog_option( 1, $key2 ) );
    57         $this->assertFalse( get_blog_option( 1, $key2 ) );
    58         $this->assertFalse( get_option( $key2 ) ); // check get_option()
    59     }
    60 
    61     function test_from_same_site_with_null_blog_id() {
    62         $key = rand_str();
    63         $key2 = rand_str();
    64         $value = rand_str();
    65         $value2 = rand_str();
    66 
    67         $this->assertFalse( get_blog_option( null, 'doesnotexist' ) );
    68         $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
    69 
    70         $this->assertTrue( add_blog_option( null, $key, $value ) );
    71         // Assert all values of $blog_id that means the current or main blog (the same here).
    72         $this->assertEquals( $value, get_blog_option( null, $key ) );
    73         $this->assertEquals( $value, get_blog_option( null, $key ) );
    74         $this->assertEquals( $value, get_option( $key ) ); // check get_option()
    75 
    76         $this->assertFalse( add_blog_option( null, $key, $value ) );  // Already exists
    77         $this->assertFalse( update_blog_option( null, $key, $value ) );  // Value is the same
    78         $this->assertTrue( update_blog_option( null, $key, $value2 ) );
    79         $this->assertEquals( $value2, get_blog_option( null, $key ) );
    80         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    81         $this->assertFalse( add_blog_option( null, $key, $value ) );
    82         $this->assertEquals( $value2, get_blog_option( null, $key ) );
    83         $this->assertEquals( $value2, get_option( $key ) ); // check get_option()
    84 
    85         $this->assertTrue( delete_blog_option( null, $key ) );
    86         $this->assertFalse( get_blog_option( null, $key ) );
    87         $this->assertFalse( get_option( $key ) ); // check get_option()
    88         $this->assertFalse( delete_blog_option( null, $key ) );
    89         $this->assertTrue( update_blog_option( null, $key2, $value2 ) );
    90         $this->assertEquals( $value2, get_blog_option( null, $key2 ) );
    91         $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
    92         $this->assertTrue( delete_blog_option( null, $key2 ) );
    93         $this->assertFalse( get_blog_option( null, $key2 ) );
    94         $this->assertFalse( get_option( $key2 ) ); // check get_option()
    9522    }
    9623
  • branches/3.8/tests/phpunit/tests/post.php

    r32186 r47338  
    447447
    448448        global $wp_rewrite;
     449        $wp_rewrite->init();
    449450        $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
     451        $wp_rewrite->flush_rules();
    450452
    451453        $post = array(
     
    736738        $this->assertEquals( $post->post_author, $this->author_id );
    737739        $this->assertEquals( $post->post_title, $title );
    738     }
    739 
    740     /**
    741      * @ticket 19373
    742      */
    743     function test_insert_programmatic_without_current_user_success() {
    744         $this->_unset_current_user();
    745 
    746         register_taxonomy( 'test_tax', 'post' );
    747 
    748         $title = rand_str();
    749         $post_data = array(
    750             'post_author' => $this->author_id,
    751             'post_status' => 'public',
    752             'post_content' => rand_str(),
    753             'post_title' => $title,
    754             'tax_input' => array(
    755                 'test_tax' => array( 'term', 'term2', 'term3' )
    756             )
    757         );
    758         // with sanitize set to false
    759         $insert_post_id = wp_insert_post( $post_data, true, false );
    760 
    761         $post = get_post( $insert_post_id );
    762         $this->assertEquals( $post->post_author, $this->author_id );
    763         $this->assertEquals( $post->post_title, $title );
    764 
    765         $terms = wp_get_object_terms( $insert_post_id, 'test_tax' );
    766         $this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) );
    767     }
    768 
    769     /**
    770      * @ticket 19373
    771      */
    772     function test_insert_programmatic_without_current_user_fail() {
    773         $this->_unset_current_user();
    774 
    775         register_taxonomy( 'test_tax', 'post' );
    776 
    777         $title = rand_str();
    778         $post_data = array(
    779             // post_author not set
    780             'post_status' => 'public',
    781             'post_content' => rand_str(),
    782             'post_title' => $title,
    783             'tax_input' => array(
    784                 'test_tax' => array( 'term', 'term2', 'term3' )
    785             )
    786         );
    787         // with sanitize set to false
    788         $insert_post_id = wp_insert_post( $post_data, true, false );
    789 
    790         // should error because no default user exists and no post author is passed in
    791         $this->assertInstanceOf( 'WP_Error', $insert_post_id );
    792         $this->assertEquals( 'empty_author', $insert_post_id->get_error_code() );
    793740    }
    794741
  • branches/3.8/tests/phpunit/tests/post/attachments.php

    r26004 r47338  
    1010    function tearDown() {
    1111        // Remove all uploads.
    12         $uploads = wp_upload_dir();
    13         foreach ( scandir( $uploads['basedir'] ) as $file )
    14             _rmdir( $uploads['basedir'] . '/' . $file );
    15 
     12        $this->remove_added_uploads();
    1613        parent::tearDown();
    1714    }
     
    212209    }
    213210
    214     /**
    215      * GUID should never be empty
    216      * @ticket 18310
    217      * @ticket 21963
    218      */
    219     function test_insert_image_without_guid() {
    220         // this image is smaller than the thumbnail size so it won't have one
    221         $filename = ( DIR_TESTDATA.'/images/test-image.jpg' );
    222         $contents = file_get_contents($filename);
    223 
    224         $upload = wp_upload_bits(basename($filename), null, $contents);
    225         $this->assertTrue( empty($upload['error']) );
    226 
    227         $upload['url'] = '';
    228         $id = $this->_make_attachment( $upload );
    229 
    230         $guid = get_the_guid( $id );
    231         $this->assertFalse( empty( $guid ) );
    232     }
    233 
    234211}
  • branches/3.8/tests/phpunit/tests/post/filtering.php

    r25002 r47338  
    9191    }
    9292
    93     /**
    94      * make sure unbalanced tags are fixed when they span a --more-- tag
    95      * @ticket 6297
    96      */
    97     function test_post_content_unbalanced_more() {
    98         $content = <<<EOF
    99 <em>some text<!--more-->
    100 that's continued after the jump</em>
    101 EOF;
    102 
    103         $expected = <<<EOF
    104 <em>some text</em><!--more-->
    105 that's continued after the jump
    106 EOF;
    107 
    108         $id = $this->factory->post->create( array( 'post_content' => $content ) );
    109         $post = get_post($id);
    110 
    111         $this->assertEquals( $expected, $post->post_content );
    112     }
    113 
    114     /**
    115      * make sure unbalanced tags are fixed when they span a --nextpage-- tag
    116      * @ticket 6297
    117      */
    118     function test_post_content_unbalanced_nextpage() {
    119         $content = <<<EOF
    120 <em>some text<!--nextpage-->
    121 that's continued after the jump</em>
    122 EOF;
    123 
    124         $expected = <<<EOF
    125 <em>some text</em><!--nextpage-->
    126 that's continued after the jump
    127 EOF;
    128 
    129         $id = $this->factory->post->create( array( 'post_content' => $content ) );
    130         $post = get_post($id);
    131 
    132         $this->assertEquals( $expected, $post->post_content );
    133     }
    134 
    135     /**
    136      * make sure unbalanced tags are fixed when they span both --more-- and --nextpage-- tags (in that order)
    137      * @ticket 6297
    138      */
    139     function test_post_content_unbalanced_more_nextpage() {
    140         $content = <<<EOF
    141 <em>some text<!--more-->
    142 that's continued after the jump</em>
    143 <!--nextpage-->
    144 <p>and the next page
    145 <!--nextpage-->
    146 breaks the graf</p>
    147 EOF;
    148 
    149         $expected = <<<EOF
    150 <em>some text</em><!--more-->
    151 that's continued after the jump
    152 <!--nextpage-->
    153 <p>and the next page
    154 </p><!--nextpage-->
    155 breaks the graf
    156 EOF;
    157 
    158         $id = $this->factory->post->create( array( 'post_content' => $content ) );
    159         $post = get_post($id);
    160 
    161         $this->assertEquals( $expected, $post->post_content );
    162     }
    163 
    164     /**
    165      * make sure unbalanced tags are fixed when they span both --nextpage-- and --more-- tags (in that order)
    166      * @ticket 6297
    167      */
    168     function test_post_content_unbalanced_nextpage_more() {
    169         $content = <<<EOF
    170 <em>some text<!--nextpage-->
    171 that's continued after the jump</em>
    172 <!--more-->
    173 <p>and the next page
    174 <!--nextpage-->
    175 breaks the graf</p>
    176 EOF;
    177 
    178         $expected = <<<EOF
    179 <em>some text</em><!--nextpage-->
    180 that's continued after the jump
    181 <!--more-->
    182 <p>and the next page
    183 </p><!--nextpage-->
    184 breaks the graf
    185 EOF;
    186 
    187         $id = $this->factory->post->create( array( 'post_content' => $content ) );
    188         $post = get_post($id);
    189 
    190         $this->assertEquals( $expected, $post->post_content );
    191     }
    192 
    19393    // make sure unbalanced tags are untouched when the balance option is off
    19494    function test_post_content_nobalance_nextpage_more() {
  • branches/3.8/tests/phpunit/tests/post/revisions.php

    r32150 r47338  
    5454
    5555        wp_set_current_user( 0 );
    56     }
    57 
    58     /**
    59     * @ticket 7392
    60     * @ticket 9843
    61     */
    62     function test_revision_dont_save_revision_if_unchanged() {
    63         $post = get_default_post_to_edit( 'post', true );
    64         $post_id = $post->ID;
    65 
    66         $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation.
    67 
    68         wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_content' => 'some_content', 'ID' => $post_id ) );
    69 
    70         $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision
    71 
    72         // First update
    73         wp_update_post( array( 'post_content'   => 'some updated content', 'ID' => $post_id ) );
    74 
    75         $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far
    76 
    77         //update the post
    78         wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision
    79         $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far
    80 
    81         //next try to save another identical update, tests for patch that prevents storing duplicates
    82         wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
    83         $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision
    84 
    85         //next try to save another update, same content, but new ttile, should save revision
    86         wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) );
    87         $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should  be 4 revision
    88 
    89         //next try to save another identical update
    90         wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
    91         $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision
    9256    }
    9357
  • branches/3.8/tests/phpunit/tests/query.php

    r27647 r47338  
    22
    33class Tests_Query extends WP_UnitTestCase {
     4
     5    function setUp() {
     6        global $wp_rewrite;
     7        parent::setUp();
     8
     9        $wp_rewrite->init();
     10        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     11
     12        create_initial_taxonomies();
     13
     14        $wp_rewrite->flush_rules();
     15    }
    416
    517    /**
  • branches/3.8/tests/phpunit/tests/query/conditionals.php

    r32150 r47338  
    2424
    2525        global $wp_rewrite;
    26         update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
     26
     27        $wp_rewrite->init();
     28        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     29
    2730        create_initial_taxonomies();
    28         $GLOBALS['wp_rewrite']->init();
    29         flush_rewrite_rules();
     31
     32        $wp_rewrite->flush_rules();
    3033    }
    3134
    3235    function tearDown() {
    33         $GLOBALS['wp_rewrite']->init();
     36        global $wp_rewrite;
     37        $wp_rewrite->init();
     38
    3439        parent::tearDown();
    3540    }
  • branches/3.8/tests/phpunit/tests/query/results.php

    r26479 r47338  
    280280
    281281    /**
    282      * @ticket 18897
    283      */
    284     function test_query_offset_and_paged() {
    285         $posts = $this->q->query('paged=2&offset=3');
    286 
    287         $expected = array (
    288             0 => 'many-trackbacks',
    289             1 => 'one-trackback',
    290             2 => 'comment-test',
    291             3 => 'lorem-ipsum',
    292             4 => 'cat-c',
    293             5 => 'cat-b',
    294             6 => 'cat-a',
    295             7 => 'cats-a-and-c',
    296             8 => 'cats-b-and-c',
    297             9 => 'cats-a-and-b',
    298         );
    299 
    300         $this->assertCount( 10, $posts );
    301         $this->assertTrue( $this->q->is_paged() );
    302         $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) );
    303     }
    304 
    305     /**
    306282     * @ticket 11056
    307283     */
  • branches/3.8/tests/phpunit/tests/query/taxQuery.php

    r26946 r47338  
    2323
    2424    function setUp() {
     25        global $wp_rewrite;
    2526        parent::setUp();
    2627
    2728        set_current_screen( 'front' );
    2829
    29         update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
    30 
    3130        $GLOBALS['wp_the_query'] = new WP_Query();
    3231        $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
     32
     33        $wp_rewrite->init();
     34        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    3335
    3436        create_initial_taxonomies();
    3537        register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
    3638
    37         $GLOBALS['wp_rewrite']->init();
    38         flush_rewrite_rules();
     39        $wp_rewrite->flush_rules();
    3940
    4041        $this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
     
    5758
    5859    function tearDown() {
     60        global $wp_rewrite;
    5961        parent::tearDown();
    6062
    6163        _unregister_taxonomy( 'testtax' );
     64
     65        $wp_rewrite->init();
    6266
    6367        remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
  • branches/3.8/tests/phpunit/tests/query/verboseRewriteRules.php

    r25002 r47338  
    99class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals {
    1010    function setUp() {
     11        global $wp_rewrite;
     12
    1113        parent::setUp();
    12         global $wp_rewrite;
    13         update_option( 'permalink_structure', '/%category%/%year%/%postname%/' );
     14       
     15        $wp_rewrite->init();
     16        $wp_rewrite->set_permalink_structure( '/%category%/%year%/%postname%/' );
     17
    1418        create_initial_taxonomies();
    15         $GLOBALS['wp_rewrite']->init();
    16         flush_rewrite_rules();
     19
     20        $wp_rewrite->flush_rules();
    1721    }
    1822}
  • branches/3.8/tests/phpunit/tests/rewrite.php

    r32150 r47338  
    99
    1010    function setUp() {
     11        global $wp_rewrite;
    1112        parent::setUp();
    1213
    1314        // Need rewrite rules in place to use url_to_postid
    14         global $wp_rewrite;
    15         update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
     15        $wp_rewrite->init();
     16        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     17
    1618        create_initial_taxonomies();
    17         $GLOBALS['wp_rewrite']->init();
    18         flush_rewrite_rules();
     19
     20        $wp_rewrite->flush_rules();
    1921    }
    2022
    2123    function tearDown() {
    22         $GLOBALS['wp_rewrite']->init();
     24        global $wp_rewrite;
     25        $wp_rewrite->init();
     26
    2327        parent::tearDown();
    2428    }
     
    3539    function test_url_to_postid_custom_post_type() {
    3640        delete_option( 'rewrite_rules' );
    37        
     41
    3842        $post_type = rand_str( 12 );
    3943        register_post_type( $post_type, array( 'public' => true ) );
    40        
     44
    4145        $id = $this->factory->post->create( array( 'post_type' => $post_type ) );
    42         $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );     
    43        
    44         _unregister_post_type( $post_type );       
     46        $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     47
     48        _unregister_post_type( $post_type );
    4549    }
    46    
     50
    4751    function test_url_to_postid_hierarchical() {
    4852
  • branches/3.8/tests/phpunit/tests/shortcode.php

    r33567 r47338  
    309309
    310310    /**
    311      * @ticket 14050
    312      */
    313     function test_multiple_shortcode_unautop() {
    314         // a blank line is added at the end, so test with it already there
    315         $test_string = "[footag]\n[footag]\n";
    316         $actual = shortcode_unautop( wpautop( $test_string ) );
    317         $this->assertEquals( $test_string, $actual );
    318     }
    319 
    320     /**
    321311     * @ticket 10326
    322312     */
  • branches/3.8/tests/phpunit/tests/taxonomy.php

    r25923 r47338  
    106106
    107107    /**
    108      * @ticket 11058
    109      */
    110     function test_registering_taxonomies_to_object_types() {
    111         // Create a taxonomy to test with
    112         $tax = 'test_tax';
    113         $this->assertFalse( taxonomy_exists($tax) );
    114         register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );
    115 
    116         // Create a post type to test with
    117         $post_type = 'test_cpt';
    118         $this->assertFalse( get_post_type( $post_type ) );
    119         $this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) );
    120 
    121         // Core taxonomy, core post type
    122         $this->assertTrue( unregister_taxonomy_for_object_type( 'category', 'post' ) );
    123         $this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'post' ) );
    124         $this->assertTrue( register_taxonomy_for_object_type( 'category', 'post' ) );
    125 
    126         // Core taxonomy, non-core post type
    127         $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
    128         $this->assertTrue( unregister_taxonomy_for_object_type( 'category', $post_type ) );
    129         $this->assertFalse( unregister_taxonomy_for_object_type( 'category', $post_type ) );
    130         $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
    131 
    132         // Core taxonomies, non-post object types
    133         $this->assertFalse( register_taxonomy_for_object_type( 'category', 'user' ) );
    134         $this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'user' ) );
    135 
    136         // Non-core taxonomy, core post type
    137         $this->assertTrue( unregister_taxonomy_for_object_type( $tax, 'post' ) );
    138         $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'post' ) );
    139         $this->assertTrue( register_taxonomy_for_object_type( $tax, 'post' ) );
    140 
    141         // Non-core taxonomy, non-core post type
    142         $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
    143         $this->assertTrue( unregister_taxonomy_for_object_type( $tax, $post_type ) );
    144         $this->assertFalse( unregister_taxonomy_for_object_type( $tax, $post_type ) );
    145         $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
    146 
    147         // Non-core taxonomies, non-post object types
    148         $this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) );
    149         $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) );
    150 
    151         unset($GLOBALS['wp_taxonomies'][$tax]);
    152         _unregister_post_type( $post_type );
    153 
    154     }
    155     /**
    156108     * @ticket 25706
    157109     */
  • branches/3.8/tests/phpunit/tests/term.php

    r26511 r47338  
    413413
    414414    /**
    415      * @ticket 5809
    416      */
    417     function test_update_shared_term() {
    418         $random_tax = __FUNCTION__;
    419 
    420         register_taxonomy( $random_tax, 'post' );
    421 
    422         $post_id = $this->factory->post->create();
    423 
    424         $old_name = 'Initial';
    425 
    426         $t1 = wp_insert_term( $old_name, 'category' );
    427         $t2 = wp_insert_term( $old_name, 'post_tag' );
    428 
    429         $this->assertEquals( $t1['term_id'], $t2['term_id'] );
    430 
    431         wp_set_post_categories( $post_id, array( $t1['term_id'] ) );
    432         wp_set_post_tags( $post_id, array( (int) $t2['term_id'] ) );
    433 
    434         $new_name = 'Updated';
    435 
    436         // create the term in a third taxonomy, just to keep things interesting
    437         $t3 = wp_insert_term( $old_name, $random_tax );
    438         wp_set_post_terms( $post_id, array( (int) $t3['term_id'] ), $random_tax );
    439         $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );
    440 
    441         $t2_updated = wp_update_term( $t2['term_id'], 'post_tag', array(
    442             'name' => $new_name
    443         ) );
    444 
    445         $this->assertNotEquals( $t2_updated['term_id'], $t3['term_id'] );
    446 
    447         // make sure the terms have split
    448         $this->assertEquals( $old_name, get_term_field( 'name', $t1['term_id'], 'category' ) );
    449         $this->assertEquals( $new_name, get_term_field( 'name', $t2_updated['term_id'], 'post_tag' ) );
    450 
    451         // and that they are still assigned to the correct post
    452         $this->assertPostHasTerms( $post_id, array( $t1['term_id'] ), 'category' );
    453         $this->assertPostHasTerms( $post_id, array( $t2_updated['term_id'] ), 'post_tag' );
    454         $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );
    455 
    456         // clean up
    457         unset( $GLOBALS['wp_taxonomies'][ $random_tax ] );
    458     }
    459 
    460     /**
    461415     * @ticket 17646
    462416     */
     
    495449
    496450        $this->assertEquals( $expected_term_ids, $assigned_term_ids );
    497     }
    498 
    499     /**
    500      * @ticket 24189
    501      */
    502     function test_object_term_cache_when_term_changes() {
    503         $post_id = $this->factory->post->create();
    504         $tag_id = $this->factory->tag->create( array( 'description' => 'My Amazing Tag' ) );
    505 
    506         $tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' );
    507 
    508         $terms = get_the_terms( $post_id, 'post_tag' );
    509         $this->assertEquals( $tag_id, $terms[0]->term_id );
    510         $this->assertEquals( 'My Amazing Tag', $terms[0]->description );
    511 
    512         $_updated = wp_update_term( $tag_id, 'post_tag', array(
    513             'description' => 'This description is even more amazing!'
    514         ) );
    515 
    516         $_new_term = get_term( $tag_id, 'post_tag' );
    517         $this->assertEquals( $tag_id, $_new_term->term_id );
    518         $this->assertEquals( 'This description is even more amazing!', $_new_term->description );
    519 
    520         $terms = get_the_terms( $post_id, 'post_tag' );
    521         $this->assertEquals( $tag_id, $terms[0]->term_id );
    522         $this->assertEquals( 'This description is even more amazing!', $terms[0]->description );
    523451    }
    524452
  • branches/3.8/tests/phpunit/tests/user.php

    r30433 r47338  
    146146    }
    147147
    148     /**
    149      * Test the magic __unset method
    150      *
    151      * @ticket 20043
    152      */
    153     public function test_user_unset() {
    154         // New user
    155         $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    156         $user = new WP_User( $user_id );
    157 
    158         // Test custom fields
    159         $user->customField = 123;
    160         $this->assertEquals( $user->customField, 123 );
    161         unset( $user->customField );
    162         $this->assertFalse( isset( $user->customField ) );
    163         return $user;
    164     }
    165 
    166     /**
    167      * @depends test_user_unset
    168      * @expectedDeprecated WP_User->id
    169      * @ticket 20043
    170      */
    171     function test_user_unset_lowercase_id( $user ) {
    172         // Test 'id' (lowercase)
    173         unset( $user->id );
    174         return $user;
    175     }
    176 
    177     /**
    178      * @depends test_user_unset_lowercase_id
    179      * @ticket 20043
    180      */
    181     function test_user_unset_uppercase_id( $user ) {
    182         // Test 'ID'
    183         $this->assertNotEmpty( $user->ID );
    184         unset( $user->ID );
    185         $this->assertEmpty( $user->ID );
    186     }
    187 
    188148    // Test meta property magic functions for property get/set/isset.
    189149    function test_user_meta_properties() {
  • branches/3.8/tests/phpunit/tests/xmlrpc/wp/uploadFile.php

    r25002 r47338  
    3030    }
    3131
    32     /**
    33      * @ticket 21292
    34      */
    35     function test_network_limit() {
    36         $this->make_user_by_role( 'editor' );
    37 
    38         update_option( 'blog_upload_space', 0.1 );
    39 
    40         // create attachment
    41         $filename = ( DIR_TESTDATA . '/images/canola.jpg' );
    42         $contents = file_get_contents( $filename );
    43         $data = array(
    44             'name' => 'canola.jpg',
    45             'type' => 'image/jpeg',
    46             'bits' => $contents
    47         );
    48 
    49         $result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) );
    50 
    51         // Only multisite should have a limit
    52         if ( is_multisite() )
    53             $this->assertInstanceOf( 'IXR_Error', $result );
    54         else
    55             $this->assertNotInstanceOf( 'IXR_Error', $result );
    56     }
    57 
    58     /**
    59      * @ticket 11946
    60      */
    61     function test_valid_mime() {
    62         $this->make_user_by_role( 'editor' );
    63 
    64         // create attachment
    65         $filename = ( DIR_TESTDATA . '/images/test-image-mime-jpg.png' );
    66         $contents = file_get_contents( $filename );
    67         $data = array(
    68             'name' => 'test-image-mime-jpg.png',
    69             'type' => 'image/png',
    70             'bits' => $contents
    71         );
    72 
    73         $result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) );
    74 
    75         $this->assertNotInstanceOf( 'IXR_Error', $result );
    76 
    77         $this->assertEquals( 'image/jpeg', $result['type'] );
    78     }
    7932}
Note: See TracChangeset for help on using the changeset viewer.