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.

git-svn-id: https://develop.svn.wordpress.org/branches/3.8@47338 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-02-21 13:05:39 +00:00
parent 03cccce414
commit 410959cd7e
64 changed files with 982 additions and 1953 deletions

View File

@ -1,26 +1,91 @@
# Travis CI Configuration File
sudo: false
dist: trusty
language: php
cache:
directories:
- $HOME/.npm
- vendor
- $HOME/.composer/cache
php:
- "5.5"
- "5.2"
# Build matrix options
matrix:
include:
- php: 5.5
env: WP_TRAVISCI=travis:js
- php: 5.5
env: WP_TRAVISCI=travis:phpunit
- php: 5.2
env: WP_TRAVISCI=travis:phpunit
dist: precise
fast_finish: true
# Before install, failures in this section will result in build status 'errored'
before_install:
- WP_CORE_DIR=/tmp/wordpress/
- >
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
mysql -e "CREATE DATABASE wordpress_tests;" -uroot
cp wp-tests-config-sample.php wp-tests-config.php
sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
sed -i "s/yourusernamehere/travis/" wp-tests-config.php
sed -i "s/yourpasswordhere//" wp-tests-config.php
svn checkout https://plugins.svn.wordpress.org/wordpress-importer/trunk tests/phpunit/data/plugins/wordpress-importer
fi
# Before script, failures in this section will result in build status 'failed'
before_script:
- |
stable='^[0-9\.]+$';
if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then
phpenv config-rm xdebug.ini
fi
- mysql -e "CREATE DATABASE wordpress_tests;" -uroot
- cp wp-tests-config-sample.php wp-tests-config.php
- sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
- sed -i "s/yourusernamehere/travis/" wp-tests-config.php
- sed -i "s/yourpasswordhere//" wp-tests-config.php
- svn checkout https://plugins.svn.wordpress.org/wordpress-importer/trunk tests/phpunit/data/plugins/wordpress-importer
- npm install -g grunt-cli
- npm install
- php --version
script: grunt test
- |
# Remove Xdebug for a huge performance increase, but not from nightly:
stable='^[0-9\.]+$'
if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then
phpenv config-rm xdebug.ini
fi
- |
# Export Composer's global bin dir to PATH, but not on PHP 5.2:
if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then
composer config --list --global
export PATH=`composer config --list --global | grep '\[home\]' | { read a; echo "${a#* }/vendor/bin:$PATH"; }`
fi
- |
# Install the specified version of PHPUnit depending on the PHP version:
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
case "$TRAVIS_PHP_VERSION" in
7.1|7.0|nightly)
echo "Using PHPUnit 5.x"
composer global require "phpunit/phpunit:^5"
;;
5.6|5.5|5.4|5.3)
echo "Using PHPUnit 4.x"
composer global require "phpunit/phpunit:^4"
;;
5.2)
# Do nothing, use default PHPUnit 3.6.x
echo "Using default PHPUnit, hopefully 3.6"
;;
*)
echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION"
exit 1
;;
esac
fi
- npm --version
- node --version
- nvm install 0.10.48
- npm install -g grunt-cli
- npm install
- npm prune
- php --version
- php -m
- npm --version
- node --version
- which phpunit
- phpunit --version
- curl --version
- grunt --version
- git --version
- svn --version
script: grunt $WP_TRAVISCI
notifications:
slack:
rooms:
@ -28,4 +93,3 @@ notifications:
on_start: never
on_failure: always
on_success: change
on_pull_requests: false

View File

@ -359,15 +359,18 @@ module.exports = function(grunt) {
// Register tasks.
// Copy task.
grunt.registerTask('copy:all', ['copy:files', 'copy:version']);
// RTL task.
grunt.registerTask('rtl', ['cssjanus:core', 'cssjanus:colors']);
// Color schemes task.
grunt.registerTask('colors', ['sass:colors']);
// JSHint task.
grunt.registerTask('jshint:corejs', ['jshint:grunt', 'jshint:tests', 'jshint:themes', 'jshint:core']);
// Copy task.
grunt.registerTask('copy:all', ['copy:files', 'copy:version']);
// Build task.
grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core', 'colors', 'rtl', 'cssmin:rtl', 'cssmin:colors',
'uglify:core', 'uglify:tinymce', 'concat:tinymce', 'compress:tinymce', 'clean:tinymce']);
@ -383,8 +386,13 @@ module.exports = function(grunt) {
grunt.registerTask('qunit:compiled', 'Runs QUnit tests on compiled as well as uncompiled scripts.',
['build', 'copy:qunit', 'qunit']);
grunt.registerTask('test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit']);
// Travis CI tasks.
grunt.registerTask('travis:js', 'Runs Javascript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]);
grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', 'phpunit');
// Default task.
grunt.registerTask('default', ['build']);

View File

@ -11,16 +11,16 @@
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-cssmin": "~0.6.1",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-qunit": "~0.2.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.7.0",
"grunt-cssjanus": "git://github.com/yoavf/grunt-cssjanus.git#e0158f4087d1c4bb5a8d1648a63ef133338b5879",
"grunt-sass": "~1.0.0",
"grunt-sass": "~0.16.0",
"matchdep": "~0.1.2"
}
}

View File

@ -25,4 +25,7 @@
<logging>
<log type="junit" target="tests/phpunit/build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
<php>
<const name="WP_RUN_CORE_TESTS" value="1" />
</php>
</phpunit>

View File

@ -95,8 +95,8 @@ require dirname( __FILE__ ) . '/utils.php';
/**
* A child class of the PHP test runner.
*
* Not actually used as a runner. Rather, used to access the protected
* longOptions property, to parse the arguments passed to the script.
* Used to access the protected longOptions property, to parse the arguments
* passed to the script.
*
* If it is determined that phpunit was called with a --group that corresponds
* to an @ticket annotation (such as `phpunit --group 12345` for bugs marked
@ -105,15 +105,29 @@ require dirname( __FILE__ ) . '/utils.php';
* If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then
* how you call phpunit has no effect.
*/
class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command {
class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
protected $longOptions = array(
'exclude-group=',
'group=',
);
function __construct( $argv ) {
$options = PHPUnit_Util_Getopt::getopt(
$argv,
'd:c:hv',
array_keys( $this->longOptions )
);
array_shift( $argv );
$options = array();
while ( list( $i, $arg ) = each( $argv ) ) {
try {
if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {
PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );
}
}
catch ( PHPUnit_Framework_Exception $e ) {
// Enforcing recognized arguments or correctly formed arguments is
// not really the concern here.
continue;
}
}
$ajax_message = true;
foreach ( $options[0] as $option ) {
foreach ( $options as $option ) {
switch ( $option[0] ) {
case '--exclude-group' :
$ajax_message = false;
@ -121,15 +135,17 @@ class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command {
case '--group' :
$groups = explode( ',', $option[1] );
foreach ( $groups as $group ) {
if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) )
if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) {
WP_UnitTestCase::forceTicket( $group );
}
}
$ajax_message = ! in_array( 'ajax', $groups );
continue 2;
}
}
if ( $ajax_message )
if ( $ajax_message ) {
echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL;
}
}
}
new WP_PHPUnit_TextUI_Command( $_SERVER['argv'] );
new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );

View File

@ -9,45 +9,162 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
protected $expected_deprecated = array();
protected $caught_deprecated = array();
protected $expected_doing_it_wrong = array();
protected $caught_doing_it_wrong = array();
/**
* @var WP_UnitTest_Factory
protected $caught_doing_it_wrong = array();
protected static $hooks_saved = array();
protected static $ignore_files;
/**
* @var WP_UnitTest_Factory
*/
protected $factory;
function setUp() {
set_time_limit(0);
global $wpdb;
function setUp() {
set_time_limit(0);
if ( ! self::$ignore_files ) {
self::$ignore_files = $this->scan_user_uploads();
}
if ( ! self::$hooks_saved ) {
$this->_backup_hooks();
}
global $wpdb;
$wpdb->suppress_errors = false;
$wpdb->show_errors = true;
$wpdb->db_connect();
ini_set('display_errors', 1 );
$this->factory = new WP_UnitTest_Factory;
$this->clean_up_global_scope();
$this->start_transaction();
$this->expectDeprecated();
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
}
$this->factory = new WP_UnitTest_Factory;
$this->clean_up_global_scope();
/*
* When running core tests, ensure that post types and taxonomies
* are reset for each test. We skip this step for non-core tests,
* given the large number of plugins that register post types and
* taxonomies at 'init'.
*/
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
$this->reset_post_types();
$this->reset_taxonomies();
}
$this->start_transaction();
$this->expectDeprecated();
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
}
/**
* Unregister existing post types and register defaults.
*
* Run before each test in order to clean up the global scope, in case
* a test forgets to unregister a post type on its own, or fails before
* it has a chance to do so.
*/
protected function reset_post_types() {
foreach ( get_post_types() as $pt ) {
_unregister_post_type( $pt );
}
create_initial_post_types();
}
/**
* Unregister existing taxonomies and register defaults.
*
* Run before each test in order to clean up the global scope, in case
* a test forgets to unregister a taxonomy on its own, or fails before
* it has a chance to do so.
*/
protected function reset_taxonomies() {
foreach ( get_taxonomies() as $tax ) {
_unregister_taxonomy( $tax );
}
create_initial_taxonomies();
}
function tearDown() {
global $wpdb;
$this->expectedDeprecated();
$wpdb->query( 'ROLLBACK' );
remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
if ( is_multisite() ) {
while ( ms_is_switched() ) {
restore_current_blog();
}
}
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
}
remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
$this->_restore_hooks();
wp_set_current_user( 0 );
}
function clean_up_global_scope() {
$_GET = array();
$_POST = array();
$this->flush_cache();
}
function flush_cache() {
global $wp_object_cache;
}
/**
* Allow tests to be skipped on some automated runs
*
* For test runs on Travis for something other than trunk/master
* we want to skip tests that only need to run for master.
*/
public function skipOnAutomatedBranches() {
// gentenv can be disabled
if ( ! function_exists( 'getenv' ) ) {
return false;
}
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
$travis_branch = getenv( 'TRAVIS_BRANCH' );
$travis_pull_request = getenv( 'TRAVIS_PULL_REQUEST' );
if ( false !== $travis_pull_request && 'master' !== $travis_branch ) {
$this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
}
}
/**
* Saves the action and filter-related globals so they can be restored later.
*
* Stores $merged_filters, $wp_actions, $wp_current_filter, and $wp_filter
* on a class variable so they can be restored on tearDown() using _restore_hooks().
*
* @global array $merged_filters
* @global array $wp_actions
* @global array $wp_current_filter
* @global array $wp_filter
* @return void
*/
protected function _backup_hooks() {
$globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
foreach ( $globals as $key ) {
self::$hooks_saved[ $key ] = $GLOBALS[ $key ];
}
}
/**
* Restores the hook-related globals to their state at setUp()
* so that future tests aren't affected by hooks set during this last test.
*
* @global array $merged_filters
* @global array $wp_actions
* @global array $wp_current_filter
* @global array $wp_filter
* @return void
*/
protected function _restore_hooks() {
$globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
foreach ( $globals as $key ) {
if ( isset( self::$hooks_saved[ $key ] ) ) {
$GLOBALS[ $key ] = self::$hooks_saved[ $key ];
}
}
}
function flush_cache() {
global $wp_object_cache;
$wp_object_cache->group_ops = array();
$wp_object_cache->stats = array();
$wp_object_cache->memcache_debug = array();
@ -64,17 +181,19 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
global $wpdb;
$wpdb->query( 'SET autocommit = 0;' );
$wpdb->query( 'START TRANSACTION;' );
add_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
}
function _create_temporary_tables( $queries ) {
return str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $queries );
function _create_temporary_tables( $query ) {
if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) )
return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 );
return $query;
}
function _drop_temporary_tables( $query ) {
if ( 'DROP TABLE' === substr( $query, 0, 10 ) )
return 'DROP TEMPORARY TABLE ' . substr( $query, 10 );
if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) )
return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 );
return $query;
}
@ -203,10 +322,16 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
$GLOBALS['wp']->main($parts['query']);
}
protected function checkRequirements() {
parent::checkRequirements();
if ( WP_TESTS_FORCE_KNOWN_BUGS )
return;
protected function checkRequirements() {
parent::checkRequirements();
// Core tests no longer check against open Trac tickets, but others using WP_UnitTestCase may do so.
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
return;
}
if ( WP_TESTS_FORCE_KNOWN_BUGS )
return;
$tickets = PHPUnit_Util_Test::getTickets( get_class( $this ), $this->getName( false ) );
foreach ( $tickets as $ticket ) {
if ( is_numeric( $ticket ) ) {
@ -229,7 +354,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
function knownWPBug( $ticket_id ) {
if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) )
return;
if ( ! TracTickets::isTracTicketClosed( 'http://core.trac.wordpress.org', $ticket_id ) )
if ( ! TracTickets::isTracTicketClosed( 'https://core.trac.wordpress.org', $ticket_id ) )
$this->markTestSkipped( sprintf( 'WordPress Ticket #%d is not fixed', $ticket_id ) );
}
@ -239,7 +364,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
function knownUTBug( $ticket_id ) {
if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'UT' . $ticket_id, self::$forced_tickets ) )
return;
if ( ! TracTickets::isTracTicketClosed( 'http://unit-tests.trac.wordpress.org', $ticket_id ) )
if ( ! TracTickets::isTracTicketClosed( 'https://unit-tests.trac.wordpress.org', $ticket_id ) )
$this->markTestSkipped( sprintf( 'Unit Tests Ticket #%d is not fixed', $ticket_id ) );
}
@ -249,7 +374,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
function knownPluginBug( $ticket_id ) {
if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) )
return;
if ( ! TracTickets::isTracTicketClosed( 'http://plugins.trac.wordpress.org', $ticket_id ) )
if ( ! TracTickets::isTracTicketClosed( 'https://plugins.trac.wordpress.org', $ticket_id ) )
$this->markTestSkipped( sprintf( 'WordPress Plugin Ticket #%d is not fixed', $ticket_id ) );
}
@ -325,6 +450,56 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
$message .= implode( $not_true, ', ' ) . ' should be true. ';
if ( count($not_false) )
$message .= implode( $not_false, ', ' ) . ' should be false.';
$this->assertTrue( $passed, $message );
}
}
$this->assertTrue( $passed, $message );
}
function unlink( $file ) {
$exists = is_file( $file );
if ( $exists && ! in_array( $file, self::$ignore_files ) ) {
//error_log( $file );
unlink( $file );
} elseif ( ! $exists ) {
$this->fail( "Trying to delete a file that doesn't exist: $file" );
}
}
function rmdir( $path ) {
$files = $this->files_in_dir( $path );
foreach ( $files as $file ) {
if ( ! in_array( $file, self::$ignore_files ) ) {
$this->unlink( $file );
}
}
}
function remove_added_uploads() {
// Remove all uploads.
$uploads = wp_upload_dir();
$this->rmdir( $uploads['basedir'] );
}
function files_in_dir( $dir ) {
$files = array();
$iterator = new RecursiveDirectoryIterator( $dir );
$objects = new RecursiveIteratorIterator( $iterator );
foreach ( $objects as $name => $object ) {
if ( is_file( $name ) ) {
$files[] = $name;
}
}
return $files;
}
function scan_user_uploads() {
static $files = array();
if ( ! empty( $files ) ) {
return $files;
}
$uploads = wp_upload_dir();
$files = $this->files_in_dir( $uploads['basedir'] );
return $files;
}
}

