Changeset 47343
- Timestamp:
- 02/22/2020 12:05:12 PM (5 years ago)
- Location:
- branches/3.7
- Files:
-
- 2 added
- 7 deleted
- 66 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.7
- Property svn:mergeinfo changed
-
branches/3.7/Gruntfile.js
r25693 r47343 65 65 dest: BUILD_DIR, 66 66 src: [] 67 }, 68 qunit: { 69 src: 'tests/qunit/index.html', 70 dest: 'tests/qunit/compiled.html', 71 options: { 72 processContent: function( src ) { 73 return src.replace( /([^\.])*\.\.\/src/ig , '/../build' ); 74 } 75 } 67 76 } 68 77 }, … … 83 92 qunit: { 84 93 files: ['tests/qunit/**/*.html'] 94 }, 95 phpunit: { 96 'default': { 97 cmd: 'phpunit', 98 args: ['-c', 'phpunit.xml.dist'] 99 }, 100 ajax: { 101 cmd: 'phpunit', 102 args: ['-c', 'phpunit.xml.dist', '--group', 'ajax'] 103 }, 104 multisite: { 105 cmd: 'phpunit', 106 args: ['-c', 'tests/phpunit/multisite.xml'] 107 } 85 108 }, 86 109 uglify: { … … 184 207 'uglify:tinymce', 'concat:tinymce', 'compress:tinymce', 'clean:tinymce']); 185 208 186 // Testing task. 187 grunt.registerTask('test', ['qunit']); 209 // Testing tasks. 210 grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax and multisite tests.', function() { 211 grunt.util.spawn({ 212 cmd: this.data.cmd, 213 args: this.data.args, 214 opts: {stdio: 'inherit'} 215 }, this.async()); 216 }); 217 218 grunt.registerTask('qunit:compiled', 'Runs QUnit tests on compiled as well as uncompiled scripts.', 219 ['build', 'copy:qunit', 'qunit']); 220 221 grunt.registerTask('test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit']); 222 223 // Travis CI tasks. 224 grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', 'phpunit'); 188 225 189 226 // Default task. -
branches/3.7/package.json
r46936 r47343 12 12 "grunt": "~0.4.1", 13 13 "grunt-contrib-clean": "~0.5.0", 14 "grunt-contrib-compress": "~0.5.2", 15 "grunt-contrib-concat": "~0.3.0", 14 16 "grunt-contrib-copy": "~0.4.1", 15 17 "grunt-contrib-cssmin": "~0.6.1", … … 17 19 "grunt-contrib-uglify": "~0.2.2", 18 20 "grunt-contrib-watch": "~0.5.1", 19 "grunt-contrib-compress": "~0.5.2",20 "grunt-contrib-concat": "~0.3.0",21 21 "matchdep": "~0.1.2" 22 22 } -
branches/3.7/phpunit.xml.dist
r25165 r47343 26 26 <log type="junit" target="tests/phpunit/build/logs/junit.xml" logIncompleteSkipped="false"/> 27 27 </logging> 28 <php> 29 <const name="WP_RUN_CORE_TESTS" value="1" /> 30 </php> 28 31 </phpunit> -
branches/3.7/src
- Property svn:mergeinfo changed
/trunk/src merged: 26252,26307,26512
- Property svn:mergeinfo changed
-
branches/3.7/src/wp-admin/includes/upgrade.php
r32435 r47343 1645 1645 1646 1646 // Fetch the table column structure from the database 1647 $ wpdb->suppress_errors();1647 $suppress = $wpdb->suppress_errors(); 1648 1648 $tablefields = $wpdb->get_results("DESCRIBE {$table};"); 1649 $wpdb->suppress_errors( false);1649 $wpdb->suppress_errors( $suppress ); 1650 1650 1651 1651 if ( ! $tablefields ) -
branches/3.7/src/wp-includes/meta.php
r25583 r47343 559 559 560 560 // Get meta info 561 $id_list = join( ',', $ids);562 $ meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",563 $meta_type), ARRAY_A );561 $id_list = join( ',', $ids ); 562 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 563 $meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A ); 564 564 565 565 if ( !empty($meta_list) ) { -
branches/3.7/src/wp-includes/ms-functions.php
r39806 r47343 1131 1131 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 1132 1132 1133 $ wpdb->suppress_errors();1133 $suppress = $wpdb->suppress_errors(); 1134 1134 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) 1135 1135 die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); 1136 $wpdb->suppress_errors( false);1136 $wpdb->suppress_errors( $suppress ); 1137 1137 1138 1138 $url = get_blogaddress_by_id( $blog_id ); … … 1181 1181 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 1182 1182 1183 $ wpdb->suppress_errors();1183 $suppress = $wpdb->suppress_errors(); 1184 1184 1185 1185 wp_install_defaults($user_id); 1186 1186 1187 $wpdb->suppress_errors( false);1187 $wpdb->suppress_errors( $suppress ); 1188 1188 } 1189 1189 -
branches/3.7/src/wp-includes/wp-db.php
r42241 r47343 1259 1259 1260 1260 if ( WP_DEBUG ) { 1261 $error_reporting = false; 1262 if ( defined( 'E_DEPRECATED' ) ) { 1263 $error_reporting = error_reporting(); 1264 error_reporting( $error_reporting ^ E_DEPRECATED ); 1265 } 1261 1266 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); 1267 if ( false !== $error_reporting ) { 1268 error_reporting( $error_reporting ); 1269 } 1262 1270 } else { 1263 1271 $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); -
branches/3.7/tests/phpunit/includes/bootstrap.php
r25415 r47343 96 96 * A child class of the PHP test runner. 97 97 * 98 * Not actually used as a runner. Rather, used to access the protected99 * longOptions property, to parse the argumentspassed to the script.98 * Used to access the protected longOptions property, to parse the arguments 99 * passed to the script. 100 100 * 101 101 * If it is determined that phpunit was called with a --group that corresponds … … 106 106 * how you call phpunit has no effect. 107 107 */ 108 class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command { 108 class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt { 109 protected $longOptions = array( 110 'exclude-group=', 111 'group=', 112 ); 109 113 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 115 129 $ajax_message = true; 116 foreach ( $options [0]as $option ) {130 foreach ( $options as $option ) { 117 131 switch ( $option[0] ) { 118 132 case '--exclude-group' : … … 122 136 $groups = explode( ',', $option[1] ); 123 137 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 ) ) { 125 139 WP_UnitTestCase::forceTicket( $group ); 140 } 126 141 } 127 142 $ajax_message = ! in_array( 'ajax', $groups ); … … 129 144 } 130 145 } 131 if ( $ajax_message ) 146 if ( $ajax_message ) { 132 147 echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL; 148 } 133 149 } 134 150 } 135 new WP_PHPUnit_ TextUI_Command( $_SERVER['argv'] );151 new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); -
branches/3.7/tests/phpunit/includes/factory.php
r25660 r47343 160 160 161 161 function create_object( $args ) { 162 global $wpdb; 162 163 $meta = isset( $args['meta'] ) ? $args['meta'] : array(); 163 164 $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); 164 return wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] ); 165 // temp tables will trigger db errors when we attempt to reference them as new temp tables 166 $suppress = $wpdb->suppress_errors(); 167 $blog = wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] ); 168 $wpdb->suppress_errors( $suppress ); 169 return $blog; 165 170 } 166 171 -
branches/3.7/tests/phpunit/includes/install.php
r25002 r47343 22 22 require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 23 23 require_once ABSPATH . '/wp-includes/wp-db.php'; 24 25 define( 'WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version' );26 27 $wpdb->suppress_errors();28 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );29 $wpdb->suppress_errors( false );30 31 $hash = get_option( 'db_version' ) . ' ' . (int) $multisite . ' ' . sha1_file( $config_file_path );32 33 if ( $installed && file_exists( WP_TESTS_VERSION_FILE ) && file_get_contents( WP_TESTS_VERSION_FILE ) == $hash )34 return;35 24 36 25 $wpdb->query( 'SET storage_engine = INNODB' ); … … 64 53 populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install ); 65 54 } 66 67 file_put_contents( WP_TESTS_VERSION_FILE, $hash ); -
branches/3.7/tests/phpunit/includes/testcase.php
r42068 r47343 12 12 protected $caught_doing_it_wrong = array(); 13 13 14 protected static $hooks_saved = array(); 15 protected static $ignore_files; 16 14 17 /** 15 18 * @var WP_UnitTest_Factory … … 19 22 function setUp() { 20 23 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 } 21 32 22 33 global $wpdb; … … 27 38 $this->factory = new WP_UnitTest_Factory; 28 39 $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 29 52 $this->start_transaction(); 30 53 $this->expectDeprecated(); 31 54 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(); 32 83 } 33 84 … … 36 87 $this->expectedDeprecated(); 37 88 $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' ) ); 39 95 remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); 40 96 remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); 97 $this->_restore_hooks(); 98 wp_set_current_user( 0 ); 41 99 } 42 100 … … 47 105 } 48 106 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 49 166 function flush_cache() { 50 167 global $wp_object_cache; … … 65 182 $wpdb->query( 'SET autocommit = 0;' ); 66 183 $wpdb->query( 'START TRANSACTION;' ); 67 add_filter( ' dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );184 add_filter( 'query', array( $this, '_create_temporary_tables' ) ); 68 185 add_filter( 'query', array( $this, '_drop_temporary_tables' ) ); 69 186 } 70 187 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; 73 192 } 74 193 75 194 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 ); 78 197 return $query; 79 198 } … … 213 332 protected function checkRequirements() { 214 333 parent::checkRequirements(); 334 335 // Core tests no longer check against open Trac tickets, but others using WP_UnitTestCase may do so. 336 if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { 337 return; 338 } 339 215 340 if ( WP_TESTS_FORCE_KNOWN_BUGS ) 216 341 return; … … 237 362 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) 238 363 return; 239 if ( ! TracTickets::isTracTicketClosed( 'http ://core.trac.wordpress.org', $ticket_id ) )364 if ( ! TracTickets::isTracTicketClosed( 'https://core.trac.wordpress.org', $ticket_id ) ) 240 365 $this->markTestSkipped( sprintf( 'WordPress Ticket #%d is not fixed', $ticket_id ) ); 241 366 } … … 247 372 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'UT' . $ticket_id, self::$forced_tickets ) ) 248 373 return; 249 if ( ! TracTickets::isTracTicketClosed( 'http ://unit-tests.trac.wordpress.org', $ticket_id ) )374 if ( ! TracTickets::isTracTicketClosed( 'https://unit-tests.trac.wordpress.org', $ticket_id ) ) 250 375 $this->markTestSkipped( sprintf( 'Unit Tests Ticket #%d is not fixed', $ticket_id ) ); 251 376 } … … 257 382 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) 258 383 return; 259 if ( ! TracTickets::isTracTicketClosed( 'http ://plugins.trac.wordpress.org', $ticket_id ) )384 if ( ! TracTickets::isTracTicketClosed( 'https://plugins.trac.wordpress.org', $ticket_id ) ) 260 385 $this->markTestSkipped( sprintf( 'WordPress Plugin Ticket #%d is not fixed', $ticket_id ) ); 261 386 } … … 291 416 return tempnam( $tmp_dir, 'wpunit' ); 292 417 } 418 419 function unlink( $file ) { 420 $exists = is_file( $file ); 421 if ( $exists && ! in_array( $file, self::$ignore_files ) ) { 422 //error_log( $file ); 423 unlink( $file ); 424 } elseif ( ! $exists ) { 425 $this->fail( "Trying to delete a file that doesn't exist: $file" ); 426 } 427 } 428 429 function rmdir( $path ) { 430 $files = $this->files_in_dir( $path ); 431 foreach ( $files as $file ) { 432 if ( ! in_array( $file, self::$ignore_files ) ) { 433 $this->unlink( $file ); 434 } 435 } 436 } 437 438 function remove_added_uploads() { 439 // Remove all uploads. 440 $uploads = wp_upload_dir(); 441 $this->rmdir( $uploads['basedir'] ); 442 } 443 444 function files_in_dir( $dir ) { 445 $files = array(); 446 447 $iterator = new RecursiveDirectoryIterator( $dir ); 448 $objects = new RecursiveIteratorIterator( $iterator ); 449 foreach ( $objects as $name => $object ) { 450 if ( is_file( $name ) ) { 451 $files[] = $name; 452 } 453 } 454 455 return $files; 456 } 457 458 function scan_user_uploads() { 459 static $files = array(); 460 if ( ! empty( $files ) ) { 461 return $files; 462 } 463 464 $uploads = wp_upload_dir(); 465 $files = $this->files_in_dir( $uploads['basedir'] ); 466 return $files; 467 } 293 468 } -
branches/3.7/tests/phpunit/includes/trac.php
r25002 r47343 15 15 */ 16 16 public static function isTracTicketClosed( $trac_url, $ticket_id ) { 17 if ( ! extension_loaded( 'openssl' ) ) { 18 $trac_url = preg_replace( "/^https:/", "http:", $trac_url ); 19 } 20 17 21 if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) { 18 22 // In case you're running the tests offline, keep track of open tickets. -
branches/3.7/tests/phpunit/includes/utils.php
r32188 r47343 335 335 } 336 336 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 349 337 /** 350 338 * Removes the post type and its taxonomy associations. -
branches/3.7/tests/phpunit/multisite.xml
r25294 r47343 26 26 </exclude> 27 27 </groups> 28 <php> 29 <const name="WP_RUN_CORE_TESTS" value="1" /> 30 </php> 28 31 </phpunit> -
branches/3.7/tests/phpunit/tests/ajax/DeleteComment.php
r25002 r47343 27 27 public function setUp() { 28 28 parent::setUp(); 29 $post_id = $this->factory->post->create(); 29 $_SERVER['SERVER_NAME'] = 'example.com'; 30 add_filter( 'comment_notification_recipients', '__return_empty_array' ); 31 $user_id = $this->factory->user->create(); 32 $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) ); 30 33 $this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 ); 31 34 $this->_comments = array_map( 'get_comment', $this->_comments ); -
branches/3.7/tests/phpunit/tests/ajax/DimComment.php
r25002 r47343 27 27 public function setUp() { 28 28 parent::setUp(); 29 $post_id = $this->factory->post->create(); 29 $_SERVER['SERVER_NAME'] = 'example.com'; 30 add_filter( 'comment_notification_recipients', '__return_empty_array' ); 31 $user_id = $this->factory->user->create(); 32 $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) ); 30 33 $this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 ); 31 34 $this->_comments = array_map( 'get_comment', $this->_comments ); -
branches/3.7/tests/phpunit/tests/ajax/MediaEdit.php
r25002 r47343 33 33 public function tearDown() { 34 34 // 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 ); 37 37 } 38 38 39 $uploads = wp_upload_dir();40 foreach ( scandir( $uploads['basedir'] ) as $file )41 _rmdir( $uploads['basedir'] . '/' . $file );42 43 39 parent::tearDown(); 44 40 } -
branches/3.7/tests/phpunit/tests/ajax/ReplytoComment.php
r25433 r47343 33 33 public function setUp() { 34 34 parent::setUp(); 35 $post_id = $this->factory->post->create(); 35 $_SERVER['SERVER_NAME'] = 'example.com'; 36 add_filter( 'comment_notification_recipients', '__return_empty_array' ); 37 $user_id = $this->factory->user->create(); 38 $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) ); 36 39 $this->factory->comment->create_post_comments( $post_id, 5 ); 37 40 $this->_comment_post = get_post( $post_id ); -
branches/3.7/tests/phpunit/tests/basic.php
r32151 r47343 21 21 function test_true() { 22 22 $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." ); 23 44 } 24 45 -
branches/3.7/tests/phpunit/tests/canonical.php
r32151 r47343 20 20 21 21 function setUp() { 22 global $wp_rewrite; 23 22 24 parent::setUp(); 23 25 26 update_option( 'page_comments', true ); 24 27 update_option( 'comments_per_page', 5 ); 25 28 update_option( 'posts_per_page', 5 ); 26 29 27 update_option( 'permalink_structure', $this->structure ); 30 $wp_rewrite->init(); 31 $wp_rewrite->set_permalink_structure( $this->structure ); 32 28 33 create_initial_taxonomies(); 29 $GLOBALS['wp_rewrite']->init(); 30 flush_rewrite_rules();34 35 $wp_rewrite->flush_rules(); 31 36 32 37 $this->old_current_user = get_current_user_id(); … … 80 85 81 86 function tearDown() { 87 global $wp_rewrite; 82 88 wp_set_current_user( $this->old_current_user ); 83 89 84 $ GLOBALS['wp_rewrite']->init();90 $wp_rewrite->init(); 85 91 parent::tearDown(); 86 92 } … … 168 174 // Categories 169 175 170 array( '?cat=%d', '/category/parent/', 15256 ),171 array( '?cat=%d', '/category/parent/child-1/', 15256 ),172 176 array( '?cat=%d', '/category/parent/child-1/child-2/' ), // no children 173 177 array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ), … … 175 179 array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ), 176 180 array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ), 177 array( '/category/child-1/', '/category/parent/child-1/', 18734 ),178 array( '/category/foo/child-1/', '/category/parent/child-1/', 18734 ),179 181 180 182 // Categories & Intersections with other vars … … 186 188 187 189 // Categories with Dates 188 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 ), 189 // array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ), 190 array( '/2008/04/?cat=1', array( 'url' => '/category/uncategorized/?year=2008&monthnum=04', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ), 190 array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ), 191 191 // array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ), 192 array( '/2008/?category_name=cat-a', array( 'url' => '/category/cat-a/?year=2008', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 20386 ),193 // array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),194 array( '/category/uncategorized/?year=2008', array( 'url' => '/category/uncategorized/?year=2008', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),195 192 196 193 // Pages 197 array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'198 array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),199 194 array( '/child-page-1/', '/parent-page/child-page-1/'), 200 195 array( '/?page_id=144', '/parent-page/child-page-1/'), … … 216 211 217 212 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 ?! 218 array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/', 11694 ), // post with 4 pages219 213 array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ), 220 214 array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ), 221 215 222 216 // Comments 223 array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/', 20388 ), 224 array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages 225 array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages 217 array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/' ), 226 218 227 219 // Attachments … … 246 238 array( '/?author=%d', '/author/canonical-author/' ), 247 239 // array( '/?author=%d&year=2008', '/2008/?author=3'), 248 array( '/?author=%d&year=2008', '/author/canonical-author/?year=2008', 17661 ),249 240 // array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase. 250 array( '/author/canonical-author/?year=2008', '/author/canonical-author/?year=2008', 17661 ),251 241 252 242 // Feeds -
branches/3.7/tests/phpunit/tests/canonical/customRules.php
r25002 r47343 30 30 array( '/ccr/uncategorized/sort/asc/', array( 'url' => '/ccr/uncategorized/sort/asc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'asc' ) ) ), 31 31 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 ),33 32 ); 34 33 } -
branches/3.7/tests/phpunit/tests/canonical/pageOnFront.php
r25002 r47343 16 16 update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) ); 17 17 $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(); 19 25 } 20 26 -
branches/3.7/tests/phpunit/tests/dependencies/scripts.php
r25002 r47343 85 85 $wp_scripts->base_url = $base_url_backup; 86 86 } 87 88 /**89 * @ticket 2222990 */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 2222998 */99 function test_json_encode_should_not_encode_special_literal_values() {100 $literal = new WP_JS_Literal( 'baba()' );101 $this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );102 }103 104 /**105 * @ticket 22229106 */107 function test_json_encode_should_not_encode_special_literal_values_with_dependencies() {108 $literal = new WP_JS_Literal( 'baba()', array( 'dep0', 'dep1' ) );109 $this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );110 }111 87 } -
branches/3.7/tests/phpunit/tests/feed/rss2.php
r25002 r47343 111 111 112 112 // 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'] ); 115 116 116 117 // categories (perhaps multiple) 117 118 $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); 119 120 if (empty($cat_ids)) $cat_ids = array(1); 120 121 // should be the same number of categories -
branches/3.7/tests/phpunit/tests/filters.php
r25377 r47343 250 250 return $tag; 251 251 } 252 253 /**254 * @ticket 21169255 */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 }270 252 } -
branches/3.7/tests/phpunit/tests/formatting/EscUrl.php
r25002 r47343 64 64 65 65 /** 66 * @ticket 1685967 */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&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) );71 //IPv6 addresses in urls - RFC273272 $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 /**78 66 * @ticket 21974 79 67 */ -
branches/3.7/tests/phpunit/tests/formatting/MakeClickable.php
r25264 r47343 324 324 $this->assertEquals( $in, $out ); 325 325 } 326 327 /**328 * @ticket 16859329 */330 function test_square_brackets() {331 $urls_before = array(332 'http://example.com/?foo[bar]=baz',333 'http://example.com/?baz=bar&foo[bar]=baz',334 );335 $urls_expected = array(336 '<a href="http://example.com/?foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?foo%5Bbar%5D=baz</a>',337 '<a href="http://example.com/?baz=bar&foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?baz=bar&foo%5Bbar%5D=baz</a>',338 );339 foreach ($urls_before as $key => $url) {340 $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );341 }342 }343 326 } -
branches/3.7/tests/phpunit/tests/formatting/MapDeep.php
r25002 r47343 5 5 */ 6 6 class Tests_Formatting_MapDeep extends WP_UnitTestCase { 7 function setUp() { 8 if ( ! function_exists( 'map_deep' ) ) { 9 $this->markTestSkipped( "map_deep function doesn't exist" ); 10 } 11 12 parent::setUp(); 13 } 14 7 15 function test_map_deep_with_any_function_over_empty_array_should_return_empty_array() { 8 16 $this->assertEquals( array(), map_deep( array( $this, 'return_baba' ), array() ) ); -
branches/3.7/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php
r25002 r47343 34 34 function test_handles_non_entity_ampersands() { 35 35 $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull")); 36 }37 38 /**39 * @ticket 1082340 */41 function test_strips_entities() {42 $this->assertEquals("no-entities-here", sanitize_title_with_dashes("No Entities – Here &"));43 $this->assertEquals("one-two", sanitize_title_with_dashes("One & Two", '', 'save'));44 $this->assertEquals("one-two", sanitize_title_with_dashes("One { 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 && 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'));50 36 } 51 37 -
branches/3.7/tests/phpunit/tests/formatting/SanitizeUser.php
r25002 r47343 10 10 $this->assertEquals($expected, sanitize_user($input)); 11 11 } 12 /**13 * @ticket 1082314 */15 function test_strips_entities() {16 $this->assertEquals("ATT", sanitize_user("AT&T"));17 $this->assertEquals("ATT Test;", sanitize_user("AT&T Test;"));18 $this->assertEquals("AT&T Test;", sanitize_user("AT&T Test;"));19 }20 12 function test_strips_percent_encoded_octets() { 21 13 $expected = is_multisite() ? 'franois' : 'Franois'; -
branches/3.7/tests/phpunit/tests/functions.php
r25313 r47343 132 132 } 133 133 134 /**135 * @ticket 9930136 */137 134 function test_is_serialized() { 138 135 $cases = array( … … 143 140 serialize(25), 144 141 serialize(1.1), 145 serialize(2.1E+200),146 142 serialize('this string will be serialized'), 147 143 serialize("a\nb"), … … 156 152 'a string', 157 153 'garbage:a:0:garbage;', 158 'b:4;',159 154 's:4:test;' 160 155 ); -
branches/3.7/tests/phpunit/tests/functions/deprecated.php
r25409 r47343 149 149 wp_save_image_file( $file, $img, 'image/jpeg', 1 ); 150 150 imagedestroy( $img ); 151 @unlink($file);151 unlink( $file ); 152 152 153 153 // Check if the arg was deprecated … … 170 170 wp_save_image_file( $file, $img, 'image/jpeg', 1 ); 171 171 unset( $img ); 172 @unlink($file);172 unlink( $file ); 173 173 174 174 // Check if the arg was deprecated -
branches/3.7/tests/phpunit/tests/http/base.php
r25224 r47343 285 285 $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) ); 286 286 } 287 288 287 288 289 289 } -
branches/3.7/tests/phpunit/tests/http/functions.php
r25002 r47343 6 6 */ 7 7 class 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 8 16 function test_head_request() { 9 17 // 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'; 11 19 $response = wp_remote_head( $url ); 12 20 $headers = wp_remote_retrieve_headers( $response ); … … 20 28 function test_head_redirect() { 21 29 // 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'; 23 31 $response = wp_remote_head( $url ); 24 32 $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) ); … … 26 34 27 35 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'; 29 37 $headers = wp_remote_head( $url ); 30 38 … … 34 42 35 43 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'; 37 45 $file = tempnam('/tmp', 'testfile'); 38 46 … … 52 60 function test_get_redirect() { 53 61 // 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'; 55 63 $file = tempnam('/tmp', 'testfile'); 56 64 … … 70 78 function test_get_redirect_limit_exceeded() { 71 79 // 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'; 73 81 $file = tempnam('/tmp', 'testfile'); 74 82 // pretend we've already redirected 5 times -
branches/3.7/tests/phpunit/tests/image/base.php
r25002 r47343 10 10 */ 11 11 public function setUp() { 12 parent::setUp(); 13 12 14 if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) { 13 15 $this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) ); … … 21 23 */ 22 24 public function tearDown() { 25 parent::tearDown(); 26 23 27 remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 ); 28 parent::tearDown(); 24 29 } 25 30 … … 34 39 /** 35 40 * Helper assertion for testing alpha on images 36 * 41 * 37 42 * @param string $image_path 38 43 * @param array $point array(x,y) -
branches/3.7/tests/phpunit/tests/image/editor_gd.php
r25002 r47343 7 7 * @group wp-image-editor-gd 8 8 */ 9 require_once( dirname( __FILE__ ) . '/base.php' ); 9 10 10 11 class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { … … 14 15 require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 15 16 require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' ); 17 16 18 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(); 17 31 } 18 32 … … 135 149 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 136 150 151 unlink( $save_to_file ); 137 152 } 138 153 … … 154 169 155 170 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 171 172 unlink( $save_to_file ); 156 173 } 157 174 -
branches/3.7/tests/phpunit/tests/image/editor_imagick.php
r25002 r47343 7 7 * @group wp-image-editor-imagick 8 8 */ 9 require_once( dirname( __FILE__ ) . '/base.php' ); 9 10 10 11 class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { … … 22 23 23 24 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(); 24 37 } 25 38 … … 143 156 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 144 157 158 unlink( $save_to_file ); 145 159 } 146 160 … … 158 172 159 173 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 160 174 161 175 $editor->save( $save_to_file ); 162 176 163 177 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 178 179 unlink( $save_to_file ); 164 180 } 165 181 } -
branches/3.7/tests/phpunit/tests/image/functions.php
r25409 r47343 31 31 $finfo = new finfo(); 32 32 $mime_type = $finfo->file( $filename, FILEINFO_MIME ); 33 } elseif ( function_exists('mime_content_type') ) {34 $mime_type = mime_content_type( $filename );35 33 } 36 34 if ( false !== strpos( $mime_type, ';' ) ) { … … 91 89 $files = array( 92 90 // 'test-image-cmyk.jpg', Allowed in r9727 93 'test-image.bmp',91 // 'test-image.bmp', Allowed in r28589 94 92 // 'test-image-grayscale.jpg', Allowed in r9727 95 93 'test-image.pct', … … 113 111 */ 114 112 public function test_wp_save_image_file() { 113 if ( ! extension_loaded( 'fileinfo' ) ) { 114 $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); 115 } 116 115 117 include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); 116 118 … … 143 145 144 146 // Clean up 145 @unlink( $file );146 @unlink( $ret['path'] );147 unlink( $file ); 148 unlink( $ret['path'] ); 147 149 } 148 150 … … 157 159 */ 158 160 public function test_mime_overrides_filename() { 161 if ( ! extension_loaded( 'fileinfo' ) ) { 162 $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); 163 } 159 164 160 165 // Test each image editor engine … … 181 186 182 187 // Clean up 183 @unlink( $file );184 @unlink( $ret['path'] );188 unlink( $file ); 189 unlink( $ret['path'] ); 185 190 unset( $img ); 186 191 } … … 192 197 */ 193 198 public function test_inferred_mime_types() { 199 if ( ! extension_loaded( 'fileinfo' ) ) { 200 $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); 201 } 194 202 195 203 // Mime types … … 224 232 $this->assertNotInstanceOf( 'WP_Error', $ret ); 225 233 $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); 226 @unlink( $file ); 227 @unlink( $ret['path'] ); 234 unlink( $ret['path'] ); 228 235 } 229 236 … … 284 291 $this->markTestSkipped( 'jpeg support unavailable' ); 285 292 286 $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', 287 298 0, 0, 100, 100, 100, 100, false, 288 299 DIR_TESTDATA . '/images/' . rand_str() . '.jpg' ); … … 304 315 305 316 public function test_wp_crop_image_url_not_exist() { 306 $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', 307 322 0, 0, 100, 100, 100, 100 ); 308 323 $this->assertInstanceOf( 'WP_Error', $file ); -
branches/3.7/tests/phpunit/tests/image/intermediate_size.php
r25507 r47343 1 1 <?php 2 3 2 /** 4 3 * @group image … … 7 6 */ 8 7 class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 8 function tearDown() { 9 $this->remove_added_uploads(); 10 parent::tearDown(); 11 } 12 9 13 function test_make_intermediate_size_no_size() { 10 14 $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false ); -
branches/3.7/tests/phpunit/tests/image/resize.php
r25002 r47343 5 5 * @group media 6 6 * @group upload 7 * @group resize 7 8 */ 9 require_once( dirname( __FILE__ ) . '/base.php' ); 10 8 11 abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase { 9 12 … … 109 112 $this->assertEquals( IMAGETYPE_JPEG, $type ); 110 113 111 unlink( $image);114 unlink( $image ); 112 115 } 113 116 … … 136 139 137 140 /** 138 * Try resizing a php file (bad image)139 * @ticket 6821140 */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 /**149 141 * Function to help out the tests 150 142 */ -
branches/3.7/tests/phpunit/tests/image/resize_gd.php
r25002 r47343 5 5 * @group media 6 6 * @group upload 7 * @group resize 7 8 */ 9 require_once( dirname( __FILE__ ) . '/resize.php' ); 10 8 11 class Test_Image_Resize_GD extends WP_Tests_Image_Resize_UnitTestCase { 9 12 … … 13 16 */ 14 17 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 15 37 } -
branches/3.7/tests/phpunit/tests/image/resize_imagick.php
r25002 r47343 5 5 * @group media 6 6 * @group upload 7 * @group resize 7 8 */ 9 require_once( dirname( __FILE__ ) . '/resize.php' ); 10 8 11 class Test_Image_Resize_Imagick extends WP_Tests_Image_Resize_UnitTestCase { 9 12 … … 13 16 */ 14 17 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 } 15 25 } -
branches/3.7/tests/phpunit/tests/l10n.php
r25407 r47343 17 17 $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) ); 18 18 } 19 20 /**21 * @ticket 2131922 */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 }31 19 } -
branches/3.7/tests/phpunit/tests/link.php
r25404 r47343 4 4 */ 5 5 class Tests_Link extends WP_UnitTestCase { 6 7 function tearDown() { 8 global $wp_rewrite; 9 $wp_rewrite->init(); 10 parent::tearDown(); 11 } 6 12 7 13 function _get_pagenum_link_cb( $url ) { … … 30 36 31 37 function test_wp_get_shortlink() { 38 global $wp_rewrite; 39 32 40 $post_id = $this->factory->post->create(); 33 41 $post_id2 = $this->factory->post->create(); 42 43 $wp_rewrite->init(); 44 $wp_rewrite->set_permalink_structure( '' ); 45 $wp_rewrite->flush_rules(); 34 46 35 47 // Basic case … … 60 72 $this->assertEquals( '', wp_get_shortlink() ); 61 73 62 global $wp_rewrite;63 $wp_rewrite->permalink_structure = '';64 74 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 65 75 $wp_rewrite->flush_rules(); … … 74 84 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) ); 75 85 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() ); 76 77 $wp_rewrite->set_permalink_structure( '' );78 $wp_rewrite->flush_rules();79 86 } 80 87 … … 87 94 88 95 global $wp_rewrite; 89 $wp_rewrite->permalink_structure = '';90 96 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 91 97 $wp_rewrite->flush_rules(); 92 98 93 99 $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();97 100 } 98 101 -
branches/3.7/tests/phpunit/tests/mail.php
r32151 r47343 70 70 $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0); 71 71 $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0); 72 }73 74 /**75 * @ticket 1544876 */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: 8bit90 91 Here is some plain text.92 93 94 --' . $boundry . '95 Content-Type: text/html; charset = "UTF-8"96 Content-Transfer-Encoding: 8bit97 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']);106 72 } 107 73 -
branches/3.7/tests/phpunit/tests/media.php
r39719 r47343 367 367 ); 368 368 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 ); 370 386 371 387 unset( $_FILES['upload'] ); … … 377 393 378 394 $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'] ); 379 405 } 380 406 -
branches/3.7/tests/phpunit/tests/meta.php
r25255 r47343 172 172 $this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) ); 173 173 } 174 175 function test_meta_cache_order_asc() { 176 $post_id = $this->factory->post->create(); 177 $colors = array( 'red', 'blue', 'yellow', 'green' ); 178 foreach ( $colors as $color ) 179 add_post_meta( $post_id, 'color', $color ); 180 181 foreach ( range( 1, 10 ) as $i ) { 182 $meta = get_post_meta( $post_id, 'color' ); 183 $this->assertEquals( $meta, $colors ); 184 185 if ( 0 === $i % 2 ) 186 wp_cache_delete( $post_id, 'post_meta' ); 187 } 188 } 174 189 } -
branches/3.7/tests/phpunit/tests/ms.php
r25621 r47343 10 10 class Tests_MS extends WP_UnitTestCase { 11 11 protected $plugin_hook_count = 0; 12 protected $suppress = false; 12 13 13 14 function setUp() { 15 global $wpdb; 14 16 parent::setUp(); 17 $this->suppress = $wpdb->suppress_errors(); 15 18 16 19 $_SERVER['REMOTE_ADDR'] = ''; 20 } 21 22 function tearDown() { 23 global $wpdb; 24 parent::tearDown(); 25 $wpdb->suppress_errors( $this->suppress ); 17 26 } 18 27 … … 106 115 107 116 foreach ( $wpdb->tables( 'blog', false ) as $table ) { 108 $ wpdb->suppress_errors();117 $suppress = $wpdb->suppress_errors(); 109 118 $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); 110 $wpdb->suppress_errors( false);119 $wpdb->suppress_errors( $suppress ); 111 120 $this->assertNotEmpty( $table_fields ); 112 121 $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" ); … … 140 149 $prefix = $wpdb->get_blog_prefix( $blog_id ); 141 150 foreach ( $wpdb->tables( 'blog', false ) as $table ) { 142 $ wpdb->suppress_errors();151 $suppress = $wpdb->suppress_errors(); 143 152 $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); 144 $wpdb->suppress_errors( false);153 $wpdb->suppress_errors( $suppress ); 145 154 if ( $drop_tables ) 146 155 $this->assertEmpty( $table_fields ); -
branches/3.7/tests/phpunit/tests/option/blogOption.php
r25397 r47343 6 6 */ 7 7 class Tests_Option_BlogOption extends WP_UnitTestCase { 8 protected $suppress = false; 9 8 10 function setUp() { 11 global $wpdb; 9 12 parent::setUp(); 13 $this->suppress = $wpdb->suppress_errors(); 10 14 11 15 $_SERVER['REMOTE_ADDR'] = null; 12 16 } 13 17 14 function test_from_same_site() { 15 $key = rand_str(); 16 $key2 = rand_str(); 17 $value = rand_str(); 18 $value2 = rand_str(); 19 20 $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) ); 21 $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() 22 23 $this->assertTrue( add_blog_option( 1, $key, $value ) ); 24 // Assert all values of $blog_id that means the current or main blog (the same here). 25 $this->assertEquals( $value, get_blog_option( 1, $key ) ); 26 $this->assertEquals( $value, get_blog_option( null, $key ) ); 27 $this->assertEquals( $value, get_blog_option( '1', $key ) ); 28 $this->assertEquals( $value, get_option( $key ) ); // check get_option() 29 30 $this->assertFalse( add_blog_option( 1, $key, $value ) ); // Already exists 31 $this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same 32 $this->assertTrue( update_blog_option( 1, $key, $value2 ) ); 33 $this->assertEquals( $value2, get_blog_option( 1, $key ) ); 34 $this->assertEquals( $value2, get_option( $key ) ); // check get_option() 35 $this->assertFalse( add_blog_option( 1, $key, $value ) ); 36 $this->assertEquals( $value2, get_blog_option( 1, $key ) ); 37 $this->assertEquals( $value2, get_option( $key ) ); // check get_option() 38 39 $this->assertTrue( delete_blog_option( 1, $key ) ); 40 $this->assertFalse( get_blog_option( 1, $key ) ); 41 $this->assertFalse( get_option( $key ) ); // check get_option() 42 $this->assertFalse( delete_blog_option( 1, $key ) ); 43 $this->assertTrue( update_blog_option( 1, $key2, $value2 ) ); 44 $this->assertEquals( $value2, get_blog_option( 1, $key2 ) ); 45 $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() 46 $this->assertTrue( delete_blog_option( 1, $key2 ) ); 47 $this->assertFalse( get_blog_option( 1, $key2 ) ); 48 $this->assertFalse( get_option( $key2 ) ); // check get_option() 49 } 50 51 function test_from_same_site_with_null_blog_id() { 52 $key = rand_str(); 53 $key2 = rand_str(); 54 $value = rand_str(); 55 $value2 = rand_str(); 56 57 $this->assertFalse( get_blog_option( null, 'doesnotexist' ) ); 58 $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() 59 60 $this->assertTrue( add_blog_option( null, $key, $value ) ); 61 // Assert all values of $blog_id that means the current or main blog (the same here). 62 $this->assertEquals( $value, get_blog_option( null, $key ) ); 63 $this->assertEquals( $value, get_blog_option( null, $key ) ); 64 $this->assertEquals( $value, get_option( $key ) ); // check get_option() 65 66 $this->assertFalse( add_blog_option( null, $key, $value ) ); // Already exists 67 $this->assertFalse( update_blog_option( null, $key, $value ) ); // Value is the same 68 $this->assertTrue( update_blog_option( null, $key, $value2 ) ); 69 $this->assertEquals( $value2, get_blog_option( null, $key ) ); 70 $this->assertEquals( $value2, get_option( $key ) ); // check get_option() 71 $this->assertFalse( add_blog_option( null, $key, $value ) ); 72 $this->assertEquals( $value2, get_blog_option( null, $key ) ); 73 $this->assertEquals( $value2, get_option( $key ) ); // check get_option() 74 75 $this->assertTrue( delete_blog_option( null, $key ) ); 76 $this->assertFalse( get_blog_option( null, $key ) ); 77 $this->assertFalse( get_option( $key ) ); // check get_option() 78 $this->assertFalse( delete_blog_option( null, $key ) ); 79 $this->assertTrue( update_blog_option( null, $key2, $value2 ) ); 80 $this->assertEquals( $value2, get_blog_option( null, $key2 ) ); 81 $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() 82 $this->assertTrue( delete_blog_option( null, $key2 ) ); 83 $this->assertFalse( get_blog_option( null, $key2 ) ); 84 $this->assertFalse( get_option( $key2 ) ); // check get_option() 18 function tearDown() { 19 global $wpdb; 20 parent::tearDown(); 21 $wpdb->suppress_errors( $this->suppress ); 85 22 } 86 23 -
branches/3.7/tests/phpunit/tests/post.php
r32188 r47343 447 447 448 448 global $wp_rewrite; 449 $wp_rewrite->init(); 449 450 $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); 451 $wp_rewrite->flush_rules(); 450 452 451 453 $post = array( … … 736 738 $this->assertEquals( $post->post_author, $this->author_id ); 737 739 $this->assertEquals( $post->post_title, $title ); 738 }739 740 /**741 * @ticket 19373742 */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 false759 $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 19373771 */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 set780 '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 false788 $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 in791 $this->assertInstanceOf( 'WP_Error', $insert_post_id );792 $this->assertEquals( 'empty_author', $insert_post_id->get_error_code() );793 740 } 794 741 -
branches/3.7/tests/phpunit/tests/post/attachments.php
r25002 r47343 10 10 function tearDown() { 11 11 // 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(); 16 13 parent::tearDown(); 17 14 } … … 212 209 } 213 210 214 /**215 * GUID should never be empty216 * @ticket 18310217 * @ticket 21963218 */219 function test_insert_image_without_guid() {220 // this image is smaller than the thumbnail size so it won't have one221 $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 234 211 } -
branches/3.7/tests/phpunit/tests/post/filtering.php
r25002 r47343 91 91 } 92 92 93 /**94 * make sure unbalanced tags are fixed when they span a --more-- tag95 * @ticket 629796 */97 function test_post_content_unbalanced_more() {98 $content = <<<EOF99 <em>some text<!--more-->100 that's continued after the jump</em>101 EOF;102 103 $expected = <<<EOF104 <em>some text</em><!--more-->105 that's continued after the jump106 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-- tag116 * @ticket 6297117 */118 function test_post_content_unbalanced_nextpage() {119 $content = <<<EOF120 <em>some text<!--nextpage-->121 that's continued after the jump</em>122 EOF;123 124 $expected = <<<EOF125 <em>some text</em><!--nextpage-->126 that's continued after the jump127 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 6297138 */139 function test_post_content_unbalanced_more_nextpage() {140 $content = <<<EOF141 <em>some text<!--more-->142 that's continued after the jump</em>143 <!--nextpage-->144 <p>and the next page145 <!--nextpage-->146 breaks the graf</p>147 EOF;148 149 $expected = <<<EOF150 <em>some text</em><!--more-->151 that's continued after the jump152 <!--nextpage-->153 <p>and the next page154 </p><!--nextpage-->155 breaks the graf156 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 6297167 */168 function test_post_content_unbalanced_nextpage_more() {169 $content = <<<EOF170 <em>some text<!--nextpage-->171 that's continued after the jump</em>172 <!--more-->173 <p>and the next page174 <!--nextpage-->175 breaks the graf</p>176 EOF;177 178 $expected = <<<EOF179 <em>some text</em><!--nextpage-->180 that's continued after the jump181 <!--more-->182 <p>and the next page183 </p><!--nextpage-->184 breaks the graf185 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 193 93 // make sure unbalanced tags are untouched when the balance option is off 194 94 function test_post_content_nobalance_nextpage_more() { -
branches/3.7/tests/phpunit/tests/post/revisions.php
r32151 r47343 54 54 55 55 wp_set_current_user( 0 ); 56 }57 58 /**59 * @ticket 739260 * @ticket 984361 */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 revision71 72 // First update73 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 far76 77 //update the post78 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision79 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far80 81 //next try to save another identical update, tests for patch that prevents storing duplicates82 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save83 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision84 85 //next try to save another update, same content, but new ttile, should save revision86 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 revision88 89 //next try to save another identical update90 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save91 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision92 56 } 93 57 -
branches/3.7/tests/phpunit/tests/query.php
r25601 r47343 2 2 3 3 class 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 } 4 16 5 17 /** -
branches/3.7/tests/phpunit/tests/query/conditionals.php
r32151 r47343 24 24 25 25 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 27 30 create_initial_taxonomies(); 28 $GLOBALS['wp_rewrite']->init(); 29 flush_rewrite_rules();31 32 $wp_rewrite->flush_rules(); 30 33 } 31 34 32 35 function tearDown() { 33 $GLOBALS['wp_rewrite']->init(); 36 global $wp_rewrite; 37 $wp_rewrite->init(); 38 34 39 parent::tearDown(); 35 40 } -
branches/3.7/tests/phpunit/tests/query/results.php
r25356 r47343 280 280 281 281 /** 282 * @ticket 18897283 */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 /**306 282 * @ticket 11056 307 283 */ -
branches/3.7/tests/phpunit/tests/query/verboseRewriteRules.php
r25002 r47343 9 9 class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals { 10 10 function setUp() { 11 global $wp_rewrite; 12 11 13 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 14 18 create_initial_taxonomies(); 15 $GLOBALS['wp_rewrite']->init(); 16 flush_rewrite_rules();19 20 $wp_rewrite->flush_rules(); 17 21 } 18 22 } -
branches/3.7/tests/phpunit/tests/rewrite.php
r32151 r47343 9 9 10 10 function setUp() { 11 global $wp_rewrite; 11 12 parent::setUp(); 12 13 13 14 // 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 16 18 create_initial_taxonomies(); 17 $GLOBALS['wp_rewrite']->init(); 18 flush_rewrite_rules();19 20 $wp_rewrite->flush_rules(); 19 21 } 20 22 21 23 function tearDown() { 22 $GLOBALS['wp_rewrite']->init(); 24 global $wp_rewrite; 25 $wp_rewrite->init(); 26 23 27 parent::tearDown(); 24 28 } … … 35 39 function test_url_to_postid_custom_post_type() { 36 40 delete_option( 'rewrite_rules' ); 37 41 38 42 $post_type = rand_str( 12 ); 39 43 register_post_type( $post_type, array( 'public' => true ) ); 40 44 41 45 $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 ); 45 49 } 46 50 47 51 function test_url_to_postid_hierarchical() { 48 52 -
branches/3.7/tests/phpunit/tests/shortcode.php
r33568 r47343 309 309 310 310 /** 311 * @ticket 14050312 */313 function test_multiple_shortcode_unautop() {314 // a blank line is added at the end, so test with it already there315 $test_string = "[footag]\n[footag]\n";316 $actual = shortcode_unautop( wpautop( $test_string ) );317 $this->assertEquals( $test_string, $actual );318 }319 320 /**321 311 * @ticket 10326 322 312 */ -
branches/3.7/tests/phpunit/tests/taxonomy.php
r25924 r47343 106 106 107 107 /** 108 * @ticket 11058109 */110 function test_registering_taxonomies_to_object_types() {111 // Create a taxonomy to test with112 $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 with117 $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 type122 $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 type127 $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 types133 $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 type137 $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 type142 $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 types148 $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 /**156 108 * @ticket 25706 157 109 */ -
branches/3.7/tests/phpunit/tests/term.php
r25551 r47343 388 388 } 389 389 390 /**391 * @ticket 5809392 */393 function test_update_shared_term() {394 $random_tax = __FUNCTION__;395 396 register_taxonomy( $random_tax, 'post' );397 398 $post_id = $this->factory->post->create();399 400 $old_name = 'Initial';401 402 $t1 = wp_insert_term( $old_name, 'category' );403 $t2 = wp_insert_term( $old_name, 'post_tag' );404 405 $this->assertEquals( $t1['term_id'], $t2['term_id'] );406 407 wp_set_post_categories( $post_id, array( $t1['term_id'] ) );408 wp_set_post_tags( $post_id, array( (int) $t2['term_id'] ) );409 410 $new_name = 'Updated';411 412 // create the term in a third taxonomy, just to keep things interesting413 $t3 = wp_insert_term( $old_name, $random_tax );414 wp_set_post_terms( $post_id, array( (int) $t3['term_id'] ), $random_tax );415 $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );416 417 $t2_updated = wp_update_term( $t2['term_id'], 'post_tag', array(418 'name' => $new_name419 ) );420 421 $this->assertNotEquals( $t2_updated['term_id'], $t3['term_id'] );422 423 // make sure the terms have split424 $this->assertEquals( $old_name, get_term_field( 'name', $t1['term_id'], 'category' ) );425 $this->assertEquals( $new_name, get_term_field( 'name', $t2_updated['term_id'], 'post_tag' ) );426 427 // and that they are still assigned to the correct post428 $this->assertPostHasTerms( $post_id, array( $t1['term_id'] ), 'category' );429 $this->assertPostHasTerms( $post_id, array( $t2_updated['term_id'] ), 'post_tag' );430 $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );431 432 // clean up433 unset( $GLOBALS['wp_taxonomies'][ $random_tax ] );434 }435 436 390 private function assertPostHasTerms( $post_id, $expected_term_ids, $taxonomy ) { 437 391 $assigned_term_ids = wp_get_object_terms( $post_id, $taxonomy, array( … … 440 394 441 395 $this->assertEquals( $expected_term_ids, $assigned_term_ids ); 442 }443 444 /**445 * @ticket 24189446 */447 function test_object_term_cache_when_term_changes() {448 $post_id = $this->factory->post->create();449 $tag_id = $this->factory->tag->create( array( 'description' => 'My Amazing Tag' ) );450 451 $tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' );452 453 $terms = get_the_terms( $post_id, 'post_tag' );454 $this->assertEquals( $tag_id, $terms[0]->term_id );455 $this->assertEquals( 'My Amazing Tag', $terms[0]->description );456 457 $_updated = wp_update_term( $tag_id, 'post_tag', array(458 'description' => 'This description is even more amazing!'459 ) );460 461 $_new_term = get_term( $tag_id, 'post_tag' );462 $this->assertEquals( $tag_id, $_new_term->term_id );463 $this->assertEquals( 'This description is even more amazing!', $_new_term->description );464 465 $terms = get_the_terms( $post_id, 'post_tag' );466 $this->assertEquals( $tag_id, $terms[0]->term_id );467 $this->assertEquals( 'This description is even more amazing!', $terms[0]->description );468 396 } 469 397 -
branches/3.7/tests/phpunit/tests/user.php
r30434 r47343 146 146 } 147 147 148 /**149 * Test the magic __unset method150 *151 * @ticket 20043152 */153 public function test_user_unset() {154 // New user155 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );156 $user = new WP_User( $user_id );157 158 // Test custom fields159 $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_unset168 * @expectedDeprecated WP_User->id169 * @ticket 20043170 */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_id179 * @ticket 20043180 */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 188 148 // Test meta property magic functions for property get/set/isset. 189 149 function test_user_meta_properties() { -
branches/3.7/tests/phpunit/tests/xmlrpc/wp/getPosts.php
r25002 r47343 52 52 )); 53 53 54 $post_ids = array(); 54 55 $num_posts = 17; 55 $post_ids = $this->factory->post->create_many( $num_posts, array( 'post_type' => $cpt_name ) ); 56 56 foreach ( range( 1, $num_posts ) as $i ) { 57 $post_ids[] = $this->factory->post->create( array( 58 'post_type' => $cpt_name, 59 'post_date' => date( 'Y-m-d H:i:s', time() + $i ) 60 ) ); 61 } 57 62 // get them all 58 63 $filter = array( 'post_type' => $cpt_name, 'number' => $num_posts + 10 ); … … 67 72 do { 68 73 $presults = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) ); 69 foreach( $presults as $post ) { 70 $posts_found[] = $post['post_id']; 71 } 74 $posts_found = array_merge( $posts_found, wp_list_pluck( $presults, 'post_id' ) ); 72 75 $filter['offset'] += $filter['number']; 73 76 } while ( count( $presults ) > 0 ); -
branches/3.7/tests/phpunit/tests/xmlrpc/wp/uploadFile.php
r25002 r47343 30 30 } 31 31 32 /**33 * @ticket 2129234 */35 function test_network_limit() {36 $this->make_user_by_role( 'editor' );37 38 update_option( 'blog_upload_space', 0.1 );39 40 // create attachment41 $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' => $contents47 );48 49 $result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) );50 51 // Only multisite should have a limit52 if ( is_multisite() )53 $this->assertInstanceOf( 'IXR_Error', $result );54 else55 $this->assertNotInstanceOf( 'IXR_Error', $result );56 }57 58 /**59 * @ticket 1194660 */61 function test_valid_mime() {62 $this->make_user_by_role( 'editor' );63 64 // create attachment65 $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' => $contents71 );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 }79 32 }
Note: See TracChangeset
for help on using the changeset viewer.