View File

@ -14,6 +14,10 @@ class TracTickets {
* @return bool|null true if the ticket is resolved, false if not resolved, null on error
*/
public static function isTracTicketClosed( $trac_url, $ticket_id ) {
if ( ! extension_loaded( 'openssl' ) ) {
$trac_url = preg_replace( "/^https:/", "http:", $trac_url );
}
if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) {
// In case you're running the tests offline, keep track of open tickets.
$file = DIR_TESTDATA . '/.trac-ticket-cache.' . str_replace( array( 'http://', 'https://', '/' ), array( '', '', '-' ), rtrim( $trac_url, '/' ) );

View File

@ -332,22 +332,10 @@ if ( !function_exists( 'str_getcsv' ) ) {
fclose( $fp );
return $data;
}
}
function _rmdir( $path ) {
if ( in_array(basename( $path ), array( '.', '..' ) ) ) {
return;
} elseif ( is_file( $path ) ) {
unlink( $path );
} elseif ( is_dir( $path ) ) {
foreach ( scandir( $path ) as $file )
_rmdir( $path . '/' . $file );
rmdir( $path );
}
}
/**
* Removes the post type and its taxonomy associations.
}
/**
* Removes the post type and its taxonomy associations.
*/
function _unregister_post_type( $cpt_name ) {
unset( $GLOBALS['wp_post_types'][ $cpt_name ] );

View File

@ -25,4 +25,7 @@
<group>ajax</group>
</exclude>
</groups>
<php>
<const name="WP_RUN_CORE_TESTS" value="1" />
</php>
</phpunit>

View File

@ -26,7 +26,9 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
*/
public function setUp() {
parent::setUp();
$post_id = $this->factory->post->create();
add_filter( 'comment_notification_recipients', '__return_empty_array' );
$user_id = $this->factory->user->create();
$post_id = $this->factory->post->create( array( 'post_author' => $user_id ) );
$this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 );
$this->_comments = array_map( 'get_comment', $this->_comments );
}

View File

@ -26,7 +26,9 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
*/
public function setUp() {
parent::setUp();
$post_id = $this->factory->post->create();
add_filter( 'comment_notification_recipients', '__return_empty_array' );
$user_id = $this->factory->user->create();
$post_id = $this->factory->post->create( array( 'post_author' => $user_id ) );
$this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 );
$this->_comments = array_map( 'get_comment', $this->_comments );
}

View File

@ -30,17 +30,13 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase {
/**
* Tear down the test fixture.
*/
public function tearDown() {
// Cleanup
foreach ($this->_ids as $id){
wp_delete_attachment($id, true);
}
$uploads = wp_upload_dir();
foreach ( scandir( $uploads['basedir'] ) as $file )
_rmdir( $uploads['basedir'] . '/' . $file );
parent::tearDown();
public function tearDown() {
// Cleanup
foreach ( $this->_ids as $id ) {
wp_delete_attachment( $id, true );
}
parent::tearDown();
}
/**

View File

@ -32,7 +32,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
*/
public function setUp() {
parent::setUp();
$post_id = $this->factory->post->create();
add_filter( 'comment_notification_recipients', '__return_empty_array' );
$user_id = $this->factory->user->create();
$post_id = $this->factory->post->create( array( 'post_author' => $user_id ) );
$this->factory->comment->create_post_comments( $post_id, 5 );
$this->_comment_post = get_post( $post_id );

View File

@ -22,6 +22,27 @@ class Tests_Basic extends WP_UnitTestCase {
$this->assertTrue($this->val);
}
function test_license() {
// This test is designed to only run on trunk/master
$this->skipOnAutomatedBranches();
$license = file_get_contents( ABSPATH . 'license.txt' );
preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
$this_year = date( 'Y' );
$this->assertEquals( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
}
function test_package_json() {
$package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
$package_json = json_decode( $package_json, true );
list( $version ) = explode( '-', $GLOBALS['wp_version'] );
// package.json uses x.y.z, so fill cleaned $wp_version for .0 releases
if ( 1 == substr_count( $version, '.' ) ) {
$version .= '.0';
}
$this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
}
// two tests for a lame bug in PHPUnit that broke the $GLOBALS reference
function test_globals() {
global $test_foo;

View File

@ -17,20 +17,24 @@ class Tests_Canonical extends WP_UnitTestCase {
var $author_id;
var $post_ids;
var $term_ids;
function setUp() {
parent::setUp();
function setUp() {
global $wp_rewrite;
parent::setUp();
update_option( 'page_comments', true );
update_option( 'comments_per_page', 5 );
update_option( 'posts_per_page', 5 );
update_option( 'permalink_structure', $this->structure );
create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules();
$this->old_current_user = get_current_user_id();
update_option( 'posts_per_page', 5 );
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( $this->structure );
create_initial_taxonomies();
$wp_rewrite->flush_rules();
$this->old_current_user = get_current_user_id();
$this->author_id = $this->factory->user->create( array( 'user_login' => 'canonical-author' ) );
wp_set_current_user( $this->author_id );
@ -78,13 +82,14 @@ class Tests_Canonical extends WP_UnitTestCase {
$this->factory->term->create( array( 'name' => 'post-formats' ) );
}
function tearDown() {
wp_set_current_user( $this->old_current_user );
$GLOBALS['wp_rewrite']->init();
parent::tearDown();
}
function tearDown() {
global $wp_rewrite;
wp_set_current_user( $this->old_current_user );
$wp_rewrite->init();
parent::tearDown();
}
// URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..
// Return url's are full url's with the prepended home.
@ -173,32 +178,23 @@ class Tests_Canonical extends WP_UnitTestCase {
array( '?cat=%d', '/category/parent/child-1/child-2/' ), // no children
array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ),
array( '/category/uncategorized/page/2/', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
array( '/category/child-1/', '/category/parent/child-1/', 18734 ),
array( '/category/foo/child-1/', '/category/parent/child-1/', 18734 ),
// Categories & Intersections with other vars
array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
// Categories & Intersections with other vars
array( '/category/uncategorized/?tag=post-formats', array( 'url' => '/category/uncategorized/?tag=post-formats', 'qv' => array('category_name' => 'uncategorized', 'tag' => 'post-formats') ) ),
array( '/?category_name=cat-a,cat-b', array( 'url' => '/?category_name=cat-a,cat-b', 'qv' => array( 'category_name' => 'cat-a,cat-b' ) ) ),
// Taxonomies with extra Query Vars
array( '/category/cat-a/page/1/?test=one%20two', '/category/cat-a/?test=one%20two', 18086), // Extra query vars should stay encoded
// Categories with Dates
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 ),
// array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
array( '/2008/04/?cat=1', array( 'url' => '/category/uncategorized/?year=2008&monthnum=04', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
// array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
array( '/2008/?category_name=cat-a', array( 'url' => '/category/cat-a/?year=2008', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 20386 ),
// array( '/category/uncategorized/?year=2008', array( 'url' => '/2008/?category_name=uncategorized', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
array( '/category/uncategorized/?year=2008', array( 'url' => '/category/uncategorized/?year=2008', 'qv' => array('category_name' => 'uncategorized', 'year' => '2008' ) ), 17661 ),
// Pages
array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
array( '/child-page-1/', '/parent-page/child-page-1/'),
array( '/?page_id=144', '/parent-page/child-page-1/'),
// Categories with Dates
array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
// array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
// Pages
array( '/child-page-1/', '/parent-page/child-page-1/'),
array( '/?page_id=144', '/parent-page/child-page-1/'),
array( '/abo', '/about/' ),
// Posts
@ -214,18 +210,15 @@ class Tests_Canonical extends WP_UnitTestCase {
array( '/2008/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
array( '/2010/post-format-test-au/', '/2008/06/02/post-format-test-audio/'), // A Year the post is not in
array( '/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
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 ?!
array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
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 ?!
array( '/2008/09/03/images-test/8/', '/2008/09/03/images-test/4/', 11694 ), // post with 4 pages
array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
// Comments
array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/' ),
array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/', 20388 ), // there's only 3 pages
// Attachments
// Comments
array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/' ),
// Attachments
array( '/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
array( '/2008/06/10/post-format-test-gallery/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
@ -244,13 +237,11 @@ class Tests_Canonical extends WP_UnitTestCase {
array( '/2012/11/51/', '/2012/11/'),
// Authors
array( '/?author=%d', '/author/canonical-author/' ),
// array( '/?author=%d&year=2008', '/2008/?author=3'),
array( '/?author=%d&year=2008', '/author/canonical-author/?year=2008', 17661 ),
// array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
array( '/author/canonical-author/?year=2008', '/author/canonical-author/?year=2008', 17661 ),
// Feeds
array( '/?author=%d', '/author/canonical-author/' ),
// array( '/?author=%d&year=2008', '/2008/?author=3'),
// array( '/author/canonical-author/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
// Feeds
array( '/?feed=atom', '/feed/atom/' ),
array( '/?feed=rss2', '/feed/' ),
array( '/?feed=comments-rss2', '/comments/feed/'),

View File

@ -27,9 +27,8 @@ class Tests_Canonical_CustomRules extends Tests_Canonical {
*/
return array(
// Custom Rewrite rules leading to Categories
array( '/ccr/uncategorized/sort/asc/', array( 'url' => '/ccr/uncategorized/sort/asc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'asc' ) ) ),
array( '/ccr/uncategorized/sort/desc/', array( 'url' => '/ccr/uncategorized/sort/desc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'desc' ) ) ),
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 ),
);
}
array( '/ccr/uncategorized/sort/asc/', array( 'url' => '/ccr/uncategorized/sort/asc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'asc' ) ) ),
array( '/ccr/uncategorized/sort/desc/', array( 'url' => '/ccr/uncategorized/sort/desc/', 'qv' => array( 'category_name' => 'uncategorized', 'order' => 'desc' ) ) ),
);
}
}

View File

@ -13,11 +13,17 @@ class Tests_Canonical_PageOnFront extends Tests_Canonical {
global $wp_rewrite;
update_option( 'show_on_front', 'page' );
update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
$wp_rewrite->init();
flush_rewrite_rules();
}
update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
$wp_rewrite->init();
$wp_rewrite->flush_rules();
}
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
parent::tearDown();
}
function data() {
/* Format:
* [0]: $test_url,

View File

@ -1,80 +0,0 @@
<?php
/**
* @group canonical
* @group rewrite
* @group query
*/
class Tests_Canonical_PermalinkFormat extends WP_UnitTestCase {
/**
* @ticket 21167
*/
public function test_dotted_formats() {
global $wp_rewrite;
// Create a sample post
$cat_id = $this->factory->term->create( array(
'name' => 'permalink-test',
'taxonomy' => 'category'
) );
$user_id = $this->factory->user->create( array(
'role' => 'editor',
'user_login' => 'permalink_user',
) );
$post_id = $this->factory->post->create( array(
'post_title' => 'lorem-ipsum',
'post_date' => '2012-08-02 14:15:05',
'post_author' => $user_id,
'category' => $cat_id
) );
wp_set_post_categories( $post_id, array( $cat_id ) );
// Sample permalinks
$tests = array(
'/%postname%.%post_id%/ ' => array(
'regex' => '([^/]+)\.([0-9]+)(/[0-9]+)?/?$',
'url' => 'index.php?name=$1&p=$2&page=$3'
),
'/%year%.%monthnum%.%postname%/' => array(
'regex' => '([0-9]{4})\.([0-9]{1,2})\.([^/]+)(/[0-9]+)?/?$',
'url' => 'index.php?year=$1&monthnum=$2&name=$3&page=$4'
),
'/%post_id%.%postname%/' => array(
'regex' => '([0-9]+)\.([^/]+)(/[0-9]+)?/?$',
'url' => 'index.php?p=$1&name=$2&page=$3'
),
'/%postname%.%year%/' => array(
'regex' => '([^/]+)\.([0-9]{4})(/[0-9]+)?/?$',
'url' => 'index.php?name=$1&year=$2&page=$3'
),
'/$%postname%$/' => array(
'regex' => '\$([^/]+)\$(/[0-9]+)?/?$',
'url' => 'index.php?name=$1&page=$2'
),
'%year%.+?%monthnum%.+?%day%.+?%hour%.+?%minute%.+?%second%.+?%post_id%.+?%postname%.+?%category%.+?%author%.+?' => array(
'regex' => '([0-9]{4})\.\+\?([0-9]{1,2})\.\+\?([0-9]{1,2})\.\+\?([0-9]{1,2})\.\+\?([0-9]{1,2})\.\+\?([0-9]{1,2})\.\+\?([0-9]+)\.\+\?([^/]+)\.\+\?%category%\.\+\?([^/]+)\.\+\?(/[0-9]+)?/?$',
'url' => 'index.php?year=$1&monthnum=$2&day=$3&hour=$4&minute=$5&second=$6&p=$7&name=$8&%category%$9&author_name=$10&page=$11'
),
);
// Test permalinks
foreach ( $tests as $permalink_format => $expected ) {
update_option( 'permalink_structure', $permalink_format );
// Get the rewrite rules
$rules = $wp_rewrite->generate_rewrite_rules( get_option( 'permalink_structure' ), EP_PERMALINK, false, false, false, false );
// Filter out only the post rewrite rule
foreach ( $rules as $regex => $url ) {
if ( false === strpos( $url, 'attachment=$' ) && false === strpos( $url, 'tb=' ) && false === strpos( $url, 'cpage=$' ) ) {
break;
}
}
// Test that expected === actual
$this->assertEquals( $regex, $expected['regex'], "Problem with permalink format: $permalink_format" );
$this->assertEquals( $url, $expected['url'], "Problem with permalink format: $permalink_format" );
}
}
}

View File

@ -82,38 +82,6 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
// Cleanup
$wp_scripts->base_url = $base_url_backup;
}
/**
* @ticket 22229
*/
function test_inline_should_not_output_script_tag_with_src() {
wp_enqueue_script( 'baba-inline-0', 'inline' );
$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
}
/**
* @ticket 22229
*/
function test_json_encode_should_not_encode_special_literal_values() {
if ( ! class_exists( 'WP_JS_Literal' ) ) {
$this->markTestSkipped( "WP_JS_Literal class doesn't exist" );
}
$literal = new WP_JS_Literal( 'baba()' );
$this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );
}
/**
* @ticket 22229
*/
function test_json_encode_should_not_encode_special_literal_values_with_dependencies() {
if ( ! class_exists( 'WP_JS_Literal' ) ) {
$this->markTestSkipped( "WP_JS_Literal class doesn't exist" );
}
$literal = new WP_JS_Literal( 'baba()', array( 'dep0', 'dep1' ) );
$this->assertEquals( '{"x":baba()}', WP_JS_Literal::json_encode( array( 'x' => $literal ), array( $literal ) ) );
}
}
$wp_scripts->base_url = $base_url_backup;
}
}

View File

@ -1,256 +0,0 @@
<?php
/**
* Test WP_Export_Query class
*
* @group export
* @ticket 22435
*/
class Test_WP_Export_Query extends WP_UnitTestCase {
function setUp() {
if ( ! class_exists( 'WP_Export_Query' ) ) {
$this->markTestSkipped( "WP_Export_Query class doesn't exist" );
}
parent::setUp();
}
function test_WP_Export_Query_should_be_initialized_with_an_array() {
$export = new WP_Export_Query( array( 'author' => 'all' ) );
$this->assertTrue( (bool) $export );
}
function test_WP_Export_Query_should_use_post_ids_if_passed() {
$export = new WP_Export_Query( array( 'post_ids' => array( 1, 2, 3 ) ) );
$this->assertEquals( array( 1, 2, 3 ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_all_posts_if_all_arg_is_true() {
$post_id = $this->factory->post->create();
$export = new WP_Export_Query();
$this->assertEquals( array( $post_id ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_all_posts_if_no_args_passed() {
$post_id = $this->factory->post->create();
$export = new WP_Export_Query();
$this->assertEquals( array( $post_id ), $export->post_ids() );
}
function test_WP_Export_Query_should_not_export_anything_if_post_type_arg_is_set_to_non_existing_post_type() {
$post_id = $this->factory->post->create();
$export = new WP_Export_Query( array( 'post_type' => 'baba' ) );
$this->assertEquals( array(), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_a_certain_post_type_if_the_post_type_arg_is_set() {
register_post_type( 'baba' );
$post_id = $this->factory->post->create( array( 'post_type' => 'baba' ) );
$_ = $this->factory->post->create( array( 'post_type' => 'dyado' ) );
$export = new WP_Export_Query( array( 'post_type' => 'baba' ) );
$this->assertEquals( array( $post_id ), $export->post_ids() );
_unregister_post_type( 'baba' );
}
function test_WP_Export_Query_should_not_export_post_types_with_can_export_set_to_false() {
register_post_type( 'non-exportable', array( 'can_export' => false ) );
register_post_type( 'exportable', array( 'can_export' => true ) );
$non_exportable_post_id = $this->factory->post->create( array( 'post_type' => 'non-exportable' ) );
$exportable_post_id = $this->factory->post->create( array( 'post_type' => 'exportable' ) );
$export = new WP_Export_Query();
$this->assertEquals( array( $exportable_post_id ), $export->post_ids() );
_unregister_post_type( 'non-exportable' );
_unregister_post_type( 'exportable' );
}
function test_WP_Export_Query_should_not_export_auto_drafts_by_default() {
$post_id = $this->factory->post->create( array( 'post_status' => 'auto-draft' ) );
$export = new WP_Export_Query();
$this->assertEquals( array(), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_certain_status_if_status_arg_is_set() {
$post_id_baba = $this->factory->post->create( array( 'post_status' => 'baba' ) );
$post_id_dudu = $this->factory->post->create( array( 'post_status' => 'dudu' ) );
$export = new WP_Export_Query( array( 'status' => 'baba' ) );
$this->assertEquals( array( $post_id_baba ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_certain_author_id_if_status_arg_is_a_number() {
$user_id = $this->factory->user->create();
$post_by_user = $this->factory->post->create( array( 'post_author' => $user_id ) );
$other_post = $this->factory->post->create( array( 'post_author' => $user_id + 1 ) );
$export = new WP_Export_Query( array( 'author' => $user_id ) );
$this->assertEquals( array( $post_by_user ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_certain_author_name_if_status_arg_is_a_username() {
$user = $this->factory->user->create_and_get( array( 'user_login' => 'baba' ) );
$post_by_user = $this->factory->post->create( array( 'post_author' => $user->ID ) );
$other_post = $this->factory->post->create( array( 'post_author' => $user->ID + 1 ) );
$export = new WP_Export_Query( array( 'author' => 'baba' ) );
$this->assertEquals( array( $post_by_user ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_certain_author_object_if_author_is_an_object_with_ID_member_variable() {
$user = $this->factory->user->create_and_get();
$post_by_user = $this->factory->post->create( array( 'post_author' => $user->ID ) );
$other_post = $this->factory->post->create( array( 'post_author' => $user->ID + 1 ) );
$export = new WP_Export_Query( array( 'author' => $user ) );
$this->assertEquals( array( $post_by_user ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_after_certain_start_date_if_start_date_arg_is_passed() {
$post_before = $this->factory->post->create( array( 'post_date' => '2012-11-10 23:59:59' ) );
$post_after = $this->factory->post->create( array( 'post_date' => '2012-11-11 00:00:00' ) );
$export = new WP_Export_Query( array( 'start_date' => '2012-11-11' ) );
$this->assertEquals( array( $post_after ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_after_certain_end_date_if_end_date_arg_is_passed() {
$post_before = $this->factory->post->create( array( 'post_date' => '2012-11-10 23:59:59' ) );
$post_after = $this->factory->post->create( array( 'post_date' => '2012-11-11 00:00:00' ) );
$export = new WP_Export_Query( array( 'end_date' => '2012-11-10' ) );
$this->assertEquals( array( $post_before ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_certain_category_if_category_arg_is_passed() {
$category_id = $this->factory->category->create( array( 'name' => 'baba' ) );
$post_with_category = $this->factory->post->create( array( 'post_category' => array( $category_id ) ) );
$post_without = $this->factory->post->create();
$export = new WP_Export_Query( array( 'post_type' => 'post', 'category' => 'baba' ) );
$this->assertEquals( array( $post_with_category ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_only_posts_with_certain_category_id_if_category_arg_is_passed() {
$category_id = $this->factory->category->create( array( 'name' => 'baba' ) );
$post_with_category = $this->factory->post->create( array( 'post_category' => array( $category_id ) ) );
$post_without = $this->factory->post->create();
$export = new WP_Export_Query( array( 'post_type' => 'post', 'category' => $category_id ) );
$this->assertEquals( array( $post_with_category ), $export->post_ids() );
}
function test_WP_Export_Query_should_filter_posts_by_category_only_for_post_post_type() {
$category_id = $this->factory->category->create( array( 'name' => 'baba' ) );
$post_with_category = $this->factory->post->create( array( 'post_category' => array( $category_id ) ) );
$post_without = $this->factory->post->create();
$different_post_type = $this->factory->post->create( array( 'post_type' => 'page' ) );
$export = new WP_Export_Query( array( 'category' => $category_id ) );
$this->assertEqualSets( array( $post_with_category, $post_without, $different_post_type ), $export->post_ids() );
}
function test_WP_Export_Query_should_include_attachments_of_posts_if_we_are_filtering_only_some_post_types() {
register_post_type( 'baba' );
$post_id = $this->factory->post->create( array( 'post_type' => 'baba' ) );
$attachment_post_id = $this->factory->post->create( array( 'post_type' => 'attachment', 'post_parent' => $post_id ) );
$export = new WP_Export_Query( array( 'post_type' => 'baba' ) );
$this->assertEquals( array( $post_id, $attachment_post_id ), $export->post_ids() );
_unregister_post_type( 'baba' );
}
function test_authors_should_return_list_of_users_for_each_post_author() {
$user_id = $this->factory->user->create();
$this->factory->post->create( array( 'post_author' => $user_id ) );
$export = new WP_Export_Query();
$authors = $export->authors();
$this->assertEquals( 1, count( $authors ) );
$this->assertEquals( $user_id, $authors[0]->ID );
}
function test_authors_should_skip_non_existing_authors() {
$this->factory->post->create( array( 'post_author' => 11 ) );
$export = new WP_Export_Query();
$this->assertEquals( array(), $export->authors() );
}
function test_authors_should_skip_auto_draft_authors() {
$user_id = $this->factory->user->create();
$this->factory->post->create( array( 'post_author' => $user_id, 'post_status' => 'auto-draft' ) );
$export = new WP_Export_Query();
$this->assertEquals( array(), $export->authors() );
}
function test_categories_should_return_only_the_category_we_are_filtering_on() {
$category_id = $this->factory->category->create( array( 'name' => 'baba' ) );
$other_category_id = $this->factory->category->create( array( 'name' => 'dyado' ) );
$export = new WP_Export_Query( array( 'post_type' => 'post', 'category' => $category_id ) );
$this->assertEquals( 1, count( $export->categories() ) );
}
function test_categories_should_return_no_categories_if_we_are_requesting_only_one_post_type() {
$category_id = $this->factory->category->create();
$export = new WP_Export_Query( array( 'post_type' => 'post' ) );
$this->assertEquals( array(), $export->categories() );
}
function test_categories_should_return_all_categories_if_we_are_requesting_all_post_types() {
$category_id = $this->factory->category->create();
$another_category_id = $this->factory->category->create();
$export = new WP_Export_Query();
$this->assertEqualSets( array( 1, $category_id, $another_category_id ), self::get_term_ids( $export->categories() ) );
}
function test_categories_should_not_return_a_child_before_its_parent_category() {
$child_category_id = $this->factory->category->create();
$top_category_id = $this->factory->category->create();
wp_update_term( $child_category_id, 'category', array( 'parent' => $top_category_id ) );
$export = new WP_Export_Query();
$this->assertNoChildBeforeParent( $export->categories() );
}
function test_tags_should_return_all_tags() {
$tag_id = $this->factory->tag->create();
$export = new WP_Export_Query();
$this->assertEquals( array( $tag_id ), self::get_term_ids( $export->tags() ) );
}
function test_tags_should_return_no_tags_if_we_are_requesting_only_one_post_type() {
$category_id = $this->factory->tag->create();
$export = new WP_Export_Query( array( 'post_type' => 'post' ) );
$this->assertEquals( array(), $export->tags() );
}
function test_custom_taxonomies_terms_should_return_all_terms() {
register_taxonomy( 'taxonomy_all', 'post' );
$term_id = $this->factory->term->create( array( 'taxonomy' => 'taxonomy_all' ) );
$export = new WP_Export_Query();
$this->assertEquals( array( $term_id ), self::get_term_ids( $export->custom_taxonomies_terms() ) );
_unregister_taxonomy( 'taxonomy_all' );
}
function test_custom_taxonomes_terms_should_return_no_terms_if_we_are_requesting_only_one_post_type() {
register_taxonomy( 'taxonomy_one_post_type', 'post' );
$term_id = $this->factory->term->create( array( 'taxonomy' => 'taxonomy_one_post_type' ) );
$export = new WP_Export_Query( array( 'post_type' => 'post' ) );
$this->assertEquals( array(), $export->custom_taxonomies_terms() );
_unregister_taxonomy( 'taxonomy_one_post_type' );
}
function test_custom_taxonomies_terms_should_not_return_a_child_before_its_parent_term() {
register_taxonomy( 'heir', 'post', array( 'hierarchical' => true ) );
$child_term_id = $this->factory->term->create( array( 'taxonomy' => 'heir' ) );
$top_term_id = $this->factory->term->create( array( 'taxonomy' => 'heir' ) );
wp_update_term( $child_term_id, 'heir', array( 'parent' => $top_term_id ) );
$export = new WP_Export_Query();
$this->assertNoChildBeforeParent( $export->custom_taxonomies_terms() );
_unregister_taxonomy( 'heir' );
}
private function assertNoChildBeforeParent( $terms ) {
$visited = array();
foreach( $terms as $term ) {
$this->assertTrue( isset( $visited[$term->parent] ) || !$term->parent );
$visited[$term->term_id] = true;
}
}
private static function get_term_ids( $terms ) {
return array_values( array_map( array( __CLASS__, '_get_term_ids_cb' ), $terms ) );
}
private static function _get_term_ids_cb( $c ) {
return intval( $c->term_id );
}
}

View File

@ -1,43 +0,0 @@
<?php
/**
* Test export functions
*
* @group export
* @ticket 22435
*/
class Test_WP_Export_Functions extends WP_UnitTestCase {
function setUp() {
if ( ! function_exists( 'wp_export' ) ) {
$this->markTestSkipped( "wp_export function doesn't exist" );
}
parent::setUp();
}
function test_wp_export_returns_wp_error_if_the_writer_throws_Export_exception() {
$this->assertTrue( is_wp_error( wp_export( array( 'writer' => 'Test_WP_Export_Stub_Writer_Throws_Export_Exception' ) ) ) );
}
function test_wp_export_passes_the_exception_if_the_writer_throws_other_exception() {
$this->setExpectedException( 'Exception' );
wp_export( array( 'writer' => 'Test_WP_Export_Stub_Writer_Throws_Other_Exception' ) );
}
}
class Test_WP_Export_Stub_Writer_Throws_Export_Exception {
function __construct( $formatter ) {
}
function export() {
throw new WP_Export_Exception( 'baba' );
}
}
class Test_WP_Export_Stub_Writer_Throws_Other_Exception {
function __construct( $formatter ) {
}
function export() {
throw new Exception( 'baba' );
}
}

View File

@ -1,28 +0,0 @@
<?php
/**
* Test WP_Export_*_Writer classes
*
* @group export
* @ticket 22435
*/
class Test_WP_Export_Writers extends WP_UnitTestCase {
function test_export_returner_returns_all_the_return_values() {
if ( ! class_exists( 'WP_Export_Returner' ) ) {
$this->markTestSkipped( "WP_Export_Returner class doesn't exist" );
}
$returner = new WP_Export_Returner( $this->get_x_formatter() );
$this->assertEquals( 'xxx' , $returner->export() );
}
private function get_x_formatter() {
$methods = array( 'before_posts', 'posts', 'after_posts' );
$formatter = $this->getMock( 'WP_Export_WXR_Formatter', $methods, array( null ) );
foreach( $methods as $method ) {
$return = 'posts' == $method? array( 'x' ) : 'x';
$formatter->expects( $this->once() )->method( $method )->with()->will( $this->returnValue( $return ) );
}
return $formatter;
}
}

View File

@ -108,16 +108,17 @@ class Tests_Feed_RSS2 extends WP_UnitTestCase {
// pub date
$pubdate = xml_find($items[$i]['child'], 'pubDate');
$this->assertEquals(strtotime($posts[$i]->post_date), strtotime($pubdate[0]['content']));
// author
$creator = xml_find($items[$i]['child'], 'dc:creator');
$this->assertEquals($this->author->user_nicename, $creator[0]['content']);
// categories (perhaps multiple)
$categories = xml_find($items[$i]['child'], 'category');
$cat_ids = wp_get_post_categories($post->ID);
if (empty($cat_ids)) $cat_ids = array(1);
// should be the same number of categories
// author
$creator = xml_find( $items[$i]['child'], 'dc:creator' );
$user = new WP_User( $posts[$i]->post_author );
$this->assertEquals( $user->user_login, $creator[0]['content'] );
// categories (perhaps multiple)
$categories = xml_find($items[$i]['child'], 'category');
$cat_ids = wp_get_post_categories($posts[$i]->ID);
if (empty($cat_ids)) $cat_ids = array(1);
// should be the same number of categories
$this->assertEquals(count($cat_ids), count($categories));
// ..with the same names
for ($j=0; $j < count($cat_ids); $j++)

View File

@ -247,24 +247,6 @@ class Tests_Filters extends WP_UnitTestCase {
function _self_removal($tag) {
remove_action( $tag, array($this, '_self_removal'), 10, 1 );
return $tag;
}
/**
* @ticket 21169
*/
function test_filter_removal_during_filter() {
$tag = rand_str();
$a = new MockAction();
$b = new MockAction();
add_action( $tag, array($a, 'filter_append'), 11, 1 );
add_action( $tag, array($b, 'filter_append'), 12, 1 );
add_action( $tag, array($this, '_self_removal'), 10, 1 );
$result = apply_filters($tag, $tag);
$this->assertEquals( 1, $a->get_call_count(), 'priority 11 filters should run after priority 10 empties itself' );
$this->assertEquals( 1, $b->get_call_count(), 'priority 12 filters should run after priority 10 empties itself and priority 11 runs' );
$this->assertEquals( $result, $tag . '_append_append', 'priority 11 and 12 filters should run after priority 10 empties itself' );
}
}
return $tag;
}
}

View File

@ -61,22 +61,10 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase {
$this->assertEquals( 'feed:feed:alert(1)', esc_url( 'feed:feed:alert(1)' ) );
$this->assertEquals( 'feed:http://wordpress.org/feed/', esc_url( 'feed:http://wordpress.org/feed/' ) );
}
/**
* @ticket 16859
*/
function test_square_brackets() {
$this->assertEquals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo[bar]=baz' ) );
$this->assertEquals( 'http://example.com/?baz=bar&#038;foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) );
//IPv6 addresses in urls - RFC2732
$this->assertEquals( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) );
$this->assertEquals( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) );
$this->assertEquals( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) );
}
/**
* @ticket 21974
*/
/**
* @ticket 21974
*/
function test_protocol_relative_with_colon() {
$this->assertEquals( '//example.com/foo?foo=abc:def', esc_url( '//example.com/foo?foo=abc:def' ) );
}

View File

@ -363,21 +363,4 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
$out = make_clickable( $in );
$this->assertEquals( $in, $out );
}
/**
* @ticket 16859
*/
function test_square_brackets() {
$urls_before = array(
'http://example.com/?foo[bar]=baz',
'http://example.com/?baz=bar&foo[bar]=baz',
);
$urls_expected = array(
'<a href="http://example.com/?foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?foo%5Bbar%5D=baz</a>',
'<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>',
);
foreach ($urls_before as $key => $url) {
$this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
}
}
}

View File

@ -31,24 +31,10 @@ class Tests_Formatting_SanitizeTitleWithDashes extends WP_UnitTestCase {
$this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t----"));
}
function test_handles_non_entity_ampersands() {
$this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
}
/**
* @ticket 10823
*/
function test_strips_entities() {
$this->assertEquals("no-entities-here", sanitize_title_with_dashes("No &nbsp; Entities &ndash; Here &amp;"));
$this->assertEquals("one-two", sanitize_title_with_dashes("One &amp; Two", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One &#123; Two;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One & Two;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One Two™;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One &&amp; Two;", '', 'save'));
$this->assertEquals("onetwo", sanitize_title_with_dashes("One&Two", '', 'save'));
$this->assertEquals("onetwo-test", sanitize_title_with_dashes("One&Two Test;", '', 'save'));
}
function test_handles_non_entity_ampersands() {
$this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
}
function test_replaces_nbsp() {
$this->assertEquals("dont-break-the-space", sanitize_title_with_dashes("don't break the space", '', 'save'));
}

View File

@ -7,18 +7,10 @@ class Tests_Formatting_SanitizeUser extends WP_UnitTestCase {
function test_strips_html() {
$input = "Captain <strong>Awesome</strong>";
$expected = is_multisite() ? 'captain awesome' : 'Captain Awesome';
$this->assertEquals($expected, sanitize_user($input));
}
/**
* @ticket 10823
*/
function test_strips_entities() {
$this->assertEquals("ATT", sanitize_user("AT&amp;T"));
$this->assertEquals("ATT Test;", sanitize_user("AT&amp;T Test;"));
$this->assertEquals("AT&T Test;", sanitize_user("AT&T Test;"));
}
function test_strips_percent_encoded_octets() {
$expected = is_multisite() ? 'franois' : 'Franois';
$this->assertEquals($expected, sanitize_user($input));
}
function test_strips_percent_encoded_octets() {
$expected = is_multisite() ? 'franois' : 'Franois';
$this->assertEquals( $expected, sanitize_user( "Fran%c3%a7ois" ) );
}
function test_optional_strict_mode_reduces_to_safe_ascii_subset() {

View File

@ -129,22 +129,18 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\fg.png' ), 'Slash not removed' );
$this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\fg.png' ), 'Double slashed not removed' );
$this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' );
}
/**
* @ticket 9930
*/
function test_is_serialized() {
$cases = array(
}
function test_is_serialized() {
$cases = array(
serialize(null),
serialize(true),
serialize(false),
serialize(-25),
serialize(25),
serialize(1.1),
serialize(2.1E+200),
serialize('this string will be serialized'),
serialize("a\nb"),
serialize(25),
serialize(1.1),
serialize('this string will be serialized'),
serialize("a\nb"),
serialize(array()),
serialize(array(1,1,2,3,5,8,13)),
serialize( (object)array('test' => true, '3', 4) )
@ -153,11 +149,10 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertTrue( is_serialized($case), "Serialized data: $case" );
$not_serialized = array(
'a string',
'garbage:a:0:garbage;',
'b:4;',
's:4:test;'
);
'a string',
'garbage:a:0:garbage;',
's:4:test;'
);
foreach ( $not_serialized as $case )
$this->assertFalse( is_serialized($case), "Test data: $case" );
}

View File

@ -146,11 +146,11 @@ class Test_Functions_Deprecated extends WP_UnitTestCase {
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
$file = wp_tempnam();
$img = imagecreatefromjpeg( DIR_TESTDATA . '/images/canola.jpg' );
wp_save_image_file( $file, $img, 'image/jpeg', 1 );
imagedestroy( $img );
@unlink($file);
// Check if the arg was deprecated
wp_save_image_file( $file, $img, 'image/jpeg', 1 );
imagedestroy( $img );
unlink( $file );
// Check if the arg was deprecated
$check = $this->was_deprecated( 'argument', 'wp_save_image_file' );
$this->assertNotEmpty( $check );
}
@ -167,11 +167,11 @@ class Test_Functions_Deprecated extends WP_UnitTestCase {
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
$file = wp_tempnam();
$img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
wp_save_image_file( $file, $img, 'image/jpeg', 1 );
unset( $img );
@unlink($file);
// Check if the arg was deprecated
wp_save_image_file( $file, $img, 'image/jpeg', 1 );
unset( $img );
unlink( $file );
// Check if the arg was deprecated
$check = $this->was_deprecated( 'argument', 'wp_save_image_file' );
$this->assertFalse( $check );
}

View File

@ -282,8 +282,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$this->markTestSkipped( 'This install of PHP does not support SSL' );
$res = wp_remote_get( 'https://wordpress.org/' );
$this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
}
}
$this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
}
}

View File

@ -3,13 +3,21 @@
/**
* @group http
* @group external-http
*/
class Tests_HTTP_Functions extends WP_UnitTestCase {
function test_head_request() {
// this url give a direct 200 response
$url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$headers = wp_remote_retrieve_headers( $response );
*/
class Tests_HTTP_Functions extends WP_UnitTestCase {
public function setUp() {
if ( ! extension_loaded( 'openssl' ) ) {
$this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
}
parent::setUp();
}
function test_head_request() {
// this url give a direct 200 response
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$headers = wp_remote_retrieve_headers( $response );
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
@ -17,25 +25,25 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
}
function test_head_redirect() {
// this url will 301 redirect
$url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
function test_head_redirect() {
// this url will 301 redirect
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
}
function test_head_404() {
$url = 'http://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
$headers = wp_remote_head( $url );
function test_head_404() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
$headers = wp_remote_head( $url );
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
$this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
}
function test_get_request() {
$url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$file = tempnam('/tmp', 'testfile');
function test_get_request() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$file = tempnam('/tmp', 'testfile');
$headers = wp_get_http($url, $file);
// should return the same headers as a head request
@ -49,11 +57,11 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
$this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
}
function test_get_redirect() {
// this will redirect to asdftestblog1.files.wordpress.com
$url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$file = tempnam('/tmp', 'testfile');
function test_get_redirect() {
// this will redirect to asdftestblog1.files.wordpress.com
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$file = tempnam('/tmp', 'testfile');
$headers = wp_get_http($url, $file);
// should return the same headers as a head request
@ -67,11 +75,11 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
$this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
}
function test_get_redirect_limit_exceeded() {
// this will redirect to asdftestblog1.files.wordpress.com
$url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$file = tempnam('/tmp', 'testfile');
// pretend we've already redirected 5 times
function test_get_redirect_limit_exceeded() {
// this will redirect to asdftestblog1.files.wordpress.com
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$file = tempnam('/tmp', 'testfile');
// pretend we've already redirected 5 times
$headers = wp_get_http( $url, $file, 6 );
$this->assertFalse( $headers );
}

View File

@ -7,10 +7,12 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
/**
* Set the image editor engine according to the unit test's specification
*/
public function setUp() {
if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) {
$this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) );
*/
public function setUp() {
parent::setUp();
if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) {
$this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) );
}
add_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
@ -18,11 +20,14 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
/**
* Undo the image editor override
*/
public function tearDown() {
remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
}
*/
public function tearDown() {
parent::tearDown();
remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
parent::tearDown();
}
/**
* Override the image editor engine
* @return string
@ -31,11 +36,11 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
return array( $this->editor_engine );
}
/**
* Helper assertion for testing alpha on images
*
* @param string $image_path
* @param array $point array(x,y)
/**
* Helper assertion for testing alpha on images
*
* @param string $image_path
* @param array $point array(x,y)
* @param int $alpha
*/
protected function assertImageAlphaAtPoint( $image_path, $point, $alpha ) {

View File

@ -4,18 +4,32 @@
* Test the WP_Image_Editor_GD class
* @group image
* @group media
* @group wp-image-editor-gd
*/
class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
* @group wp-image-editor-gd
*/
require_once( dirname( __FILE__ ) . '/base.php' );
class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
public $editor_engine = 'WP_Image_Editor_GD';
public function setup() {
require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );
parent::setUp();
}
public function tearDown() {
$folder = DIR_TESTDATA . '/images/waffles-*.jpg';
foreach ( glob( $folder ) as $file ) {
unlink( $file );
}
$this->remove_added_uploads();
parent::tearDown();
}
/**
* Check support for GD compatible mime types.
*
@ -134,6 +148,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
unlink( $save_to_file );
}
/**
@ -151,8 +166,10 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
}
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
unlink( $save_to_file );
}
}

View File

@ -4,10 +4,11 @@
* Test the WP_Image_Editor_Imagick class
* @group image
* @group media
* @group wp-image-editor-imagick
*/
class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
* @group wp-image-editor-imagick
*/
require_once( dirname( __FILE__ ) . '/base.php' );
class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
public $editor_engine = 'WP_Image_Editor_Imagick';
@ -23,6 +24,18 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
parent::setUp();
}
public function tearDown() {
$folder = DIR_TESTDATA . '/images/waffles-*.jpg';
foreach ( glob( $folder ) as $file ) {
unlink( $file );
}
$this->remove_added_uploads();
parent::tearDown();
}
/**
* Check support for Image Magick compatible mime types.
*
@ -142,6 +155,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
unlink( $save_to_file );
}
/**
@ -156,10 +170,12 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
$editor = wp_get_image_editor( $file );
$editor->load();
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
}
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
unlink( $save_to_file );
}
}

View File

@ -86,11 +86,11 @@ class Tests_Image_Functions extends WP_UnitTestCase {
function test_is_displayable_image_negative() {
// these are image files but aren't suitable for web pages because of compatibility or size issues
$files = array(
// 'test-image-cmyk.jpg', Allowed in r9727
'test-image.bmp',
// 'test-image-grayscale.jpg', Allowed in r9727
'test-image.pct',
$files = array(
// 'test-image-cmyk.jpg', Allowed in r9727
// 'test-image.bmp', Allowed in r28589
// 'test-image-grayscale.jpg', Allowed in r9727
'test-image.pct',
'test-image.tga',
'test-image.sgi',
'test-image.tiff',
@ -142,12 +142,12 @@ class Tests_Image_Functions extends WP_UnitTestCase {
$this->assertNotEmpty( $ret );
$this->assertNotInstanceOf( 'WP_Error', $ret );
$this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) );
// Clean up
@unlink( $file );
@unlink( $ret['path'] );
}
// Clean up
unlink( $file );
unlink( $ret['path'] );
}
// Clean up
unset( $img );
}
@ -183,12 +183,12 @@ class Tests_Image_Functions extends WP_UnitTestCase {
$this->assertNotEmpty( $ret );
$this->assertNotInstanceOf( 'WP_Error', $ret );
$this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) );
// Clean up
@unlink( $file );
@unlink( $ret['path'] );
unset( $img );
}
// Clean up
unlink( $file );
unlink( $ret['path'] );
unset( $img );
}
}
/**
@ -229,12 +229,11 @@ class Tests_Image_Functions extends WP_UnitTestCase {
$file = wp_unique_filename( $temp, uniqid() . ".$ext" );
$ret = $img->save( trailingslashit( $temp ) . $file );
$this->assertNotEmpty( $ret );
$this->assertNotInstanceOf( 'WP_Error', $ret );
$this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) );
@unlink( $file );
@unlink( $ret['path'] );
}
$this->assertNotInstanceOf( 'WP_Error', $ret );
$this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) );
unlink( $ret['path'] );
}
// Clean up
unset( $img );
}
@ -289,11 +288,15 @@ class Tests_Image_Functions extends WP_UnitTestCase {
public function test_wp_crop_image_url() {
if ( !function_exists( 'imagejpeg' ) )
$this->markTestSkipped( 'jpeg support unavailable' );
$file = wp_crop_image( 'http://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
0, 0, 100, 100, 100, 100, false,
DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
$this->markTestSkipped( 'jpeg support unavailable' );
if ( ! extension_loaded( 'openssl' ) ) {
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' );
}
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
0, 0, 100, 100, 100, 100, false,
DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
$this->assertNotInstanceOf( 'WP_Error', $file );
$this->assertFileExists( $file );
$image = wp_get_image_editor( $file );
@ -309,11 +312,15 @@ class Tests_Image_Functions extends WP_UnitTestCase {
0, 0, 100, 100, 100, 100 );
$this->assertInstanceOf( 'WP_Error', $file );
}
public function test_wp_crop_image_url_not_exist() {
$file = wp_crop_image( 'http://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
0, 0, 100, 100, 100, 100 );
$this->assertInstanceOf( 'WP_Error', $file );
public function test_wp_crop_image_url_not_exist() {
if ( ! extension_loaded( 'openssl' ) ) {
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' );
}
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
0, 0, 100, 100, 100, 100 );
$this->assertInstanceOf( 'WP_Error', $file );
}
function mock_image_editor( $editors ) {

View File

@ -1,13 +1,17 @@
<?php
/**
* @group image
<?php
/**
* @group image
* @group media
* @group upload
*/
class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
function test_make_intermediate_size_no_size() {
$image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
*/
class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
function tearDown() {
$this->remove_added_uploads();
parent::tearDown();
}
function test_make_intermediate_size_no_size() {
$image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
$this->assertFalse( $image );
}

View File

@ -2,11 +2,14 @@
/**
* @group image
* @group media
* @group upload
*/
abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase {
* @group media
* @group upload
* @group resize
*/
require_once( dirname( __FILE__ ) . '/base.php' );
abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase {
function test_resize_jpg() {
$image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.jpg', 25, 25 );
@ -106,11 +109,11 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
list($w, $h, $type) = getimagesize($image);
$this->assertEquals( 150, $w );
$this->assertEquals( 100, $h );
$this->assertEquals( IMAGETYPE_JPEG, $type );
unlink($image);
}
$this->assertEquals( IMAGETYPE_JPEG, $type );
unlink( $image );
}
function test_resize_thumb_50x150_crop() {
$image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 50, 150, true );
@ -133,21 +136,10 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
$this->assertInstanceOf( 'WP_Error', $image );
$this->assertEquals( 'error_loading_image', $image->get_error_code() );
}
/**
* Try resizing a php file (bad image)
* @ticket 6821
*/
public function test_resize_bad_image() {
$image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
$this->assertInstanceOf( 'WP_Error', $image );
$this->assertEquals( 'invalid_image', $image->get_error_code() );
}
/**
* Function to help out the tests
*/
/**
* Function to help out the tests
*/
protected function resize_helper( $file, $width, $height, $crop = false ) {
$editor = wp_get_image_editor( $file );

View File

@ -2,14 +2,36 @@
/**
* @group image
* @group media
* @group upload
*/
class Test_Image_Resize_GD extends WP_Tests_Image_Resize_UnitTestCase {
* @group media
* @group upload
* @group resize
*/
require_once( dirname( __FILE__ ) . '/resize.php' );
class Test_Image_Resize_GD extends WP_Tests_Image_Resize_UnitTestCase {
/**
* Use the GD image editor engine
* @var string
*/
public $editor_engine = 'WP_Image_Editor_GD';
}
*/
public $editor_engine = 'WP_Image_Editor_GD';
public function setUp() {
require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );
parent::setUp();
}
/**
* Try resizing a php file (bad image)
* @ticket 6821
*/
public function test_resize_bad_image() {
$image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
$this->assertInstanceOf( 'WP_Error', $image );
$this->assertEquals( 'invalid_image', $image->get_error_code() );
}
}

View File

@ -2,14 +2,24 @@
/**
* @group image
* @group media
* @group upload
*/
class Test_Image_Resize_Imagick extends WP_Tests_Image_Resize_UnitTestCase {
* @group media
* @group upload
* @group resize
*/
require_once( dirname( __FILE__ ) . '/resize.php' );
class Test_Image_Resize_Imagick extends WP_Tests_Image_Resize_UnitTestCase {
/**
* Use the Imagick image editor engine
* @var string
*/
public $editor_engine = 'WP_Image_Editor_Imagick';
}
*/
public $editor_engine = 'WP_Image_Editor_Imagick';
public function setUp() {
require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
parent::setUp();
}
}

View File

@ -1,53 +0,0 @@
<?php
/**
* @ticket 22435
*/
class Test_WP_Post_IDs_Iterator extends WP_UnitTestCase {
function setUp() {
if ( ! class_exists( 'WP_Post_IDs_Iterator' ) ) {
$this->markTestSkipped( "WP_Post_IDs_Iterator class doesn't exist" );
}
parent::setUp();
}
function test_create() {
new WP_Post_IDs_Iterator( array( 1, 2, 3 ) );
}
function test_no_posts() {
$this->assertIteratorReturnsSamePostIDs( array() );
}
function test_less_ids_than_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1 ), 10 );
}
function test_ids_exactly_as_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1 ), 2 );
}
function test_more_ids_than_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$post_id_2 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1, $post_id_2 ), 2 );
}
function test_ids_exactly_twice_more_than_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$post_id_2 = $this->factory->post->create();
$post_id_3 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1, $post_id_2, $post_id_3 ), 2 );
}
private function assertIteratorReturnsSamePostIDs( $post_ids, $limit = 2 ) {
$this->assertEquals( $post_ids, wp_list_pluck( iterator_to_array( new WP_Post_IDs_Iterator( $post_ids, $limit ) ), 'ID' ) );
}
}

View File

@ -14,18 +14,6 @@ class Tests_L10n extends WP_UnitTestCase {
$this->assertTrue( load_textdomain( 'wp-tests-domain', $file ) );
$this->assertTrue( is_textdomain_loaded( 'wp-tests-domain' ) );
$this->assertTrue( unload_textdomain( 'wp-tests-domain' ) );
$this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
}
/**
* @ticket 21319
*/
function test_is_textdomain_loaded_for_no_translations() {
$this->assertFalse( load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/non-existent-file' ) );
$this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
$this->assertInstanceOf( 'NOOP_Translations', get_translations_for_domain( 'wp-tests-domain' ) );
// Ensure that we don't confuse NOOP_Translations to be a loaded text domain.
$this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
$this->assertFalse( unload_textdomain( 'wp-tests-domain' ) );
}
}
$this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
}
}

View File

@ -1,10 +1,16 @@
<?php
/**
* @group link
*/
class Tests_Link extends WP_UnitTestCase {
function _get_pagenum_link_cb( $url ) {
*/
class Tests_Link extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
parent::tearDown();
}
function _get_pagenum_link_cb( $url ) {
return $url . '/WooHoo';
}
@ -27,12 +33,18 @@ class Tests_Link extends WP_UnitTestCase {
$_SERVER['REQUEST_URI'] = $old_req_uri;
}
function test_wp_get_shortlink() {
$post_id = $this->factory->post->create();
$post_id2 = $this->factory->post->create();
// Basic case
function test_wp_get_shortlink() {
global $wp_rewrite;
$post_id = $this->factory->post->create();
$post_id2 = $this->factory->post->create();
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
// Basic case
$this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
unset( $GLOBALS['post'] );
@ -57,12 +69,10 @@ class Tests_Link extends WP_UnitTestCase {
// Global post is not set, once again
$this->assertEquals( '', wp_get_shortlink( 0, 'post' ) );
$this->assertEquals( '', wp_get_shortlink( 0 ) );
$this->assertEquals( '', wp_get_shortlink() );
global $wp_rewrite;
$wp_rewrite->permalink_structure = '';
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules();
$this->assertEquals( '', wp_get_shortlink() );
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules();
// With a permalink structure set, get_permalink() will no longer match.
$this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
@ -71,31 +81,24 @@ class Tests_Link extends WP_UnitTestCase {
// Global post and permalink structure are set
$GLOBALS['post'] = get_post( $post_id );
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) );
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() );
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
}
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() );
}
function test_wp_get_shortlink_with_page() {
$post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
// Basic case
// Don't test against get_permalink() since it uses ?page_id= for pages.
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
global $wp_rewrite;
$wp_rewrite->permalink_structure = '';
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules();
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
}
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules();
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
}
/**
* @ticket 17807
*/

View File

@ -67,44 +67,10 @@ class Tests_Mail extends WP_UnitTestCase {
// We need some better assertions here but these catch the failure for now.
$this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
}
/**
* @ticket 15448
*/
function test_wp_mail_plain_and_html() {
$to = 'user@example.com';
$subject = 'Test email with plain text and html versions';
$messages = array( 'text/plain' => 'Here is some plain text.',
'text/html' =>'<html><head></head><body>Here is the HTML ;-)<body></html>' );
wp_mail( $to, $subject, $messages );
preg_match( '/boundary="(.*)"/', $GLOBALS['phpmailer']->mock_sent[0]['header'], $matches);
$boundry = $matches[1];
$body = '--' . $boundry . '
Content-Type: text/plain; charset = "UTF-8"
Content-Transfer-Encoding: 8bit
Here is some plain text.
--' . $boundry . '
Content-Type: text/html; charset = "UTF-8"
Content-Transfer-Encoding: 8bit
<html><head></head><body>Here is the HTML ;-)<body></html>
--' . $boundry . '--
';
// We need some better assertions here but these test the behaviour for now.
$this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
}
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
}
/**
* @ticket 17305
*/

View File

@ -364,20 +364,46 @@ CONTENT;
'type' => 'image/jpeg',
'error' => 0,
'size' => filesize( $test_file ),
);
$post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
unset( $_FILES['upload'] );
);
$post_id = media_handle_upload(
'upload',
0,
array(),
array(
'action' => 'test_upload_titles',
'test_form' => false,
/*
* This test previously failed on WP < 4.0 due to is_uploaded_file()
* and move_uploaded_file() usage in wp_handle_upload().
*
* Since successful upload is irrelevant for the purpose of this test,
* discarding upload errors allows the test to proceed.
*/
'upload_error_handler' => array( $this, '_discard_upload_errors' ),
)
);
unset( $_FILES['upload'] );
$post = get_post( $post_id );
// Clean up.
wp_delete_attachment( $post_id );
$this->assertEquals( 'This is a test', $post->post_title );
}
$this->assertEquals( 'This is a test', $post->post_title );
}
function _discard_upload_errors( &$file, $message ) {
$uploads = wp_upload_dir();
$filename = wp_unique_filename( $uploads['path'], $file['name'] );
$new_file = $uploads['path'] . "/$filename";
$url = $uploads['url'] . "/$filename";
return array( 'file' => $new_file, 'url' => $url, 'type' => $file['type'] );
}
/**
* @ticket 33016
*/

View File

@ -17,83 +17,10 @@ class Tests_Option_BlogOption extends WP_UnitTestCase {
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
}
function test_from_same_site() {
$key = rand_str();
$key2 = rand_str();
$value = rand_str();
$value2 = rand_str();
$this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
$this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
$this->assertTrue( add_blog_option( 1, $key, $value ) );
// Assert all values of $blog_id that means the current or main blog (the same here).
$this->assertEquals( $value, get_blog_option( 1, $key ) );
$this->assertEquals( $value, get_blog_option( null, $key ) );
$this->assertEquals( $value, get_blog_option( '1', $key ) );
$this->assertEquals( $value, get_option( $key ) ); // check get_option()
$this->assertFalse( add_blog_option( 1, $key, $value ) ); // Already exists
$this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same
$this->assertTrue( update_blog_option( 1, $key, $value2 ) );
$this->assertEquals( $value2, get_blog_option( 1, $key ) );
$this->assertEquals( $value2, get_option( $key ) ); // check get_option()
$this->assertFalse( add_blog_option( 1, $key, $value ) );
$this->assertEquals( $value2, get_blog_option( 1, $key ) );
$this->assertEquals( $value2, get_option( $key ) ); // check get_option()
$this->assertTrue( delete_blog_option( 1, $key ) );
$this->assertFalse( get_blog_option( 1, $key ) );
$this->assertFalse( get_option( $key ) ); // check get_option()
$this->assertFalse( delete_blog_option( 1, $key ) );
$this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
$this->assertEquals( $value2, get_blog_option( 1, $key2 ) );
$this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
$this->assertTrue( delete_blog_option( 1, $key2 ) );
$this->assertFalse( get_blog_option( 1, $key2 ) );
$this->assertFalse( get_option( $key2 ) ); // check get_option()
}
function test_from_same_site_with_null_blog_id() {
$key = rand_str();
$key2 = rand_str();
$value = rand_str();
$value2 = rand_str();
$this->assertFalse( get_blog_option( null, 'doesnotexist' ) );
$this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
$this->assertTrue( add_blog_option( null, $key, $value ) );
// Assert all values of $blog_id that means the current or main blog (the same here).
$this->assertEquals( $value, get_blog_option( null, $key ) );
$this->assertEquals( $value, get_blog_option( null, $key ) );
$this->assertEquals( $value, get_option( $key ) ); // check get_option()
$this->assertFalse( add_blog_option( null, $key, $value ) ); // Already exists
$this->assertFalse( update_blog_option( null, $key, $value ) ); // Value is the same
$this->assertTrue( update_blog_option( null, $key, $value2 ) );
$this->assertEquals( $value2, get_blog_option( null, $key ) );
$this->assertEquals( $value2, get_option( $key ) ); // check get_option()
$this->assertFalse( add_blog_option( null, $key, $value ) );
$this->assertEquals( $value2, get_blog_option( null, $key ) );
$this->assertEquals( $value2, get_option( $key ) ); // check get_option()
$this->assertTrue( delete_blog_option( null, $key ) );
$this->assertFalse( get_blog_option( null, $key ) );
$this->assertFalse( get_option( $key ) ); // check get_option()
$this->assertFalse( delete_blog_option( null, $key ) );
$this->assertTrue( update_blog_option( null, $key2, $value2 ) );
$this->assertEquals( $value2, get_blog_option( null, $key2 ) );
$this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
$this->assertTrue( delete_blog_option( null, $key2 ) );
$this->assertFalse( get_blog_option( null, $key2 ) );
$this->assertFalse( get_option( $key2 ) ); // check get_option()
}
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
}
function test_with_another_site() {
global $current_site, $base;

View File

@ -444,11 +444,13 @@ class Tests_Post extends WP_UnitTestCase {
function test_permalink_without_title() {
// bug: permalink doesn't work if post title is empty
// might only fail if the post ID is greater than four characters
global $wp_rewrite;
$wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
$post = array(
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
$wp_rewrite->flush_rules();
$post = array(
'post_author' => $this->author_id,
'post_status' => 'publish',
'post_content' => rand_str(),
@ -733,65 +735,10 @@ class Tests_Post extends WP_UnitTestCase {
$this->assertTrue( ( is_int($insert_post_id) && $insert_post_id > 0 ) );
$post = get_post( $insert_post_id );
$this->assertEquals( $post->post_author, $this->author_id );
$this->assertEquals( $post->post_title, $title );
}
/**
* @ticket 19373
*/
function test_insert_programmatic_without_current_user_success() {
$this->_unset_current_user();
register_taxonomy( 'test_tax', 'post' );
$title = rand_str();
$post_data = array(
'post_author' => $this->author_id,
'post_status' => 'public',
'post_content' => rand_str(),
'post_title' => $title,
'tax_input' => array(
'test_tax' => array( 'term', 'term2', 'term3' )
)
);
// with sanitize set to false
$insert_post_id = wp_insert_post( $post_data, true, false );
$post = get_post( $insert_post_id );
$this->assertEquals( $post->post_author, $this->author_id );
$this->assertEquals( $post->post_title, $title );
$terms = wp_get_object_terms( $insert_post_id, 'test_tax' );
$this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) );
}
/**
* @ticket 19373
*/
function test_insert_programmatic_without_current_user_fail() {
$this->_unset_current_user();
register_taxonomy( 'test_tax', 'post' );
$title = rand_str();
$post_data = array(
// post_author not set
'post_status' => 'public',
'post_content' => rand_str(),
'post_title' => $title,
'tax_input' => array(
'test_tax' => array( 'term', 'term2', 'term3' )
)
);
// with sanitize set to false
$insert_post_id = wp_insert_post( $post_data, true, false );
// should error because no default user exists and no post author is passed in
$this->assertInstanceOf( 'WP_Error', $insert_post_id );
$this->assertEquals( 'empty_author', $insert_post_id->get_error_code() );
}
$this->assertEquals( $post->post_author, $this->author_id );
$this->assertEquals( $post->post_title, $title );
}
/**
* @ticket 24803
*/

View File

@ -7,14 +7,11 @@
*/
class Tests_Post_Attachments extends WP_UnitTestCase {
function tearDown() {
// Remove all uploads.
$uploads = wp_upload_dir();
foreach ( scandir( $uploads['basedir'] ) as $file )
_rmdir( $uploads['basedir'] . '/' . $file );
parent::tearDown();
}
function tearDown() {
// Remove all uploads.
$this->remove_added_uploads();
parent::tearDown();
}
function _make_attachment( $upload, $parent_post_id = 0 ) {
@ -209,26 +206,6 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
$this->assertFalse( is_file($thumb['path']) );
$this->assertFalse( is_file($medium['path']) );
$this->assertFalse( is_file($original) );
}
/**
* GUID should never be empty
* @ticket 18310
* @ticket 21963
*/
function test_insert_image_without_guid() {
// this image is smaller than the thumbnail size so it won't have one
$filename = ( DIR_TESTDATA.'/images/test-image.jpg' );
$contents = file_get_contents($filename);
$upload = wp_upload_bits(basename($filename), null, $contents);
$this->assertTrue( empty($upload['error']) );
$upload['url'] = '';
$id = $this->_make_attachment( $upload );
$guid = get_the_guid( $id );
$this->assertFalse( empty( $guid ) );
}
}
}
}

View File

@ -88,110 +88,10 @@ EOF;
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span a --more-- tag
* @ticket 6297
*/
function test_post_content_unbalanced_more() {
$content = <<<EOF
<em>some text<!--more-->
that's continued after the jump</em>
EOF;
$expected = <<<EOF
<em>some text</em><!--more-->
that's continued after the jump
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span a --nextpage-- tag
* @ticket 6297
*/
function test_post_content_unbalanced_nextpage() {
$content = <<<EOF
<em>some text<!--nextpage-->
that's continued after the jump</em>
EOF;
$expected = <<<EOF
<em>some text</em><!--nextpage-->
that's continued after the jump
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span both --more-- and --nextpage-- tags (in that order)
* @ticket 6297
*/
function test_post_content_unbalanced_more_nextpage() {
$content = <<<EOF
<em>some text<!--more-->
that's continued after the jump</em>
<!--nextpage-->
<p>and the next page
<!--nextpage-->
breaks the graf</p>
EOF;
$expected = <<<EOF
<em>some text</em><!--more-->
that's continued after the jump
<!--nextpage-->
<p>and the next page
</p><!--nextpage-->
breaks the graf
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span both --nextpage-- and --more-- tags (in that order)
* @ticket 6297
*/
function test_post_content_unbalanced_nextpage_more() {
$content = <<<EOF
<em>some text<!--nextpage-->
that's continued after the jump</em>
<!--more-->
<p>and the next page
<!--nextpage-->
breaks the graf</p>
EOF;
$expected = <<<EOF
<em>some text</em><!--nextpage-->
that's continued after the jump
<!--more-->
<p>and the next page
</p><!--nextpage-->
breaks the graf
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
// make sure unbalanced tags are untouched when the balance option is off
function test_post_content_nobalance_nextpage_more() {
}
// make sure unbalanced tags are untouched when the balance option is off
function test_post_content_nobalance_nextpage_more() {
update_option('use_balanceTags', 0);

View File

@ -1,156 +0,0 @@
<?php
/**
* @group media
* @group gallery
* @ticket UT30
*/
class Tests_Post_Gallery extends WP_UnitTestCase { // _WPDataset1
function setUp() {
parent::setUp();
global $wp_rewrite;
$wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
$wp_rewrite->flush_rules();
}
function test_the_content() {
// permalink page
$link = '/2008/04/01/simple-gallery-test/';
$this->go_to('/2008/04/01/simple-gallery-test/');
the_post();
// filtered output
$out = get_echo('the_content');
$this->assertNotEmpty($out, "Could not get the_content for $link.");
$expected = <<<EOF
<p>There are ten images attached to this post.  Here&#8217;s a gallery:</p>
<style type='text/css'>
.gallery {
margin: auto;
}
.gallery-item {
float: left;
margin-top: 10px;
text-align: center;
width: 33%; }
.gallery img {
border: 2px solid #cfcfcf;
}
.gallery-caption {
margin-left: 0;
}
</style>
<!-- see gallery_shortcode() in wp-includes/media.php -->
<div class='gallery'><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20040724_152504_53/' title='dsc20040724_152504_53'><img src="http://example.com/wp-content/uploads/2008/04/dsc20040724_152504_537.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/canola/' title='canola'><img src="http://example.com/wp-content/uploads/2008/04/canola3.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050315_145007_13/' title='dsc20050315_145007_13'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050315_145007_134.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050604_133440_34/' title='dsc20050604_133440_34'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050604_133440_343.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050831_165238_33/' title='dsc20050831_165238_33'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050831_165238_333.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050901_105100_21/' title='dsc20050901_105100_21'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050901_105100_213.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050813_115856_5/' title='dsc20050813_115856_5'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050813_115856_54.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050720_123726_27/' title='dsc20050720_123726_27'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050720_123726_274.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050727_091048_22/' title='Title: Seedlings'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050727_091048_224.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050726_083116_18/' title='dsc20050726_083116_18'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050726_083116_184.jpg" class="attachment-thumbnail" alt="" /></a>
</dt></dl>
<br style='clear: both;' />
</div>
<p>It&#8217;s the simplest form of the gallery tag.  All images are from the public domain site burningwell.org.</p>
<p>The images have various combinations of titles, captions and descriptions.</p>
EOF;
$this->assertEquals(strip_ws($expected), strip_ws($out));
}
function test_gallery_attributes() {
// make sure the gallery shortcode attributes are parsed correctly
$id = 575;
$post = get_post($id);
$this->assertNotNull($post, "get_post($id) could not find the post.");
$post->post_content = '[gallery columns="1" size="medium"]';
wp_update_post($post);
// permalink page
$this->go_to('/2008/04/01/simple-gallery-test/');
the_post();
// filtered output
$out = get_echo('the_content');
$expected = <<<EOF
<style type='text/css'>
.gallery {
margin: auto;
}
.gallery-item {
float: left;
margin-top: 10px;
text-align: center;
width: 100%; }
.gallery img {
border: 2px solid #cfcfcf;
}
.gallery-caption {
margin-left: 0;
}
</style>
<!-- see gallery_shortcode() in wp-includes/media.php -->
<div class='gallery'><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=565' title='dsc20040724_152504_53'><img src="http://example.com/wp-content/uploads/2008/04/dsc20040724_152504_537.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=566' title='canola'><img src="http://example.com/wp-content/uploads/2008/04/canola3.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=567' title='dsc20050315_145007_13'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050315_145007_134.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=568' title='dsc20050604_133440_34'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050604_133440_343.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=569' title='dsc20050831_165238_33'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050831_165238_333.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=570' title='dsc20050901_105100_21'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050901_105100_213.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=571' title='dsc20050813_115856_5'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050813_115856_54.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=572' title='dsc20050720_123726_27'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050720_123726_274.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=573' title='Title: Seedlings'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050727_091048_224.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://example.com/?attachment_id=574' title='dsc20050726_083116_18'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050726_083116_184.jpg" class="attachment-medium" alt="" /></a>
</dt></dl><br style="clear: both" />
<br style='clear: both;' />
</div>
EOF;
$this->assertEquals(strip_ws($expected), strip_ws($out));
}
}

View File

@ -51,46 +51,10 @@ class Tests_Post_Revisions extends WP_UnitTestCase {
//is post_meta correctly set to revision author
$this->assertEquals( $admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user
wp_set_current_user( 0 );
}
/**
* @ticket 7392
* @ticket 9843
*/
function test_revision_dont_save_revision_if_unchanged() {
$post = get_default_post_to_edit( 'post', true );
$post_id = $post->ID;
$this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation.
wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_content' => 'some_content', 'ID' => $post_id ) );
$this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision
// First update
wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) );
$this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far
//update the post
wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision
$this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far
//next try to save another identical update, tests for patch that prevents storing duplicates
wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
$this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision
//next try to save another update, same content, but new ttile, should save revision
wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) );
$this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should be 4 revision
//next try to save another identical update
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
$this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision
}
wp_set_current_user( 0 );
}
/**
* @ticket 7392
* @ticket 9843

View File

@ -1,8 +1,20 @@
<?php
class Tests_Query extends WP_UnitTestCase {
/**
class Tests_Query extends WP_UnitTestCase {
function setUp() {
global $wp_rewrite;
parent::setUp();
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
$wp_rewrite->flush_rules();
}
/**
* @ticket 16746
*/
function test_nextpage_at_start_of_content() {

View File

@ -21,18 +21,23 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
update_option( 'comments_per_page', 5 );
update_option( 'posts_per_page', 5 );
global $wp_rewrite;
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules();
}
function tearDown() {
$GLOBALS['wp_rewrite']->init();
parent::tearDown();
}
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
$wp_rewrite->flush_rules();
}
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
parent::tearDown();
}
function test_home() {
$this->go_to('/');

View File

@ -277,34 +277,10 @@ class Tests_Query_Results extends WP_UnitTestCase {
$this->assertTrue( $this->q->is_paged() );
$this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) );
}
/**
* @ticket 18897
*/
function test_query_offset_and_paged() {
$posts = $this->q->query('paged=2&offset=3');
$expected = array (
0 => 'many-trackbacks',
1 => 'one-trackback',
2 => 'comment-test',
3 => 'lorem-ipsum',
4 => 'cat-c',
5 => 'cat-b',
6 => 'cat-a',
7 => 'cats-a-and-c',
8 => 'cats-b-and-c',
9 => 'cats-a-and-b',
);
$this->assertCount( 10, $posts );
$this->assertTrue( $this->q->is_paged() );
$this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) );
}
/**
* @ticket 11056
*/
/**
* @ticket 11056
*/
function test_query_post_parent__in() {
// Query for first parent's children
$posts = $this->q->query( array(

View File

@ -20,24 +20,25 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
protected $uncat;
protected $tag;
protected $tax;
function setUp() {
parent::setUp();
set_current_screen( 'front' );
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
$GLOBALS['wp_the_query'] = new WP_Query();
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
create_initial_taxonomies();
register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules();
$this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
function setUp() {
global $wp_rewrite;
parent::setUp();
set_current_screen( 'front' );
$GLOBALS['wp_the_query'] = new WP_Query();
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
$wp_rewrite->flush_rules();
$this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
$this->cat_id = $this->factory->category->create( array( 'slug' => 'cat-slug' ) );
$this->tax_id = $this->factory->term->create( array( 'taxonomy' => 'testtax', 'slug' => 'tax-slug' ) );
$this->tax_id2 = $this->factory->term->create( array( 'taxonomy' => 'testtax', 'slug' => 'tax-slug2' ) );
@ -54,13 +55,16 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
add_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
}
function tearDown() {
parent::tearDown();
_unregister_taxonomy( 'testtax' );
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
function tearDown() {
global $wp_rewrite;
parent::tearDown();
_unregister_taxonomy( 'testtax' );
$wp_rewrite->init();
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
}
function test_tag_action_tax() {

View File

@ -6,13 +6,17 @@ require_once dirname( dirname( __FILE__ ) ) . '/query.php';
* @group query
* @group rewrite
*/
class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals {
function setUp() {
parent::setUp();
global $wp_rewrite;
update_option( 'permalink_structure', '/%category%/%year%/%postname%/' );
create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules();
}
}
class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals {
function setUp() {
global $wp_rewrite;
parent::setUp();
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%category%/%year%/%postname%/' );
create_initial_taxonomies();
$wp_rewrite->flush_rules();
}
}

View File

@ -6,22 +6,26 @@
* @group rewrite
*/
class Tests_Rewrite extends WP_UnitTestCase {
function setUp() {
parent::setUp();
// Need rewrite rules in place to use url_to_postid
global $wp_rewrite;
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules();
}
function tearDown() {
$GLOBALS['wp_rewrite']->init();
parent::tearDown();
}
function setUp() {
global $wp_rewrite;
parent::setUp();
// Need rewrite rules in place to use url_to_postid
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
$wp_rewrite->flush_rules();
}
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
parent::tearDown();
}
function test_url_to_postid() {
@ -32,20 +36,20 @@ class Tests_Rewrite extends WP_UnitTestCase {
$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
}
function test_url_to_postid_custom_post_type() {
delete_option( 'rewrite_rules' );
$post_type = rand_str( 12 );
register_post_type( $post_type, array( 'public' => true ) );
$id = $this->factory->post->create( array( 'post_type' => $post_type ) );
$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
_unregister_post_type( $post_type );
}
function test_url_to_postid_hierarchical() {
function test_url_to_postid_custom_post_type() {
delete_option( 'rewrite_rules' );
$post_type = rand_str( 12 );
register_post_type( $post_type, array( 'public' => true ) );
$id = $this->factory->post->create( array( 'post_type' => $post_type ) );
$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
_unregister_post_type( $post_type );
}
function test_url_to_postid_hierarchical() {
$parent_id = $this->factory->post->create( array( 'post_title' => 'Parent', 'post_type' => 'page' ) );
$child_id = $this->factory->post->create( array( 'post_title' => 'Child', 'post_type' => 'page', 'post_parent' => $parent_id ) );

View File

@ -306,20 +306,10 @@ EOF;
$test_string = "[footag]\n";
$this->assertEquals( $test_string, shortcode_unautop( wpautop( $test_string ) ) );
}
/**
* @ticket 14050
*/
function test_multiple_shortcode_unautop() {
// a blank line is added at the end, so test with it already there
$test_string = "[footag]\n[footag]\n";
$actual = shortcode_unautop( wpautop( $test_string ) );
$this->assertEquals( $test_string, $actual );
}
/**
* @ticket 10326
*/
/**
* @ticket 10326
*/
function test_strip_shortcodes() {
$this->assertEquals('before', strip_shortcodes('before[gallery]'));
$this->assertEquals('after', strip_shortcodes('[gallery]after'));

View File

@ -103,58 +103,10 @@ class Tests_Taxonomy extends WP_UnitTestCase {
function test_register_long_taxonomy() {
$this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) );
}
/**
* @ticket 11058
*/
function test_registering_taxonomies_to_object_types() {
// Create a taxonomy to test with
$tax = 'test_tax';
$this->assertFalse( taxonomy_exists($tax) );
register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );
// Create a post type to test with
$post_type = 'test_cpt';
$this->assertFalse( get_post_type( $post_type ) );
$this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) );
// Core taxonomy, core post type
$this->assertTrue( unregister_taxonomy_for_object_type( 'category', 'post' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'post' ) );
$this->assertTrue( register_taxonomy_for_object_type( 'category', 'post' ) );
// Core taxonomy, non-core post type
$this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
$this->assertTrue( unregister_taxonomy_for_object_type( 'category', $post_type ) );
$this->assertFalse( unregister_taxonomy_for_object_type( 'category', $post_type ) );
$this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
// Core taxonomies, non-post object types
$this->assertFalse( register_taxonomy_for_object_type( 'category', 'user' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'user' ) );
// Non-core taxonomy, core post type
$this->assertTrue( unregister_taxonomy_for_object_type( $tax, 'post' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'post' ) );
$this->assertTrue( register_taxonomy_for_object_type( $tax, 'post' ) );
// Non-core taxonomy, non-core post type
$this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
$this->assertTrue( unregister_taxonomy_for_object_type( $tax, $post_type ) );
$this->assertFalse( unregister_taxonomy_for_object_type( $tax, $post_type ) );
$this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
// Non-core taxonomies, non-post object types
$this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) );
unset($GLOBALS['wp_taxonomies'][$tax]);
_unregister_post_type( $post_type );
}
/**
* @ticket 25706
*/
/**
* @ticket 25706
*/
function test_in_category() {
$post = $this->factory->post->create_and_get();

View File

@ -410,56 +410,10 @@ class Tests_Term extends WP_UnitTestCase {
foreach ( array( $a, $b, $c, $d, $e, $f ) as $t )
$this->assertTrue( wp_delete_term( $t['term_id'], $this->taxonomy ) );
}
/**
* @ticket 5809
*/
function test_update_shared_term() {
$random_tax = __FUNCTION__;
register_taxonomy( $random_tax, 'post' );
$post_id = $this->factory->post->create();
$old_name = 'Initial';
$t1 = wp_insert_term( $old_name, 'category' );
$t2 = wp_insert_term( $old_name, 'post_tag' );
$this->assertEquals( $t1['term_id'], $t2['term_id'] );
wp_set_post_categories( $post_id, array( $t1['term_id'] ) );
wp_set_post_tags( $post_id, array( (int) $t2['term_id'] ) );
$new_name = 'Updated';
// create the term in a third taxonomy, just to keep things interesting
$t3 = wp_insert_term( $old_name, $random_tax );
wp_set_post_terms( $post_id, array( (int) $t3['term_id'] ), $random_tax );
$this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );
$t2_updated = wp_update_term( $t2['term_id'], 'post_tag', array(
'name' => $new_name
) );
$this->assertNotEquals( $t2_updated['term_id'], $t3['term_id'] );
// make sure the terms have split
$this->assertEquals( $old_name, get_term_field( 'name', $t1['term_id'], 'category' ) );
$this->assertEquals( $new_name, get_term_field( 'name', $t2_updated['term_id'], 'post_tag' ) );
// and that they are still assigned to the correct post
$this->assertPostHasTerms( $post_id, array( $t1['term_id'] ), 'category' );
$this->assertPostHasTerms( $post_id, array( $t2_updated['term_id'] ), 'post_tag' );
$this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );
// clean up
unset( $GLOBALS['wp_taxonomies'][ $random_tax ] );
}
/**
* @ticket 17646
*/
/**
* @ticket 17646
*/
function test_get_object_terms_types() {
$post_id = $this->factory->post->create();
$term = wp_insert_term( 'one', $this->taxonomy );
@ -496,32 +450,6 @@ class Tests_Term extends WP_UnitTestCase {
$this->assertEquals( $expected_term_ids, $assigned_term_ids );
}
/**
* @ticket 24189
*/
function test_object_term_cache_when_term_changes() {
$post_id = $this->factory->post->create();
$tag_id = $this->factory->tag->create( array( 'description' => 'My Amazing Tag' ) );
$tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' );
$terms = get_the_terms( $post_id, 'post_tag' );
$this->assertEquals( $tag_id, $terms[0]->term_id );
$this->assertEquals( 'My Amazing Tag', $terms[0]->description );
$_updated = wp_update_term( $tag_id, 'post_tag', array(
'description' => 'This description is even more amazing!'
) );
$_new_term = get_term( $tag_id, 'post_tag' );
$this->assertEquals( $tag_id, $_new_term->term_id );
$this->assertEquals( 'This description is even more amazing!', $_new_term->description );
$terms = get_the_terms( $post_id, 'post_tag' );
$this->assertEquals( $tag_id, $terms[0]->term_id );
$this->assertEquals( 'This description is even more amazing!', $terms[0]->description );
}
function test_wp_set_post_categories() {
$post_id = $this->factory->post->create();
$post = get_post( $post_id );

View File

@ -1,97 +0,0 @@
<?php
/**
* @group upload
* @group media
*/
class Tests_Upload extends WP_UnitTestCase {
var $siteurl;
function setUp() {
if ( is_multisite() )
$this->knownUTBug( 35 );
parent::setUp();
return;
// system defaults
update_option( 'upload_path', 'wp-content/uploads' );
update_option( 'upload_url_path', '' );
update_option( 'uploads_use_yearmonth_folders', 1 );
}
function tearDown() {
parent::tearDown();
// Remove year/month folders created by wp_upload_dir().
$uploads = wp_upload_dir();
foreach ( scandir( $uploads['basedir'] ) as $file )
_rmdir( $uploads['basedir'] . '/' . $file );
_rmdir( ABSPATH . 'foo/' );
}
function test_upload_dir_default() {
// wp_upload_dir() with default parameters
$info = wp_upload_dir();
$this->assertEquals( get_option( 'siteurl' ) . '/wp-content/uploads/' . gmstrftime('%Y/%m'), $info['url'] );
$this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] );
$this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] );
$this->assertEquals( '', $info['error'] );
}
function test_upload_dir_relative() {
// wp_upload_dir() with a relative upload path that is not 'wp-content/uploads'
update_option( 'upload_path', 'foo/bar' );
$info = wp_upload_dir();
$this->assertEquals( get_option( 'siteurl' ) . '/foo/bar/' . gmstrftime('%Y/%m'), $info['url'] );
$this->assertEquals( ABSPATH . 'foo/bar/' . gmstrftime('%Y/%m'), $info['path'] );
$this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] );
$this->assertEquals( '', $info['error'] );
}
/**
* @ticket 5953
*/
function test_upload_dir_absolute() {
$path = '/tmp/wp-unit-test';
// wp_upload_dir() with an absolute upload path
update_option( 'upload_path', $path );
// doesn't make sense to use an absolute file path without setting the url path
update_option( 'upload_url_path', '/baz' );
$info = wp_upload_dir();
$this->assertEquals( '/baz/' . gmstrftime('%Y/%m'), $info['url'] );
$this->assertEquals( "$path/" . gmstrftime('%Y/%m'), $info['path'] );
$this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] );
$this->assertEquals( '', $info['error'] );
}
function test_upload_dir_no_yearnum() {
update_option( 'uploads_use_yearmonth_folders', 0 );
$info = wp_upload_dir();
$this->assertEquals( get_option( 'siteurl' ) . '/wp-content/uploads', $info['url'] );
$this->assertEquals( ABSPATH . 'wp-content/uploads', $info['path'] );
$this->assertEquals( '', $info['subdir'] );
$this->assertEquals( '', $info['error'] );
}
function test_upload_path_absolute() {
update_option( 'upload_url_path', 'http://example.org/asdf' );
$info = wp_upload_dir();
$this->assertEquals( 'http://example.org/asdf/' . gmstrftime('%Y/%m'), $info['url'] );
$this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] );
$this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] );
$this->assertEquals( '', $info['error'] );
}
function test_upload_dir_empty() {
// upload path setting is empty - it should default to 'wp-content/uploads'
update_option('upload_path', '');
$info = wp_upload_dir();
$this->assertEquals( get_option( 'siteurl' ) . '/wp-content/uploads/' . gmstrftime('%Y/%m'), $info['url'] );
$this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] );
$this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] );
$this->assertEquals( '', $info['error'] );
}
}

View File

@ -143,50 +143,10 @@ class Tests_User extends WP_UnitTestCase {
foreach ( (array) $user as $key => $value ) {
$this->assertEquals( $value, $user->$key );
}
}
/**
* Test the magic __unset method
*
* @ticket 20043
*/
public function test_user_unset() {
// New user
$user_id = $this->factory->user->create( array( 'role' => 'author' ) );
$user = new WP_User( $user_id );
// Test custom fields
$user->customField = 123;
$this->assertEquals( $user->customField, 123 );
unset( $user->customField );
$this->assertFalse( isset( $user->customField ) );
return $user;
}
/**
* @depends test_user_unset
* @expectedDeprecated WP_User->id
* @ticket 20043
*/
function test_user_unset_lowercase_id( $user ) {
// Test 'id' (lowercase)
unset( $user->id );
return $user;
}
/**
* @depends test_user_unset_lowercase_id
* @ticket 20043
*/
function test_user_unset_uppercase_id( $user ) {
// Test 'ID'
$this->assertNotEmpty( $user->ID );
unset( $user->ID );
$this->assertEmpty( $user->ID );
}
// Test meta property magic functions for property get/set/isset.
function test_user_meta_properties() {
}
// Test meta property magic functions for property get/set/isset.
function test_user_meta_properties() {
global $wpdb;
$user_id = $this->factory->user->create( array( 'role' => 'author' ) );

View File

@ -27,53 +27,6 @@ class Tests_XMLRPC_wp_uploadFile extends WP_XMLRPC_UnitTestCase {
$this->assertInternalType( 'string', $result['file'] );
$this->assertInternalType( 'string', $result['url'] );
$this->assertInternalType( 'string', $result['type'] );
}
/**
* @ticket 21292
*/
function test_network_limit() {
$this->make_user_by_role( 'editor' );
update_option( 'blog_upload_space', 0.1 );
// create attachment
$filename = ( DIR_TESTDATA . '/images/canola.jpg' );
$contents = file_get_contents( $filename );
$data = array(
'name' => 'canola.jpg',
'type' => 'image/jpeg',
'bits' => $contents
);
$result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) );
// Only multisite should have a limit
if ( is_multisite() )
$this->assertInstanceOf( 'IXR_Error', $result );
else
$this->assertNotInstanceOf( 'IXR_Error', $result );
}
/**
* @ticket 11946
*/
function test_valid_mime() {
$this->make_user_by_role( 'editor' );
// create attachment
$filename = ( DIR_TESTDATA . '/images/test-image-mime-jpg.png' );
$contents = file_get_contents( $filename );
$data = array(
'name' => 'test-image-mime-jpg.png',
'type' => 'image/png',
'bits' => $contents
);
$result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) );
$this->assertNotInstanceOf( 'IXR_Error', $result );
$this->assertEquals( 'image/jpeg', $result['type'] );
}
}
}
}