<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41261] trunk/tests/phpunit/tests: Tests: Rename tests with underscore in the name</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41261">41261</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41261","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-08-18 09:57:12 +0000 (Fri, 18 Aug 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Rename tests with underscore in the name
There were a handful of files with an underscore in the name, which violated our naming scheme, and caused problems for anyone how enforced the scheme on their own systems.
This commit renames all of the files to the correct camelCase scheme.
Fixes <a href="https://core.trac.wordpress.org/ticket/41658">#41658</a>.</pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfilesystemfindFolderphp">trunk/tests/phpunit/tests/filesystem/findFolder.php</a></li>
<li><a href="#trunktestsphpunittestshooksaddFilterphp">trunk/tests/phpunit/tests/hooks/addFilter.php</a></li>
<li><a href="#trunktestsphpunittestshooksapplyFiltersphp">trunk/tests/phpunit/tests/hooks/applyFilters.php</a></li>
<li><a href="#trunktestsphpunittestshooksdoActionphp">trunk/tests/phpunit/tests/hooks/doAction.php</a></li>
<li><a href="#trunktestsphpunittestshooksdoAllHookphp">trunk/tests/phpunit/tests/hooks/doAllHook.php</a></li>
<li><a href="#trunktestsphpunittestshookshasFilterphp">trunk/tests/phpunit/tests/hooks/hasFilter.php</a></li>
<li><a href="#trunktestsphpunittestshookshasFiltersphp">trunk/tests/phpunit/tests/hooks/hasFilters.php</a></li>
<li><a href="#trunktestsphpunittestshookspreinitHooksphp">trunk/tests/phpunit/tests/hooks/preinitHooks.php</a></li>
<li><a href="#trunktestsphpunittestshooksremoveAllFiltersphp">trunk/tests/phpunit/tests/hooks/removeAllFilters.php</a></li>
<li><a href="#trunktestsphpunittestshooksremoveFilterphp">trunk/tests/phpunit/tests/hooks/removeFilter.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditorGdphp">trunk/tests/phpunit/tests/image/editorGd.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditorImagickphp">trunk/tests/phpunit/tests/image/editorImagick.php</a></li>
<li><a href="#trunktestsphpunittestsimageintermediateSizephp">trunk/tests/phpunit/tests/image/intermediateSize.php</a></li>
<li><a href="#trunktestsphpunittestsimageresizeGdphp">trunk/tests/phpunit/tests/image/resizeGd.php</a></li>
<li><a href="#trunktestsphpunittestsimageresizeImagickphp">trunk/tests/phpunit/tests/image/resizeImagick.php</a></li>
<li><a href="#trunktestsphpunittestsimagesiteIconphp">trunk/tests/phpunit/tests/image/siteIcon.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfilesystemfind_folderphp">trunk/tests/phpunit/tests/filesystem/find_folder.php</a></li>
<li><a href="#trunktestsphpunittestshooksadd_filterphp">trunk/tests/phpunit/tests/hooks/add_filter.php</a></li>
<li><a href="#trunktestsphpunittestshooksapply_filtersphp">trunk/tests/phpunit/tests/hooks/apply_filters.php</a></li>
<li><a href="#trunktestsphpunittestshooksdo_actionphp">trunk/tests/phpunit/tests/hooks/do_action.php</a></li>
<li><a href="#trunktestsphpunittestshooksdo_all_hookphp">trunk/tests/phpunit/tests/hooks/do_all_hook.php</a></li>
<li><a href="#trunktestsphpunittestshookshas_filterphp">trunk/tests/phpunit/tests/hooks/has_filter.php</a></li>
<li><a href="#trunktestsphpunittestshookshas_filtersphp">trunk/tests/phpunit/tests/hooks/has_filters.php</a></li>
<li><a href="#trunktestsphpunittestshookspreinit_hooksphp">trunk/tests/phpunit/tests/hooks/preinit_hooks.php</a></li>
<li><a href="#trunktestsphpunittestshooksremove_all_filtersphp">trunk/tests/phpunit/tests/hooks/remove_all_filters.php</a></li>
<li><a href="#trunktestsphpunittestshooksremove_filterphp">trunk/tests/phpunit/tests/hooks/remove_filter.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditor_gdphp">trunk/tests/phpunit/tests/image/editor_gd.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditor_imagickphp">trunk/tests/phpunit/tests/image/editor_imagick.php</a></li>
<li><a href="#trunktestsphpunittestsimageintermediate_sizephp">trunk/tests/phpunit/tests/image/intermediate_size.php</a></li>
<li><a href="#trunktestsphpunittestsimageresize_gdphp">trunk/tests/phpunit/tests/image/resize_gd.php</a></li>
<li><a href="#trunktestsphpunittestsimageresize_imagickphp">trunk/tests/phpunit/tests/image/resize_imagick.php</a></li>
<li><a href="#trunktestsphpunittestsimagesite_iconphp">trunk/tests/phpunit/tests/image/site_icon.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsfilesystemfindFolderphpfromrev41260trunktestsphpunittestsfilesystemfind_folderphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/filesystem/findFolder.php (from rev 41260, trunk/tests/phpunit/tests/filesystem/find_folder.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/filesystem/findFolder.php (rev 0)
+++ trunk/tests/phpunit/tests/filesystem/findFolder.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,109 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+require_once dirname( __FILE__ ) . '/base.php';
+
+/**
+ * @group filesystem
+ * @group wp-filesystem
+ */
+class WP_Filesystem_find_folder_UnitTestCases extends WP_Filesystem_UnitTestCase {
+
+ function test_ftp_has_root_access() {
+ global $wp_filesystem;
+ $fs = $wp_filesystem;
+ $fs->init('
+ /var/www/wordpress/
+ /var/www/wordpress/wp-includes/
+ /var/www/wordpress/index.php
+ ');
+
+ $path = $fs->find_folder( '/var/www/wordpress/' );
+ $this->assertEquals( '/var/www/wordpress/', $path );
+
+ $path = $fs->find_folder( '/this/directory/doesnt/exist/' );
+ $this->assertFalse( $path );
+
+ }
+
+ function test_sibling_wordpress_in_subdir() {
+ global $wp_filesystem;
+ $fs = $wp_filesystem;
+ $fs->init('
+ /www/example.com/wordpress/
+ /www/example.com/wordpress/wp-includes/
+ /www/example.com/wordpress/index.php
+ /www/wp.example.com/wordpress/
+ /www/wp.example.com/wordpress/wp-includes/
+ /www/wp.example.com/wordpress/wp-content/
+ /www/wp.example.com/wordpress/index.php
+ /www/index.php
+ ');
+
+ $path = $fs->find_folder( '/var/www/example.com/wordpress/' );
+ $this->assertEquals( '/www/example.com/wordpress/', $path );
+
+ $path = $fs->find_folder( '/var/www/wp.example.com/wordpress/wp-content/' );
+ $this->assertEquals( '/www/wp.example.com/wordpress/wp-content/', $path );
+
+ }
+
+ /**
+ * Two WordPress installs, with one contained within the other
+ * FTP / = /var/www/example.com/ on Disk
+ * example.com at /
+ * wp.example.com at /wp.example.com/wordpress/
+ */
+ function test_subdir_of_another() {
+ global $wp_filesystem;
+ $fs = $wp_filesystem;
+ $fs->init('
+ /wp.example.com/index.php
+ /wp.example.com/wordpress/
+ /wp.example.com/wordpress/wp-includes/
+ /wp.example.com/wordpress/index.php
+ /wp-includes/
+ /index.php
+ ');
+
+ $path = $fs->abspath( '/var/www/example.com/wp.example.com/wordpress/' );
+ $this->assertEquals( '/wp.example.com/wordpress/', $path );
+
+ $path = $fs->abspath( '/var/www/example.com/' );
+ $this->assertEquals( '/', $path );
+
+ }
+
+ /**
+ * Test the WordPress ABSPATH containing TWO tokens (www) of which exists in the current FTP home.
+ *
+ * @ticket 20934
+ */
+ function test_multiple_tokens_in_path1() {
+ global $wp_filesystem;
+ $fs = $wp_filesystem;
+ $fs->init('
+ # www.example.com
+ /example.com/www/index.php
+ /example.com/www/wp-includes/
+ /example.com/www/wp-content/plugins/
+
+ # sub.example.com
+ /example.com/sub/index.php
+ /example.com/sub/wp-includes/
+ /example.com/sub/wp-content/plugins/
+ ');
+
+ // www.example.com
+ $path = $fs->abspath( '/var/www/example.com/www/' );
+ $this->assertEquals( '/example.com/www/', $path );
+
+ // sub.example.com
+ $path = $fs->abspath( '/var/www/example.com/sub/' );
+ $this->assertEquals( '/example.com/sub/', $path );
+
+ // sub.example.com - Plugins
+ $path = $fs->find_folder( '/var/www/example.com/sub/wp-content/plugins/' );
+ $this->assertEquals( '/example.com/sub/wp-content/plugins/', $path );
+ }
+
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunktestsphpunittestsfilesystemfind_folderphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/filesystem/find_folder.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/filesystem/find_folder.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/filesystem/find_folder.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,109 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-require_once dirname( __FILE__ ) . '/base.php';
-
-/**
- * @group filesystem
- * @group wp-filesystem
- */
-class WP_Filesystem_find_folder_UnitTestCases extends WP_Filesystem_UnitTestCase {
-
- function test_ftp_has_root_access() {
- global $wp_filesystem;
- $fs = $wp_filesystem;
- $fs->init('
- /var/www/wordpress/
- /var/www/wordpress/wp-includes/
- /var/www/wordpress/index.php
- ');
-
- $path = $fs->find_folder( '/var/www/wordpress/' );
- $this->assertEquals( '/var/www/wordpress/', $path );
-
- $path = $fs->find_folder( '/this/directory/doesnt/exist/' );
- $this->assertFalse( $path );
-
- }
-
- function test_sibling_wordpress_in_subdir() {
- global $wp_filesystem;
- $fs = $wp_filesystem;
- $fs->init('
- /www/example.com/wordpress/
- /www/example.com/wordpress/wp-includes/
- /www/example.com/wordpress/index.php
- /www/wp.example.com/wordpress/
- /www/wp.example.com/wordpress/wp-includes/
- /www/wp.example.com/wordpress/wp-content/
- /www/wp.example.com/wordpress/index.php
- /www/index.php
- ');
-
- $path = $fs->find_folder( '/var/www/example.com/wordpress/' );
- $this->assertEquals( '/www/example.com/wordpress/', $path );
-
- $path = $fs->find_folder( '/var/www/wp.example.com/wordpress/wp-content/' );
- $this->assertEquals( '/www/wp.example.com/wordpress/wp-content/', $path );
-
- }
-
- /**
- * Two WordPress installs, with one contained within the other
- * FTP / = /var/www/example.com/ on Disk
- * example.com at /
- * wp.example.com at /wp.example.com/wordpress/
- */
- function test_subdir_of_another() {
- global $wp_filesystem;
- $fs = $wp_filesystem;
- $fs->init('
- /wp.example.com/index.php
- /wp.example.com/wordpress/
- /wp.example.com/wordpress/wp-includes/
- /wp.example.com/wordpress/index.php
- /wp-includes/
- /index.php
- ');
-
- $path = $fs->abspath( '/var/www/example.com/wp.example.com/wordpress/' );
- $this->assertEquals( '/wp.example.com/wordpress/', $path );
-
- $path = $fs->abspath( '/var/www/example.com/' );
- $this->assertEquals( '/', $path );
-
- }
-
- /**
- * Test the WordPress ABSPATH containing TWO tokens (www) of which exists in the current FTP home.
- *
- * @ticket 20934
- */
- function test_multiple_tokens_in_path1() {
- global $wp_filesystem;
- $fs = $wp_filesystem;
- $fs->init('
- # www.example.com
- /example.com/www/index.php
- /example.com/www/wp-includes/
- /example.com/www/wp-content/plugins/
-
- # sub.example.com
- /example.com/sub/index.php
- /example.com/sub/wp-includes/
- /example.com/sub/wp-content/plugins/
- ');
-
- // www.example.com
- $path = $fs->abspath( '/var/www/example.com/www/' );
- $this->assertEquals( '/example.com/www/', $path );
-
- // sub.example.com
- $path = $fs->abspath( '/var/www/example.com/sub/' );
- $this->assertEquals( '/example.com/sub/', $path );
-
- // sub.example.com - Plugins
- $path = $fs->find_folder( '/var/www/example.com/sub/wp-content/plugins/' );
- $this->assertEquals( '/example.com/sub/wp-content/plugins/', $path );
- }
-
-}
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunktestsphpunittestshooksaddFilterphpfromrev41260trunktestsphpunittestshooksadd_filterphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/addFilter.php (from rev 41260, trunk/tests/phpunit/tests/hooks/add_filter.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/addFilter.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/addFilter.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,280 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+
+/**
+ * Test the add_filter method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
+
+ public $hook;
+
+ public function test_add_filter_with_function() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
+ $this->assertEquals( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
+ $this->assertEquals( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
+ }
+
+ public function test_add_filter_with_object() {
+ $a = new MockAction();
+ $callback = array( $a, 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
+ $this->assertEquals( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
+ $this->assertEquals( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
+ }
+
+ public function test_add_filter_with_static_method() {
+ $callback = array( 'MockAction', 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
+ $this->assertEquals( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
+ $this->assertEquals( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
+ }
+
+ public function test_add_two_filters_with_same_priority() {
+ $callback_one = '__return_null';
+ $callback_two = '__return_false';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+
+ $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
+ $this->assertCount( 2, $hook->callbacks[ $priority ] );
+ }
+
+ public function test_add_two_filters_with_different_priority() {
+ $callback_one = '__return_null';
+ $callback_two = '__return_false';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+
+ $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+ $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
+ }
+
+ public function test_readd_filter() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+ }
+
+ public function test_readd_filter_with_different_priority() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+
+ $hook->add_filter( $tag, $callback, $priority + 1, $accepted_args );
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+ $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
+ }
+
+ public function test_sort_after_add_filter() {
+ $a = new MockAction();
+ $b = new MockAction();
+ $c = new MockAction();
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+
+ $hook->add_filter( $tag, array( $a, 'action' ), 10, 1 );
+ $hook->add_filter( $tag, array( $b, 'action' ), 5, 1 );
+ $hook->add_filter( $tag, array( $c, 'action' ), 8, 1 );
+
+ $this->assertEquals( array( 5, 8, 10 ), array_keys( $hook->callbacks ) );
+ }
+
+ public function test_remove_and_add() {
+ $this->hook = new Wp_Hook();
+
+ $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11, 1 );
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add4' ), 12, 1 );
+
+ $value = $this->hook->apply_filters( '', array() );
+
+ $this->assertSame( '24', $value );
+ }
+
+ public function test_remove_and_add_last_filter() {
+ $this->hook = new Wp_Hook();
+
+ $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add1' ), 11, 1 );
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 12, 1 );
+
+ $value = $this->hook->apply_filters( '', array() );
+
+ $this->assertSame( '12', $value );
+ }
+
+ public function test_remove_and_recurse_and_add() {
+ $this->hook = new Wp_Hook();
+
+ $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add1' ), 11, 1 );
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11, 1 );
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add3' ), 11, 1 );
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add4' ), 12, 1 );
+
+ $value = $this->hook->apply_filters( '', array() );
+
+ $this->assertSame( '1-134-234', $value );
+ }
+
+ public function _filter_remove_and_add1( $string ) {
+ return $string . '1';
+ }
+
+ public function _filter_remove_and_add2( $string ) {
+ $this->hook->remove_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11 );
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11, 1 );
+
+ return $string . '2';
+ }
+
+ public function _filter_remove_and_recurse_and_add2( $string ) {
+ $this->hook->remove_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11 );
+
+ $string .= '-' . $this->hook->apply_filters( '', array() ) . '-';
+
+ $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11, 1 );
+
+ return $string . '2';
+ }
+
+ public function _filter_remove_and_add3( $string ) {
+ return $string . '3';
+ }
+
+ public function _filter_remove_and_add4( $string ) {
+ return $string . '4';
+ }
+
+ public function test_remove_and_add_action() {
+ $this->hook = new Wp_Hook();
+ $this->action_output = '';
+
+ $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 11, 0 );
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add4' ), 12, 0 );
+
+ $this->hook->do_action( array() );
+
+ $this->assertSame( '24', $this->action_output );
+ }
+
+ public function test_remove_and_add_last_action() {
+ $this->hook = new Wp_Hook();
+ $this->action_output = '';
+
+ $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add1' ), 11, 0 );
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 12, 0 );
+
+ $this->hook->do_action( array() );
+
+ $this->assertSame( '12', $this->action_output );
+ }
+
+ public function test_remove_and_recurse_and_add_action() {
+ $this->hook = new Wp_Hook();
+ $this->action_output = '';
+
+ $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add1' ), 11, 0 );
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_recurse_and_add2' ), 11, 0 );
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add3' ), 11, 0 );
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add4' ), 12, 0 );
+
+ $this->hook->do_action( array() );
+
+ $this->assertSame( '1-134-234', $this->action_output );
+ }
+
+ public function _action_remove_and_add1() {
+ $this->action_output .= 1;
+ }
+
+ public function _action_remove_and_add2() {
+ $this->hook->remove_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 11 );
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 11, 0 );
+
+ $this->action_output .= '2';
+ }
+
+ public function _action_remove_and_recurse_and_add2() {
+ $this->hook->remove_filter( 'remove_and_add_action', array( $this, '_action_remove_and_recurse_and_add2' ), 11 );
+
+ $this->action_output .= '-';
+ $this->hook->do_action( array() );
+ $this->action_output .= '-';
+
+ $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_recurse_and_add2' ), 11, 0 );
+
+ $this->action_output .= '2';
+ }
+
+ public function _action_remove_and_add3() {
+ $this->action_output .= '3';
+ }
+
+ public function _action_remove_and_add4() {
+ $this->action_output .= '4';
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshooksadd_filterphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/add_filter.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/add_filter.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/add_filter.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,280 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-
-/**
- * Test the add_filter method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
-
- public $hook;
-
- public function test_add_filter_with_function() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
- $this->assertEquals( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
- $this->assertEquals( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
- }
-
- public function test_add_filter_with_object() {
- $a = new MockAction();
- $callback = array( $a, 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
- $this->assertEquals( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
- $this->assertEquals( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
- }
-
- public function test_add_filter_with_static_method() {
- $callback = array( 'MockAction', 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
- $this->assertEquals( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
- $this->assertEquals( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
- }
-
- public function test_add_two_filters_with_same_priority() {
- $callback_one = '__return_null';
- $callback_two = '__return_false';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
-
- $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
- $this->assertCount( 2, $hook->callbacks[ $priority ] );
- }
-
- public function test_add_two_filters_with_different_priority() {
- $callback_one = '__return_null';
- $callback_two = '__return_false';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
-
- $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
- $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
- }
-
- public function test_readd_filter() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
- }
-
- public function test_readd_filter_with_different_priority() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
-
- $hook->add_filter( $tag, $callback, $priority + 1, $accepted_args );
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
- $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
- }
-
- public function test_sort_after_add_filter() {
- $a = new MockAction();
- $b = new MockAction();
- $c = new MockAction();
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
-
- $hook->add_filter( $tag, array( $a, 'action' ), 10, 1 );
- $hook->add_filter( $tag, array( $b, 'action' ), 5, 1 );
- $hook->add_filter( $tag, array( $c, 'action' ), 8, 1 );
-
- $this->assertEquals( array( 5, 8, 10 ), array_keys( $hook->callbacks ) );
- }
-
- public function test_remove_and_add() {
- $this->hook = new Wp_Hook();
-
- $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11, 1 );
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add4' ), 12, 1 );
-
- $value = $this->hook->apply_filters( '', array() );
-
- $this->assertSame( '24', $value );
- }
-
- public function test_remove_and_add_last_filter() {
- $this->hook = new Wp_Hook();
-
- $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add1' ), 11, 1 );
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 12, 1 );
-
- $value = $this->hook->apply_filters( '', array() );
-
- $this->assertSame( '12', $value );
- }
-
- public function test_remove_and_recurse_and_add() {
- $this->hook = new Wp_Hook();
-
- $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add1' ), 11, 1 );
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11, 1 );
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add3' ), 11, 1 );
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add4' ), 12, 1 );
-
- $value = $this->hook->apply_filters( '', array() );
-
- $this->assertSame( '1-134-234', $value );
- }
-
- public function _filter_remove_and_add1( $string ) {
- return $string . '1';
- }
-
- public function _filter_remove_and_add2( $string ) {
- $this->hook->remove_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11 );
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11, 1 );
-
- return $string . '2';
- }
-
- public function _filter_remove_and_recurse_and_add2( $string ) {
- $this->hook->remove_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11 );
-
- $string .= '-' . $this->hook->apply_filters( '', array() ) . '-';
-
- $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11, 1 );
-
- return $string . '2';
- }
-
- public function _filter_remove_and_add3( $string ) {
- return $string . '3';
- }
-
- public function _filter_remove_and_add4( $string ) {
- return $string . '4';
- }
-
- public function test_remove_and_add_action() {
- $this->hook = new Wp_Hook();
- $this->action_output = '';
-
- $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 11, 0 );
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add4' ), 12, 0 );
-
- $this->hook->do_action( array() );
-
- $this->assertSame( '24', $this->action_output );
- }
-
- public function test_remove_and_add_last_action() {
- $this->hook = new Wp_Hook();
- $this->action_output = '';
-
- $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add1' ), 11, 0 );
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 12, 0 );
-
- $this->hook->do_action( array() );
-
- $this->assertSame( '12', $this->action_output );
- }
-
- public function test_remove_and_recurse_and_add_action() {
- $this->hook = new Wp_Hook();
- $this->action_output = '';
-
- $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add1' ), 11, 0 );
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_recurse_and_add2' ), 11, 0 );
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add3' ), 11, 0 );
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add4' ), 12, 0 );
-
- $this->hook->do_action( array() );
-
- $this->assertSame( '1-134-234', $this->action_output );
- }
-
- public function _action_remove_and_add1() {
- $this->action_output .= 1;
- }
-
- public function _action_remove_and_add2() {
- $this->hook->remove_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 11 );
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_add2' ), 11, 0 );
-
- $this->action_output .= '2';
- }
-
- public function _action_remove_and_recurse_and_add2() {
- $this->hook->remove_filter( 'remove_and_add_action', array( $this, '_action_remove_and_recurse_and_add2' ), 11 );
-
- $this->action_output .= '-';
- $this->hook->do_action( array() );
- $this->action_output .= '-';
-
- $this->hook->add_filter( 'remove_and_add_action', array( $this, '_action_remove_and_recurse_and_add2' ), 11, 0 );
-
- $this->action_output .= '2';
- }
-
- public function _action_remove_and_add3() {
- $this->action_output .= '3';
- }
-
- public function _action_remove_and_add4() {
- $this->action_output .= '4';
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshooksapplyFiltersphpfromrev41260trunktestsphpunittestshooksapply_filtersphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/applyFilters.php (from rev 41260, trunk/tests/phpunit/tests/hooks/apply_filters.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/applyFilters.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/applyFilters.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,45 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the apply_filters method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Apply_Filters extends WP_UnitTestCase {
+
+ public function test_apply_filters_with_callback() {
+ $a = new MockAction();
+ $callback = array( $a, 'filter' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $returned = $hook->apply_filters( $arg, array( $arg ) );
+
+ $this->assertEquals( $returned, $arg );
+ $this->assertEquals( 1, $a->get_call_count() );
+ }
+
+ public function test_apply_filters_with_multiple_calls() {
+ $a = new MockAction();
+ $callback = array( $a, 'filter' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $returned_one = $hook->apply_filters( $arg, array( $arg ) );
+ $returned_two = $hook->apply_filters( $returned_one, array( $returned_one ) );
+
+ $this->assertEquals( $returned_two, $arg );
+ $this->assertEquals( 2, $a->get_call_count() );
+ }
+
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshooksapply_filtersphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/apply_filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/apply_filters.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/apply_filters.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,45 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the apply_filters method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Apply_Filters extends WP_UnitTestCase {
-
- public function test_apply_filters_with_callback() {
- $a = new MockAction();
- $callback = array( $a, 'filter' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $returned = $hook->apply_filters( $arg, array( $arg ) );
-
- $this->assertEquals( $returned, $arg );
- $this->assertEquals( 1, $a->get_call_count() );
- }
-
- public function test_apply_filters_with_multiple_calls() {
- $a = new MockAction();
- $callback = array( $a, 'filter' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $returned_one = $hook->apply_filters( $arg, array( $arg ) );
- $returned_two = $hook->apply_filters( $returned_one, array( $returned_one ) );
-
- $this->assertEquals( $returned_two, $arg );
- $this->assertEquals( 2, $a->get_call_count() );
- }
-
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshooksdoActionphpfromrev41260trunktestsphpunittestshooksdo_actionphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/doAction.php (from rev 41260, trunk/tests/phpunit/tests/hooks/do_action.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/doAction.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/doAction.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,172 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the do_action method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
+ private $events = array();
+ private $action_output = '';
+ private $hook;
+
+ public function setUp() {
+ parent::setUp();
+ $this->events = array();
+ }
+
+ public function test_do_action_with_callback() {
+ $a = new MockAction();
+ $callback = array( $a, 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertEquals( 1, $a->get_call_count() );
+ }
+
+ public function test_do_action_with_multiple_calls() {
+ $a = new MockAction();
+ $callback = array( $a, 'filter' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertEquals( 2, $a->get_call_count() );
+ }
+
+ public function test_do_action_with_multiple_callbacks_on_same_priority() {
+ $a = new MockAction();
+ $b = new MockAction();
+ $callback_one = array( $a, 'filter' );
+ $callback_two = array( $b, 'filter' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertEquals( 1, $a->get_call_count() );
+ $this->assertEquals( 1, $a->get_call_count() );
+ }
+
+ public function test_do_action_with_multiple_callbacks_on_different_priorities() {
+ $a = new MockAction();
+ $b = new MockAction();
+ $callback_one = array( $a, 'filter' );
+ $callback_two = array( $b, 'filter' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertEquals( 1, $a->get_call_count() );
+ $this->assertEquals( 1, $a->get_call_count() );
+ }
+
+ public function test_do_action_with_no_accepted_args() {
+ $callback = array( $this, '_action_callback' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = 0;
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertEmpty( $this->events[0]['args'] );
+ }
+
+ public function test_do_action_with_one_accepted_arg() {
+ $callback = array( $this, '_action_callback' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = 1;
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertCount( 1, $this->events[0]['args'] );
+ }
+
+ public function test_do_action_with_more_accepted_args() {
+ $callback = array( $this, '_action_callback' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = 1000;
+ $arg = __FUNCTION__ . '_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->do_action( array( $arg ) );
+
+ $this->assertCount( 1, $this->events[0]['args'] );
+ }
+
+ public function test_do_action_doesnt_change_value() {
+ $this->hook = new WP_Hook();
+ $this->action_output = '';
+
+ $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value1' ), 10, 1 );
+ $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value2' ), 10, 1 );
+ $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value3' ), 11, 1 );
+
+ $this->hook->do_action( array( 'a' ) );
+
+ $this->assertSame( 'a1-b1b3-a2a3', $this->action_output );
+ }
+
+ public function _filter_do_action_doesnt_change_value1( $value ) {
+ $this->action_output .= $value . 1;
+ return 'x1';
+ }
+ public function _filter_do_action_doesnt_change_value2( $value ) {
+ $this->hook->remove_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value2' ), 10 );
+
+ $this->action_output .= '-';
+ $this->hook->do_action( array( 'b' ) );
+ $this->action_output .= '-';
+
+ $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value2' ), 10, 1 );
+
+ $this->action_output .= $value . 2;
+
+ return 'x2';
+ }
+
+ public function _filter_do_action_doesnt_change_value3( $value ) {
+ $this->action_output .= $value . 3;
+ return 'x3';
+ }
+
+ /**
+ * Use this rather than MockAction so we can test callbacks with no args
+ */
+ public function _action_callback() {
+ $args = func_get_args();
+ $this->events[] = array('action' => __FUNCTION__, 'args'=>$args);
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshooksdoAllHookphpfromrev41260trunktestsphpunittestshooksdo_all_hookphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/doAllHook.php (from rev 41260, trunk/tests/phpunit/tests/hooks/do_all_hook.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/doAllHook.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/doAllHook.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,26 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the do_all_hook method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Do_All_Hook extends WP_UnitTestCase {
+
+ public function test_do_all_hook_with_multiple_calls() {
+ $a = new MockAction();
+ $callback = array( $a, 'action' );
+ $hook = new WP_Hook();
+ $tag = 'all';
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+ $arg = 'all_arg';
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $args = array( $arg );
+ $hook->do_all_hook( $args );
+ $hook->do_all_hook( $args );
+
+ $this->assertEquals( 2, $a->get_call_count() );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshooksdo_actionphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/do_action.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/do_action.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/do_action.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,172 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the do_action method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
- private $events = array();
- private $action_output = '';
- private $hook;
-
- public function setUp() {
- parent::setUp();
- $this->events = array();
- }
-
- public function test_do_action_with_callback() {
- $a = new MockAction();
- $callback = array( $a, 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
-
- $this->assertEquals( 1, $a->get_call_count() );
- }
-
- public function test_do_action_with_multiple_calls() {
- $a = new MockAction();
- $callback = array( $a, 'filter' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
- $hook->do_action( array( $arg ) );
-
- $this->assertEquals( 2, $a->get_call_count() );
- }
-
- public function test_do_action_with_multiple_callbacks_on_same_priority() {
- $a = new MockAction();
- $b = new MockAction();
- $callback_one = array( $a, 'filter' );
- $callback_two = array( $b, 'filter' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
-
- $this->assertEquals( 1, $a->get_call_count() );
- $this->assertEquals( 1, $a->get_call_count() );
- }
-
- public function test_do_action_with_multiple_callbacks_on_different_priorities() {
- $a = new MockAction();
- $b = new MockAction();
- $callback_one = array( $a, 'filter' );
- $callback_two = array( $b, 'filter' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
-
- $this->assertEquals( 1, $a->get_call_count() );
- $this->assertEquals( 1, $a->get_call_count() );
- }
-
- public function test_do_action_with_no_accepted_args() {
- $callback = array( $this, '_action_callback' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = 0;
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
-
- $this->assertEmpty( $this->events[0]['args'] );
- }
-
- public function test_do_action_with_one_accepted_arg() {
- $callback = array( $this, '_action_callback' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = 1;
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
-
- $this->assertCount( 1, $this->events[0]['args'] );
- }
-
- public function test_do_action_with_more_accepted_args() {
- $callback = array( $this, '_action_callback' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = 1000;
- $arg = __FUNCTION__ . '_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->do_action( array( $arg ) );
-
- $this->assertCount( 1, $this->events[0]['args'] );
- }
-
- public function test_do_action_doesnt_change_value() {
- $this->hook = new WP_Hook();
- $this->action_output = '';
-
- $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value1' ), 10, 1 );
- $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value2' ), 10, 1 );
- $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value3' ), 11, 1 );
-
- $this->hook->do_action( array( 'a' ) );
-
- $this->assertSame( 'a1-b1b3-a2a3', $this->action_output );
- }
-
- public function _filter_do_action_doesnt_change_value1( $value ) {
- $this->action_output .= $value . 1;
- return 'x1';
- }
- public function _filter_do_action_doesnt_change_value2( $value ) {
- $this->hook->remove_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value2' ), 10 );
-
- $this->action_output .= '-';
- $this->hook->do_action( array( 'b' ) );
- $this->action_output .= '-';
-
- $this->hook->add_filter( 'do_action_doesnt_change_value', array( $this, '_filter_do_action_doesnt_change_value2' ), 10, 1 );
-
- $this->action_output .= $value . 2;
-
- return 'x2';
- }
-
- public function _filter_do_action_doesnt_change_value3( $value ) {
- $this->action_output .= $value . 3;
- return 'x3';
- }
-
- /**
- * Use this rather than MockAction so we can test callbacks with no args
- */
- public function _action_callback() {
- $args = func_get_args();
- $this->events[] = array('action' => __FUNCTION__, 'args'=>$args);
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshooksdo_all_hookphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/do_all_hook.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/do_all_hook.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/do_all_hook.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,26 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the do_all_hook method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Do_All_Hook extends WP_UnitTestCase {
-
- public function test_do_all_hook_with_multiple_calls() {
- $a = new MockAction();
- $callback = array( $a, 'action' );
- $hook = new WP_Hook();
- $tag = 'all';
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $arg = 'all_arg';
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $args = array( $arg );
- $hook->do_all_hook( $args );
- $hook->do_all_hook( $args );
-
- $this->assertEquals( 2, $a->get_call_count() );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshookshasFilterphpfromrev41260trunktestsphpunittestshookshas_filterphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/hasFilter.php (from rev 41260, trunk/tests/phpunit/tests/hooks/has_filter.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/hasFilter.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/hasFilter.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,83 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the has_filter method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
+
+ public function test_has_filter_with_function() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
+ }
+
+ public function test_has_filter_with_object() {
+ $a = new MockAction();
+ $callback = array( $a, 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
+ }
+
+ public function test_has_filter_with_static_method() {
+ $callback = array( 'MockAction', 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
+ }
+
+ public function test_has_filter_without_callback() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $this->assertTrue( $hook->has_filter() );
+ }
+
+ public function test_not_has_filter_without_callback() {
+ $hook = new WP_Hook();
+ $this->assertFalse( $hook->has_filter() );
+ }
+
+ public function test_not_has_filter_with_callback() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+
+ $this->assertFalse( $hook->has_filter( $tag, $callback ) );
+ }
+
+ public function test_has_filter_with_wrong_callback() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $this->assertFalse( $hook->has_filter( $tag, '__return_false' ) );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshookshasFiltersphpfromrev41260trunktestsphpunittestshookshas_filtersphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/hasFilters.php (from rev 41260, trunk/tests/phpunit/tests/hooks/has_filters.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/hasFilters.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/hasFilters.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,52 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the has_filters method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Has_Filters extends WP_UnitTestCase {
+
+ public function test_has_filters_with_callback() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $this->assertTrue( $hook->has_filters() );
+ }
+
+ public function test_has_filters_without_callback() {
+ $hook = new WP_Hook();
+ $this->assertFalse( $hook->has_filters() );
+ }
+
+ public function test_not_has_filters_with_removed_callback() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->remove_filter( $tag, $callback, $priority );
+ $this->assertFalse( $hook->has_filters() );
+ }
+
+ public function test_not_has_filter_with_directly_removed_callback() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $function_key = _wp_filter_build_unique_id( $tag, $callback, $priority );
+ unset( $hook->callbacks[ $priority ][ $function_key ] );
+
+ $this->assertFalse( $hook->has_filters() );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshookshas_filterphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/has_filter.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/has_filter.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/has_filter.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,83 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the has_filter method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
-
- public function test_has_filter_with_function() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
- }
-
- public function test_has_filter_with_object() {
- $a = new MockAction();
- $callback = array( $a, 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
- }
-
- public function test_has_filter_with_static_method() {
- $callback = array( 'MockAction', 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
- }
-
- public function test_has_filter_without_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $this->assertTrue( $hook->has_filter() );
- }
-
- public function test_not_has_filter_without_callback() {
- $hook = new WP_Hook();
- $this->assertFalse( $hook->has_filter() );
- }
-
- public function test_not_has_filter_with_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
-
- $this->assertFalse( $hook->has_filter( $tag, $callback ) );
- }
-
- public function test_has_filter_with_wrong_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $this->assertFalse( $hook->has_filter( $tag, '__return_false' ) );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshookshas_filtersphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/has_filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/has_filters.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/has_filters.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,52 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the has_filters method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Has_Filters extends WP_UnitTestCase {
-
- public function test_has_filters_with_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $this->assertTrue( $hook->has_filters() );
- }
-
- public function test_has_filters_without_callback() {
- $hook = new WP_Hook();
- $this->assertFalse( $hook->has_filters() );
- }
-
- public function test_not_has_filters_with_removed_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->remove_filter( $tag, $callback, $priority );
- $this->assertFalse( $hook->has_filters() );
- }
-
- public function test_not_has_filter_with_directly_removed_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $function_key = _wp_filter_build_unique_id( $tag, $callback, $priority );
- unset( $hook->callbacks[ $priority ][ $function_key ] );
-
- $this->assertFalse( $hook->has_filters() );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshookspreinitHooksphpfromrev41260trunktestsphpunittestshookspreinit_hooksphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/preinitHooks.php (from rev 41260, trunk/tests/phpunit/tests/hooks/preinit_hooks.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/preinitHooks.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/preinitHooks.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,39 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the IteratorAggregate implementation of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Preinit_Hooks extends WP_UnitTestCase {
+
+ public function test_array_to_hooks() {
+ $tag1 = __FUNCTION__ . '_1';
+ $priority1 = rand( 1, 100 );
+ $tag2 = __FUNCTION__ . '_2';
+ $priority2 = rand( 1, 100 );
+ $filters = array(
+ $tag1 => array(
+ $priority1 => array(
+ 'test1' => array(
+ 'function' => '__return_false',
+ 'accepted_args' => 2,
+ ),
+ ),
+ ),
+ $tag2 => array(
+ $priority2 => array(
+ 'test1' => array(
+ 'function' => '__return_null',
+ 'accepted_args' => 1,
+ ),
+ ),
+ ),
+ );
+
+ $hooks = WP_Hook::build_preinitialized_hooks( $filters );
+
+ $this->assertEquals( $priority1, $hooks[ $tag1 ]->has_filter( $tag1, '__return_false' ) );
+ $this->assertEquals( $priority2, $hooks[ $tag2 ]->has_filter( $tag2, '__return_null' ) );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshookspreinit_hooksphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/preinit_hooks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/preinit_hooks.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/preinit_hooks.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,39 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the IteratorAggregate implementation of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Preinit_Hooks extends WP_UnitTestCase {
-
- public function test_array_to_hooks() {
- $tag1 = __FUNCTION__ . '_1';
- $priority1 = rand( 1, 100 );
- $tag2 = __FUNCTION__ . '_2';
- $priority2 = rand( 1, 100 );
- $filters = array(
- $tag1 => array(
- $priority1 => array(
- 'test1' => array(
- 'function' => '__return_false',
- 'accepted_args' => 2,
- ),
- ),
- ),
- $tag2 => array(
- $priority2 => array(
- 'test1' => array(
- 'function' => '__return_null',
- 'accepted_args' => 1,
- ),
- ),
- ),
- );
-
- $hooks = WP_Hook::build_preinitialized_hooks( $filters );
-
- $this->assertEquals( $priority1, $hooks[ $tag1 ]->has_filter( $tag1, '__return_false' ) );
- $this->assertEquals( $priority2, $hooks[ $tag2 ]->has_filter( $tag2, '__return_null' ) );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshooksremoveAllFiltersphpfromrev41260trunktestsphpunittestshooksremove_all_filtersphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/removeAllFilters.php (from rev 41260, trunk/tests/phpunit/tests/hooks/remove_all_filters.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/removeAllFilters.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/removeAllFilters.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,41 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the remove_all_filters method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Remove_All_Filters extends WP_UnitTestCase {
+
+ public function test_remove_all_filters() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+
+ $hook->remove_all_filters();
+
+ $this->assertFalse( $hook->has_filters() );
+ }
+
+ public function test_remove_all_filters_with_priority() {
+ $callback_one = '__return_null';
+ $callback_two = '__return_false';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
+
+ $hook->remove_all_filters( $priority );
+
+ $this->assertFalse( $hook->has_filter( $tag, $callback_one ) );
+ $this->assertTrue( $hook->has_filters() );
+ $this->assertEquals( $priority + 1, $hook->has_filter( $tag, $callback_two ) );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshooksremoveFilterphpfromrev41260trunktestsphpunittestshooksremove_filterphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/hooks/removeFilter.php (from rev 41260, trunk/tests/phpunit/tests/hooks/remove_filter.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/removeFilter.php (rev 0)
+++ trunk/tests/phpunit/tests/hooks/removeFilter.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,81 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the remove_filter method of WP_Hook
+ *
+ * @group hooks
+ */
+class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
+
+ public function test_remove_filter_with_function() {
+ $callback = '__return_null';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->remove_filter( $tag, $callback, $priority );
+
+ $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
+ }
+
+ public function test_remove_filter_with_object() {
+ $a = new MockAction();
+ $callback = array( $a, 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->remove_filter( $tag, $callback, $priority );
+
+ $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
+ }
+
+ public function test_remove_filter_with_static_method() {
+ $callback = array( 'MockAction', 'action' );
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback, $priority, $accepted_args );
+ $hook->remove_filter( $tag, $callback, $priority );
+
+ $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
+ }
+
+ public function test_remove_filters_with_another_at_same_priority() {
+ $callback_one = '__return_null';
+ $callback_two = '__return_false';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
+
+ $hook->remove_filter( $tag, $callback_one, $priority );
+
+ $this->assertCount( 1, $hook->callbacks[ $priority ] );
+ }
+
+ public function test_remove_filter_with_another_at_different_priority() {
+ $callback_one = '__return_null';
+ $callback_two = '__return_false';
+ $hook = new WP_Hook();
+ $tag = __FUNCTION__;
+ $priority = rand( 1, 100 );
+ $accepted_args = rand( 1, 100 );
+
+ $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
+ $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
+
+ $hook->remove_filter( $tag, $callback_one, $priority );
+ $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
+ $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestshooksremove_all_filtersphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/remove_all_filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/remove_all_filters.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/remove_all_filters.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,41 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the remove_all_filters method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Remove_All_Filters extends WP_UnitTestCase {
-
- public function test_remove_all_filters() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
-
- $hook->remove_all_filters();
-
- $this->assertFalse( $hook->has_filters() );
- }
-
- public function test_remove_all_filters_with_priority() {
- $callback_one = '__return_null';
- $callback_two = '__return_false';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
-
- $hook->remove_all_filters( $priority );
-
- $this->assertFalse( $hook->has_filter( $tag, $callback_one ) );
- $this->assertTrue( $hook->has_filters() );
- $this->assertEquals( $priority + 1, $hook->has_filter( $tag, $callback_two ) );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestshooksremove_filterphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/hooks/remove_filter.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/hooks/remove_filter.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/hooks/remove_filter.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,81 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the remove_filter method of WP_Hook
- *
- * @group hooks
- */
-class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
-
- public function test_remove_filter_with_function() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->remove_filter( $tag, $callback, $priority );
-
- $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
- }
-
- public function test_remove_filter_with_object() {
- $a = new MockAction();
- $callback = array( $a, 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->remove_filter( $tag, $callback, $priority );
-
- $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
- }
-
- public function test_remove_filter_with_static_method() {
- $callback = array( 'MockAction', 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $hook->remove_filter( $tag, $callback, $priority );
-
- $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
- }
-
- public function test_remove_filters_with_another_at_same_priority() {
- $callback_one = '__return_null';
- $callback_two = '__return_false';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
-
- $hook->remove_filter( $tag, $callback_one, $priority );
-
- $this->assertCount( 1, $hook->callbacks[ $priority ] );
- }
-
- public function test_remove_filter_with_another_at_different_priority() {
- $callback_one = '__return_null';
- $callback_two = '__return_false';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
-
- $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
- $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
-
- $hook->remove_filter( $tag, $callback_one, $priority );
- $this->assertFalse( isset( $hook->callbacks[ $priority ] ) );
- $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsimageeditorGdphpfromrev41260trunktestsphpunittestsimageeditor_gdphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/image/editorGd.php (from rev 41260, trunk/tests/phpunit/tests/image/editor_gd.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editorGd.php (rev 0)
+++ trunk/tests/phpunit/tests/image/editorGd.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,556 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the WP_Image_Editor_GD class
+ * @group image
+ * @group media
+ * @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();
+ }
+
+ public function test_supports_mime_type_jpeg() {
+ $gd_image_editor = new WP_Image_Editor_GD( null );
+ $expected = imagetypes() & IMG_JPG;
+ $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) );
+ }
+
+ public function test_supports_mime_type_png() {
+ $gd_image_editor = new WP_Image_Editor_GD( null );
+ $expected = imagetypes() & IMG_PNG;
+ $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) );
+ }
+
+ public function test_supports_mime_type_gif() {
+ $gd_image_editor = new WP_Image_Editor_GD( null );
+ $expected = imagetypes() & IMG_GIF;
+ $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
+ }
+
+ /**
+ * Test resizing an image, not using crop
+ */
+ public function test_resize() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $gd_image_editor->resize( 100, 50 );
+
+ $this->assertEquals(
+ array(
+ 'width' => 75,
+ 'height' => 50,
+ ),
+ $gd_image_editor->get_size()
+ );
+ }
+
+ /**
+ * Test multi_resize with single image resize and no crop
+ */
+ public function test_single_multi_resize() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $sizes_array = array(
+ array(
+ 'width' => 50,
+ 'height' => 50,
+ ),
+ );
+
+ $resized = $gd_image_editor->multi_resize( $sizes_array );
+
+ # First, check to see if returned array is as expected
+ $expected_array = array(
+ array(
+ 'file' => 'waffles-50x33.jpg',
+ 'width' => 50,
+ 'height' => 33,
+ 'mime-type' => 'image/jpeg',
+ ),
+ );
+
+ $this->assertEquals( $expected_array, $resized );
+
+ // Now, verify real dimensions are as expected
+ $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file'];
+ $this->assertImageDimensions(
+ $image_path,
+ $expected_array[0]['width'],
+ $expected_array[0]['height']
+ );
+ }
+
+ /**
+ * Ensure multi_resize doesn't create an image when
+ * both height and weight are missing, null, or 0.
+ *
+ * ticket 26823
+ */
+ public function test_multi_resize_does_not_create() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $sizes_array = array(
+ array(
+ 'width' => 0,
+ 'height' => 0,
+ ),
+ array(
+ 'width' => 0,
+ 'height' => 0,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => null,
+ 'height' => null,
+ ),
+ array(
+ 'width' => null,
+ 'height' => null,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => '',
+ 'height' => '',
+ ),
+ array(
+ 'width' => '',
+ 'height' => '',
+ 'crop' => true,
+ ),
+ array(
+ 'width' => 0,
+ ),
+ array(
+ 'width' => 0,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => null,
+ ),
+ array(
+ 'width' => null,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => '',
+ ),
+ array(
+ 'width' => '',
+ 'crop' => true,
+ ),
+ );
+
+ $resized = $gd_image_editor->multi_resize( $sizes_array );
+
+ // If no images are generated, the returned array is empty.
+ $this->assertEmpty( $resized );
+ }
+
+ /**
+ * Test multi_resize with multiple sizes
+ *
+ * ticket 26823
+ */
+ public function test_multi_resize() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $sizes_array = array(
+
+ /**
+ * #0 - 10x10 resize, no cropping.
+ * By aspect, should be 10x6 output.
+ */
+ array(
+ 'width' => 10,
+ 'height' => 10,
+ 'crop' => false,
+ ),
+
+ /**
+ * #1 - 75x50 resize, with cropping.
+ * Output dimensions should be 75x50
+ */
+ array(
+ 'width' => 75,
+ 'height' => 50,
+ 'crop' => true,
+ ),
+
+ /**
+ * #2 - 20 pixel max height, no cropping.
+ * By aspect, should be 30x20 output.
+ */
+ array(
+ 'width' => 9999, # Arbitrary High Value
+ 'height' => 20,
+ 'crop' => false,
+ ),
+
+ /**
+ * #3 - 45 pixel max height, with cropping.
+ * By aspect, should be 45x400 output.
+ */
+ array(
+ 'width' => 45,
+ 'height' => 9999, # Arbitrary High Value
+ 'crop' => true,
+ ),
+
+ /**
+ * #4 - 50 pixel max width, no cropping.
+ * By aspect, should be 50x33 output.
+ */
+ array(
+ 'width' => 50,
+ ),
+
+ /**
+ * #5 - 55 pixel max width, no cropping, null height
+ * By aspect, should be 55x36 output.
+ */
+ array(
+ 'width' => 55,
+ 'height' => null,
+ ),
+
+ /**
+ * #6 - 55 pixel max height, no cropping, no width specified.
+ * By aspect, should be 82x55 output.
+ */
+ array(
+ 'height' => 55,
+ ),
+
+ /**
+ * #7 - 60 pixel max height, no cropping, null width.
+ * By aspect, should be 90x60 output.
+ */
+ array(
+ 'width' => null,
+ 'height' => 60,
+ ),
+
+ /**
+ * #8 - 70 pixel max height, no cropping, negative width.
+ * By aspect, should be 105x70 output.
+ */
+ array(
+ 'width' => -9999, # Arbitrary Negative Value
+ 'height' => 70,
+ ),
+
+ /**
+ * #9 - 200 pixel max width, no cropping, negative height.
+ * By aspect, should be 200x133 output.
+ */
+ array(
+ 'width' => 200,
+ 'height' => -9999, # Arbitrary Negative Value
+ ),
+ );
+
+ $resized = $gd_image_editor->multi_resize( $sizes_array );
+
+ $expected_array = array(
+
+ // #0
+ array(
+ 'file' => 'waffles-10x7.jpg',
+ 'width' => 10,
+ 'height' => 7,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #1
+ array(
+ 'file' => 'waffles-75x50.jpg',
+ 'width' => 75,
+ 'height' => 50,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #2
+ array(
+ 'file' => 'waffles-30x20.jpg',
+ 'width' => 30,
+ 'height' => 20,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #3
+ array(
+ 'file' => 'waffles-45x400.jpg',
+ 'width' => 45,
+ 'height' => 400,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #4
+ array(
+ 'file' => 'waffles-50x33.jpg',
+ 'width' => 50,
+ 'height' => 33,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #5
+ array(
+ 'file' => 'waffles-55x37.jpg',
+ 'width' => 55,
+ 'height' => 37,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #6
+ array(
+ 'file' => 'waffles-83x55.jpg',
+ 'width' => 83,
+ 'height' => 55,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #7
+ array(
+ 'file' => 'waffles-90x60.jpg',
+ 'width' => 90,
+ 'height' => 60,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #8
+ array(
+ 'file' => 'waffles-105x70.jpg',
+ 'width' => 105,
+ 'height' => 70,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #9
+ array(
+ 'file' => 'waffles-200x133.jpg',
+ 'width' => 200,
+ 'height' => 133,
+ 'mime-type' => 'image/jpeg',
+ ),
+ );
+
+ $this->assertNotNull( $resized );
+ $this->assertEquals( $expected_array, $resized );
+
+ foreach( $resized as $key => $image_data ){
+ $image_path = DIR_TESTDATA . '/images/' . $image_data['file'];
+
+ // Now, verify real dimensions are as expected
+ $this->assertImageDimensions(
+ $image_path,
+ $expected_array[$key]['width'],
+ $expected_array[$key]['height']
+ );
+ }
+ }
+
+ /**
+ * Test resizing an image with cropping
+ */
+ public function test_resize_and_crop() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $gd_image_editor->resize( 100, 50, true );
+
+ $this->assertEquals(
+ array(
+ 'width' => 100,
+ 'height' => 50,
+ ),
+ $gd_image_editor->get_size()
+ );
+ }
+
+ /**
+ * Test cropping an image
+ */
+ public function test_crop() {
+ $file = DIR_TESTDATA . '/images/gradient-square.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $gd_image_editor->crop( 0, 0, 50, 50 );
+
+ $this->assertEquals(
+ array(
+ 'width' => 50,
+ 'height' => 50,
+ ),
+ $gd_image_editor->get_size()
+ );
+ }
+
+ /**
+ * Test rotating an image 180 deg
+ */
+ public function test_rotate() {
+ $file = DIR_TESTDATA . '/images/gradient-square.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $property = new ReflectionProperty( $gd_image_editor, 'image' );
+ $property->setAccessible( true );
+
+ $color_top_left = imagecolorat( $property->getValue( $gd_image_editor ), 0, 0 );
+
+ $gd_image_editor->rotate( 180 );
+
+ $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 99, 99 ) );
+ }
+
+ /**
+ * Test flipping an image
+ */
+ public function test_flip() {
+ $file = DIR_TESTDATA . '/images/gradient-square.jpg';
+
+ $gd_image_editor = new WP_Image_Editor_GD( $file );
+ $gd_image_editor->load();
+
+ $property = new ReflectionProperty( $gd_image_editor, 'image' );
+ $property->setAccessible( true );
+
+ $color_top_left = imagecolorat( $property->getValue( $gd_image_editor ), 0, 0 );
+
+ $gd_image_editor->flip( true, false );
+
+ $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 0, 99 ) );
+ }
+
+ /**
+ * Test the image created with WP_Image_Editor_GD preserves alpha when resizing
+ *
+ * @ticket 23039
+ */
+ public function test_image_preserves_alpha_on_resize() {
+ if ( ! ( imagetypes() & IMG_PNG ) ) {
+ $this->fail( 'This test requires PHP to be compiled with PNG support.' );
+ }
+
+ $file = DIR_TESTDATA . '/images/transparent.png';
+
+ $editor = wp_get_image_editor( $file );
+
+ $this->assertNotInstanceOf( 'WP_Error', $editor );
+
+ $editor->load();
+ $editor->resize( 5, 5 );
+ $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
+
+ $editor->save( $save_to_file );
+
+ $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
+
+ unlink( $save_to_file );
+ }
+
+ /**
+ * Test the image created with WP_Image_Editor_GD preserves alpha with no resizing etc
+ *
+ * @ticket 23039
+ */
+ public function test_image_preserves_alpha() {
+ if ( ! ( imagetypes() & IMG_PNG ) ) {
+ $this->fail( 'This test requires PHP to be compiled with PNG support.' );
+ }
+
+ $file = DIR_TESTDATA . '/images/transparent.png';
+
+ $editor = wp_get_image_editor( $file );
+
+ $this->assertNotInstanceOf( 'WP_Error', $editor );
+
+ $editor->load();
+
+ $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
+
+ $editor->save( $save_to_file );
+
+ $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
+
+ unlink( $save_to_file );
+ }
+
+ /**
+ *
+ * @ticket 30596
+ */
+ public function test_image_preserves_alpha_on_rotate() {
+ if ( ! ( imagetypes() & IMG_PNG ) ) {
+ $this->fail( 'This test requires PHP to be compiled with PNG support.' );
+ }
+
+ $file = DIR_TESTDATA . '/images/transparent.png';
+
+ $image = imagecreatefrompng( $file );
+ $rgb = imagecolorat( $image, 0, 0 );
+ $expected = imagecolorsforindex( $image, $rgb );
+
+ $editor = new WP_Image_Editor_GD( $file );
+ $this->assertNotInstanceOf( 'WP_Error', $editor );
+ $editor->load();
+ $editor->rotate( 180 );
+ $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
+
+ $editor->save( $save_to_file );
+
+ $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), $expected['alpha'] );
+ unlink( $save_to_file );
+
+ }
+
+ /**
+ * Test WP_Image_Editor_GD handles extension-less images
+ * @ticket 39195
+ */
+ public function test_image_non_existent_extension() {
+ $image_editor = new WP_Image_Editor_GD( DIR_TESTDATA.'/images/test-image-no-extension' );
+ $result = $image_editor->load();
+
+ $this->assertTrue( $result );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsimageeditorImagickphpfromrev41260trunktestsphpunittestsimageeditor_imagickphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/image/editorImagick.php (from rev 41260, trunk/tests/phpunit/tests/image/editor_imagick.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editorImagick.php (rev 0)
+++ trunk/tests/phpunit/tests/image/editorImagick.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,575 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the WP_Image_Editor_Imagick class
+ * @group image
+ * @group media
+ * @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';
+
+ public function setUp() {
+ require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
+ require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.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 ImageMagick compatible mime types.
+ */
+ public function test_supports_mime_type() {
+ $imagick_image_editor = new WP_Image_Editor_Imagick( null );
+
+ $this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/jpeg' ), 'Does not support image/jpeg' );
+ $this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/png' ), 'Does not support image/png' );
+ $this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/gif' ), 'Does not support image/gif' );
+ }
+
+ /**
+ * Test resizing an image, not using crop
+ */
+ public function test_resize() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $imagick_image_editor->resize( 100, 50 );
+
+ $this->assertEquals(
+ array(
+ 'width' => 75,
+ 'height' => 50,
+ ),
+ $imagick_image_editor->get_size()
+ );
+ }
+
+ /**
+ * Test multi_resize with single image resize and no crop
+ */
+ public function test_single_multi_resize() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $sizes_array = array(
+ array(
+ 'width' => 50,
+ 'height' => 50,
+ ),
+ );
+
+ $resized = $imagick_image_editor->multi_resize( $sizes_array );
+
+ # First, check to see if returned array is as expected
+ $expected_array = array(
+ array(
+ 'file' => 'waffles-50x33.jpg',
+ 'width' => 50,
+ 'height' => 33,
+ 'mime-type' => 'image/jpeg',
+ ),
+ );
+
+ $this->assertEquals( $expected_array, $resized );
+
+ // Now, verify real dimensions are as expected
+ $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file'];
+ $this->assertImageDimensions(
+ $image_path,
+ $expected_array[0]['width'],
+ $expected_array[0]['height']
+ );
+ }
+
+ /**
+ * Ensure multi_resize doesn't create an image when
+ * both height and weight are missing, null, or 0.
+ *
+ * ticket 26823
+ */
+ public function test_multi_resize_does_not_create() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $sizes_array = array(
+ array(
+ 'width' => 0,
+ 'height' => 0,
+ ),
+ array(
+ 'width' => 0,
+ 'height' => 0,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => null,
+ 'height' => null,
+ ),
+ array(
+ 'width' => null,
+ 'height' => null,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => '',
+ 'height' => '',
+ ),
+ array(
+ 'width' => '',
+ 'height' => '',
+ 'crop' => true,
+ ),
+ array(
+ 'width' => 0,
+ ),
+ array(
+ 'width' => 0,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => null,
+ ),
+ array(
+ 'width' => null,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => '',
+ ),
+ array(
+ 'width' => '',
+ 'crop' => true,
+ ),
+ );
+
+ $resized = $imagick_image_editor->multi_resize( $sizes_array );
+
+ // If no images are generated, the returned array is empty.
+ $this->assertEmpty( $resized );
+ }
+
+ /**
+ * Test multi_resize with multiple sizes
+ *
+ * ticket 26823
+ */
+ public function test_multi_resize() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $sizes_array = array(
+
+ /**
+ * #0 - 10x10 resize, no cropping.
+ * By aspect, should be 10x6 output.
+ */
+ array(
+ 'width' => 10,
+ 'height' => 10,
+ 'crop' => false,
+ ),
+
+ /**
+ * #1 - 75x50 resize, with cropping.
+ * Output dimensions should be 75x50
+ */
+ array(
+ 'width' => 75,
+ 'height' => 50,
+ 'crop' => true,
+ ),
+
+ /**
+ * #2 - 20 pixel max height, no cropping.
+ * By aspect, should be 30x20 output.
+ */
+ array(
+ 'width' => 9999, # Arbitrary High Value
+ 'height' => 20,
+ 'crop' => false,
+ ),
+
+ /**
+ * #3 - 45 pixel max height, with cropping.
+ * By aspect, should be 45x400 output.
+ */
+ array(
+ 'width' => 45,
+ 'height' => 9999, # Arbitrary High Value
+ 'crop' => true,
+ ),
+
+ /**
+ * #4 - 50 pixel max width, no cropping.
+ * By aspect, should be 50x33 output.
+ */
+ array(
+ 'width' => 50,
+ ),
+
+ /**
+ * #5 - 55 pixel max width, no cropping, null height
+ * By aspect, should be 55x36 output.
+ */
+ array(
+ 'width' => 55,
+ 'height' => null,
+ ),
+
+ /**
+ * #6 - 55 pixel max height, no cropping, no width specified.
+ * By aspect, should be 82x55 output.
+ */
+ array(
+ 'height' => 55,
+ ),
+
+ /**
+ * #7 - 60 pixel max height, no cropping, null width.
+ * By aspect, should be 90x60 output.
+ */
+ array(
+ 'width' => null,
+ 'height' => 60,
+ ),
+
+ /**
+ * #8 - 70 pixel max height, no cropping, negative width.
+ * By aspect, should be 105x70 output.
+ */
+ array(
+ 'width' => -9999, # Arbitrary Negative Value
+ 'height' => 70,
+ ),
+
+ /**
+ * #9 - 200 pixel max width, no cropping, negative height.
+ * By aspect, should be 200x133 output.
+ */
+ array(
+ 'width' => 200,
+ 'height' => -9999, # Arbitrary Negative Value
+ ),
+ );
+
+ $resized = $imagick_image_editor->multi_resize( $sizes_array );
+
+ $expected_array = array(
+
+ // #0
+ array(
+ 'file' => 'waffles-10x7.jpg',
+ 'width' => 10,
+ 'height' => 7,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #1
+ array(
+ 'file' => 'waffles-75x50.jpg',
+ 'width' => 75,
+ 'height' => 50,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #2
+ array(
+ 'file' => 'waffles-30x20.jpg',
+ 'width' => 30,
+ 'height' => 20,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #3
+ array(
+ 'file' => 'waffles-45x400.jpg',
+ 'width' => 45,
+ 'height' => 400,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #4
+ array(
+ 'file' => 'waffles-50x33.jpg',
+ 'width' => 50,
+ 'height' => 33,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #5
+ array(
+ 'file' => 'waffles-55x37.jpg',
+ 'width' => 55,
+ 'height' => 37,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #6
+ array(
+ 'file' => 'waffles-83x55.jpg',
+ 'width' => 83,
+ 'height' => 55,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #7
+ array(
+ 'file' => 'waffles-90x60.jpg',
+ 'width' => 90,
+ 'height' => 60,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #8
+ array(
+ 'file' => 'waffles-105x70.jpg',
+ 'width' => 105,
+ 'height' => 70,
+ 'mime-type' => 'image/jpeg',
+ ),
+
+ // #9
+ array(
+ 'file' => 'waffles-200x133.jpg',
+ 'width' => 200,
+ 'height' => 133,
+ 'mime-type' => 'image/jpeg',
+ ),
+ );
+
+ $this->assertNotNull( $resized );
+ $this->assertEquals( $expected_array, $resized );
+
+ foreach( $resized as $key => $image_data ){
+ $image_path = DIR_TESTDATA . '/images/' . $image_data['file'];
+
+ // Now, verify real dimensions are as expected
+ $this->assertImageDimensions(
+ $image_path,
+ $expected_array[$key]['width'],
+ $expected_array[$key]['height']
+ );
+ }
+ }
+
+ /**
+ * Test resizing an image with cropping
+ */
+ public function test_resize_and_crop() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $imagick_image_editor->resize( 100, 50, true );
+
+ $this->assertEquals(
+ array(
+ 'width' => 100,
+ 'height' => 50,
+ ),
+ $imagick_image_editor->get_size()
+ );
+ }
+
+ /**
+ * Test cropping an image
+ */
+ public function test_crop() {
+ $file = DIR_TESTDATA . '/images/gradient-square.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $imagick_image_editor->crop( 0, 0, 50, 50 );
+
+ $this->assertEquals(
+ array(
+ 'width' => 50,
+ 'height' => 50,
+ ),
+ $imagick_image_editor->get_size()
+ );
+ }
+
+ /**
+ * Test rotating an image 180 deg
+ */
+ public function test_rotate() {
+ $file = DIR_TESTDATA . '/images/gradient-square.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $property = new ReflectionProperty( $imagick_image_editor, 'image' );
+ $property->setAccessible( true );
+
+ $color_top_left = $property->getValue( $imagick_image_editor )->getImagePixelColor( 1, 1 )->getColor();
+
+ $imagick_image_editor->rotate( 180 );
+
+ $this->assertEquals( $color_top_left, $property->getValue( $imagick_image_editor )->getImagePixelColor( 99, 99 )->getColor() );
+ }
+
+ /**
+ * Test flipping an image
+ */
+ public function test_flip() {
+ $file = DIR_TESTDATA . '/images/gradient-square.jpg';
+
+ $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+ $imagick_image_editor->load();
+
+ $property = new ReflectionProperty( $imagick_image_editor, 'image' );
+ $property->setAccessible( true );
+
+ $color_top_left = $property->getValue( $imagick_image_editor )->getImagePixelColor( 1, 1 )->getColor();
+
+ $imagick_image_editor->flip( true, false );
+
+ $this->assertEquals( $color_top_left, $property->getValue( $imagick_image_editor )->getImagePixelColor( 0, 99 )->getColor() );
+ }
+
+ /**
+ * Test the image created with WP_Image_Editor_Imagick preserves alpha when resizing
+ *
+ * @ticket 24871
+ */
+ public function test_image_preserves_alpha_on_resize() {
+ $file = DIR_TESTDATA . '/images/transparent.png';
+
+ $editor = new WP_Image_Editor_Imagick( $file );
+
+ $this->assertNotInstanceOf( 'WP_Error', $editor );
+
+ $editor->load();
+ $editor->resize( 5, 5 );
+ $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
+
+ $editor->save( $save_to_file );
+
+ $im = new Imagick( $save_to_file );
+ $pixel = $im->getImagePixelColor( 0, 0 );
+ $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
+
+ $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
+
+ unlink( $save_to_file );
+ }
+
+ /**
+ * Test the image created with WP_Image_Editor_Imagick preserves alpha with no resizing etc
+ *
+ * @ticket 24871
+ */
+ public function test_image_preserves_alpha() {
+ $file = DIR_TESTDATA . '/images/transparent.png';
+
+ $editor = new WP_Image_Editor_Imagick( $file );
+
+ $this->assertNotInstanceOf( 'WP_Error', $editor );
+
+ $editor->load();
+
+ $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
+
+ $editor->save( $save_to_file );
+
+ $im = new Imagick( $save_to_file );
+ $pixel = $im->getImagePixelColor( 0, 0 );
+ $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
+
+ $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
+
+ unlink( $save_to_file );
+ }
+
+ /**
+ *
+ * @ticket 30596
+ */
+ public function test_image_preserves_alpha_on_rotate() {
+ $file = DIR_TESTDATA . '/images/transparent.png';
+
+ $pre_rotate_editor = new Imagick( $file );
+ $pre_rotate_pixel = $pre_rotate_editor->getImagePixelColor( 0, 0 );
+ $pre_rotate_alpha = $pre_rotate_pixel->getColorValue( imagick::COLOR_ALPHA );
+ $save_to_file = tempnam( get_temp_dir(),'' ) . '.png';
+ $pre_rotate_editor->writeImage( $save_to_file );
+ $pre_rotate_editor->destroy();
+
+ $image_editor = new WP_Image_Editor_Imagick( $save_to_file );
+ $image_editor->load();
+ $this->assertNotInstanceOf( 'WP_Error', $image_editor );
+ $image_editor->rotate( 180 );
+ $image_editor->save( $save_to_file );
+
+ $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0, 0 ), $pre_rotate_alpha );
+ unlink( $save_to_file );
+ }
+
+ /**
+ * Test WP_Image_Editor_Imagick handles extension-less images
+ * @ticket 39195
+ */
+ public function test_image_non_existent_extension() {
+ $image_editor = new WP_Image_Editor_Imagick( DIR_TESTDATA.'/images/test-image-no-extension' );
+ $result = $image_editor->load();
+
+ $this->assertTrue( $result );
+ }
+
+ /**
+ * Test resetting Exif orientation data on rotate
+ *
+ * @ticket 37140
+ */
+ public function test_remove_orientation_data_on_rotate() {
+ $file = DIR_TESTDATA . "/images/test-image-upside-down.jpg";
+ $data = wp_read_image_metadata( $file );
+
+ // The orientation value 3 is equivalent to rotated upside down (180 degrees).
+ $this->assertEquals( 3, intval( $data['orientation'] ), 'Orientation value read from does not match image file Exif data: ' . $file );
+
+ $temp_file = wp_tempnam( $file );
+ $image = wp_get_image_editor( $file );
+
+ // Test a value that would not lead back to 1, as WP is resetting the value to 1 manually.
+ $image->rotate( 90 );
+ $ret = $image->save( $temp_file, 'image/jpeg' );
+
+ $data = wp_read_image_metadata( $ret['path'] );
+
+ // Make sure the image is no longer in The Upside Down Exif orientation.
+ $this->assertEquals( 1, intval( $data['orientation'] ), 'Orientation Exif data was not updated after rotating image: ' . $file );
+
+ // Remove both the generated file ending in .tmp and tmp.jpg due to wp_tempnam().
+ unlink( $temp_file );
+ unlink( $ret['path'] );
+ }
+
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsimageeditor_gdphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/image/editor_gd.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editor_gd.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/image/editor_gd.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,556 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the WP_Image_Editor_GD class
- * @group image
- * @group media
- * @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();
- }
-
- public function test_supports_mime_type_jpeg() {
- $gd_image_editor = new WP_Image_Editor_GD( null );
- $expected = imagetypes() & IMG_JPG;
- $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) );
- }
-
- public function test_supports_mime_type_png() {
- $gd_image_editor = new WP_Image_Editor_GD( null );
- $expected = imagetypes() & IMG_PNG;
- $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) );
- }
-
- public function test_supports_mime_type_gif() {
- $gd_image_editor = new WP_Image_Editor_GD( null );
- $expected = imagetypes() & IMG_GIF;
- $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
- }
-
- /**
- * Test resizing an image, not using crop
- */
- public function test_resize() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $gd_image_editor->resize( 100, 50 );
-
- $this->assertEquals(
- array(
- 'width' => 75,
- 'height' => 50,
- ),
- $gd_image_editor->get_size()
- );
- }
-
- /**
- * Test multi_resize with single image resize and no crop
- */
- public function test_single_multi_resize() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $sizes_array = array(
- array(
- 'width' => 50,
- 'height' => 50,
- ),
- );
-
- $resized = $gd_image_editor->multi_resize( $sizes_array );
-
- # First, check to see if returned array is as expected
- $expected_array = array(
- array(
- 'file' => 'waffles-50x33.jpg',
- 'width' => 50,
- 'height' => 33,
- 'mime-type' => 'image/jpeg',
- ),
- );
-
- $this->assertEquals( $expected_array, $resized );
-
- // Now, verify real dimensions are as expected
- $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file'];
- $this->assertImageDimensions(
- $image_path,
- $expected_array[0]['width'],
- $expected_array[0]['height']
- );
- }
-
- /**
- * Ensure multi_resize doesn't create an image when
- * both height and weight are missing, null, or 0.
- *
- * ticket 26823
- */
- public function test_multi_resize_does_not_create() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $sizes_array = array(
- array(
- 'width' => 0,
- 'height' => 0,
- ),
- array(
- 'width' => 0,
- 'height' => 0,
- 'crop' => true,
- ),
- array(
- 'width' => null,
- 'height' => null,
- ),
- array(
- 'width' => null,
- 'height' => null,
- 'crop' => true,
- ),
- array(
- 'width' => '',
- 'height' => '',
- ),
- array(
- 'width' => '',
- 'height' => '',
- 'crop' => true,
- ),
- array(
- 'width' => 0,
- ),
- array(
- 'width' => 0,
- 'crop' => true,
- ),
- array(
- 'width' => null,
- ),
- array(
- 'width' => null,
- 'crop' => true,
- ),
- array(
- 'width' => '',
- ),
- array(
- 'width' => '',
- 'crop' => true,
- ),
- );
-
- $resized = $gd_image_editor->multi_resize( $sizes_array );
-
- // If no images are generated, the returned array is empty.
- $this->assertEmpty( $resized );
- }
-
- /**
- * Test multi_resize with multiple sizes
- *
- * ticket 26823
- */
- public function test_multi_resize() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $sizes_array = array(
-
- /**
- * #0 - 10x10 resize, no cropping.
- * By aspect, should be 10x6 output.
- */
- array(
- 'width' => 10,
- 'height' => 10,
- 'crop' => false,
- ),
-
- /**
- * #1 - 75x50 resize, with cropping.
- * Output dimensions should be 75x50
- */
- array(
- 'width' => 75,
- 'height' => 50,
- 'crop' => true,
- ),
-
- /**
- * #2 - 20 pixel max height, no cropping.
- * By aspect, should be 30x20 output.
- */
- array(
- 'width' => 9999, # Arbitrary High Value
- 'height' => 20,
- 'crop' => false,
- ),
-
- /**
- * #3 - 45 pixel max height, with cropping.
- * By aspect, should be 45x400 output.
- */
- array(
- 'width' => 45,
- 'height' => 9999, # Arbitrary High Value
- 'crop' => true,
- ),
-
- /**
- * #4 - 50 pixel max width, no cropping.
- * By aspect, should be 50x33 output.
- */
- array(
- 'width' => 50,
- ),
-
- /**
- * #5 - 55 pixel max width, no cropping, null height
- * By aspect, should be 55x36 output.
- */
- array(
- 'width' => 55,
- 'height' => null,
- ),
-
- /**
- * #6 - 55 pixel max height, no cropping, no width specified.
- * By aspect, should be 82x55 output.
- */
- array(
- 'height' => 55,
- ),
-
- /**
- * #7 - 60 pixel max height, no cropping, null width.
- * By aspect, should be 90x60 output.
- */
- array(
- 'width' => null,
- 'height' => 60,
- ),
-
- /**
- * #8 - 70 pixel max height, no cropping, negative width.
- * By aspect, should be 105x70 output.
- */
- array(
- 'width' => -9999, # Arbitrary Negative Value
- 'height' => 70,
- ),
-
- /**
- * #9 - 200 pixel max width, no cropping, negative height.
- * By aspect, should be 200x133 output.
- */
- array(
- 'width' => 200,
- 'height' => -9999, # Arbitrary Negative Value
- ),
- );
-
- $resized = $gd_image_editor->multi_resize( $sizes_array );
-
- $expected_array = array(
-
- // #0
- array(
- 'file' => 'waffles-10x7.jpg',
- 'width' => 10,
- 'height' => 7,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #1
- array(
- 'file' => 'waffles-75x50.jpg',
- 'width' => 75,
- 'height' => 50,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #2
- array(
- 'file' => 'waffles-30x20.jpg',
- 'width' => 30,
- 'height' => 20,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #3
- array(
- 'file' => 'waffles-45x400.jpg',
- 'width' => 45,
- 'height' => 400,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #4
- array(
- 'file' => 'waffles-50x33.jpg',
- 'width' => 50,
- 'height' => 33,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #5
- array(
- 'file' => 'waffles-55x37.jpg',
- 'width' => 55,
- 'height' => 37,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #6
- array(
- 'file' => 'waffles-83x55.jpg',
- 'width' => 83,
- 'height' => 55,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #7
- array(
- 'file' => 'waffles-90x60.jpg',
- 'width' => 90,
- 'height' => 60,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #8
- array(
- 'file' => 'waffles-105x70.jpg',
- 'width' => 105,
- 'height' => 70,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #9
- array(
- 'file' => 'waffles-200x133.jpg',
- 'width' => 200,
- 'height' => 133,
- 'mime-type' => 'image/jpeg',
- ),
- );
-
- $this->assertNotNull( $resized );
- $this->assertEquals( $expected_array, $resized );
-
- foreach( $resized as $key => $image_data ){
- $image_path = DIR_TESTDATA . '/images/' . $image_data['file'];
-
- // Now, verify real dimensions are as expected
- $this->assertImageDimensions(
- $image_path,
- $expected_array[$key]['width'],
- $expected_array[$key]['height']
- );
- }
- }
-
- /**
- * Test resizing an image with cropping
- */
- public function test_resize_and_crop() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $gd_image_editor->resize( 100, 50, true );
-
- $this->assertEquals(
- array(
- 'width' => 100,
- 'height' => 50,
- ),
- $gd_image_editor->get_size()
- );
- }
-
- /**
- * Test cropping an image
- */
- public function test_crop() {
- $file = DIR_TESTDATA . '/images/gradient-square.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $gd_image_editor->crop( 0, 0, 50, 50 );
-
- $this->assertEquals(
- array(
- 'width' => 50,
- 'height' => 50,
- ),
- $gd_image_editor->get_size()
- );
- }
-
- /**
- * Test rotating an image 180 deg
- */
- public function test_rotate() {
- $file = DIR_TESTDATA . '/images/gradient-square.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $property = new ReflectionProperty( $gd_image_editor, 'image' );
- $property->setAccessible( true );
-
- $color_top_left = imagecolorat( $property->getValue( $gd_image_editor ), 0, 0 );
-
- $gd_image_editor->rotate( 180 );
-
- $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 99, 99 ) );
- }
-
- /**
- * Test flipping an image
- */
- public function test_flip() {
- $file = DIR_TESTDATA . '/images/gradient-square.jpg';
-
- $gd_image_editor = new WP_Image_Editor_GD( $file );
- $gd_image_editor->load();
-
- $property = new ReflectionProperty( $gd_image_editor, 'image' );
- $property->setAccessible( true );
-
- $color_top_left = imagecolorat( $property->getValue( $gd_image_editor ), 0, 0 );
-
- $gd_image_editor->flip( true, false );
-
- $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 0, 99 ) );
- }
-
- /**
- * Test the image created with WP_Image_Editor_GD preserves alpha when resizing
- *
- * @ticket 23039
- */
- public function test_image_preserves_alpha_on_resize() {
- if ( ! ( imagetypes() & IMG_PNG ) ) {
- $this->fail( 'This test requires PHP to be compiled with PNG support.' );
- }
-
- $file = DIR_TESTDATA . '/images/transparent.png';
-
- $editor = wp_get_image_editor( $file );
-
- $this->assertNotInstanceOf( 'WP_Error', $editor );
-
- $editor->load();
- $editor->resize( 5, 5 );
- $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
-
- $editor->save( $save_to_file );
-
- $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
-
- unlink( $save_to_file );
- }
-
- /**
- * Test the image created with WP_Image_Editor_GD preserves alpha with no resizing etc
- *
- * @ticket 23039
- */
- public function test_image_preserves_alpha() {
- if ( ! ( imagetypes() & IMG_PNG ) ) {
- $this->fail( 'This test requires PHP to be compiled with PNG support.' );
- }
-
- $file = DIR_TESTDATA . '/images/transparent.png';
-
- $editor = wp_get_image_editor( $file );
-
- $this->assertNotInstanceOf( 'WP_Error', $editor );
-
- $editor->load();
-
- $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
-
- $editor->save( $save_to_file );
-
- $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
-
- unlink( $save_to_file );
- }
-
- /**
- *
- * @ticket 30596
- */
- public function test_image_preserves_alpha_on_rotate() {
- if ( ! ( imagetypes() & IMG_PNG ) ) {
- $this->fail( 'This test requires PHP to be compiled with PNG support.' );
- }
-
- $file = DIR_TESTDATA . '/images/transparent.png';
-
- $image = imagecreatefrompng( $file );
- $rgb = imagecolorat( $image, 0, 0 );
- $expected = imagecolorsforindex( $image, $rgb );
-
- $editor = new WP_Image_Editor_GD( $file );
- $this->assertNotInstanceOf( 'WP_Error', $editor );
- $editor->load();
- $editor->rotate( 180 );
- $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
-
- $editor->save( $save_to_file );
-
- $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), $expected['alpha'] );
- unlink( $save_to_file );
-
- }
-
- /**
- * Test WP_Image_Editor_GD handles extension-less images
- * @ticket 39195
- */
- public function test_image_non_existent_extension() {
- $image_editor = new WP_Image_Editor_GD( DIR_TESTDATA.'/images/test-image-no-extension' );
- $result = $image_editor->load();
-
- $this->assertTrue( $result );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsimageeditor_imagickphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/image/editor_imagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editor_imagick.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/image/editor_imagick.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,575 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * Test the WP_Image_Editor_Imagick class
- * @group image
- * @group media
- * @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';
-
- public function setUp() {
- require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
- require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.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 ImageMagick compatible mime types.
- */
- public function test_supports_mime_type() {
- $imagick_image_editor = new WP_Image_Editor_Imagick( null );
-
- $this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/jpeg' ), 'Does not support image/jpeg' );
- $this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/png' ), 'Does not support image/png' );
- $this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/gif' ), 'Does not support image/gif' );
- }
-
- /**
- * Test resizing an image, not using crop
- */
- public function test_resize() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $imagick_image_editor->resize( 100, 50 );
-
- $this->assertEquals(
- array(
- 'width' => 75,
- 'height' => 50,
- ),
- $imagick_image_editor->get_size()
- );
- }
-
- /**
- * Test multi_resize with single image resize and no crop
- */
- public function test_single_multi_resize() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $sizes_array = array(
- array(
- 'width' => 50,
- 'height' => 50,
- ),
- );
-
- $resized = $imagick_image_editor->multi_resize( $sizes_array );
-
- # First, check to see if returned array is as expected
- $expected_array = array(
- array(
- 'file' => 'waffles-50x33.jpg',
- 'width' => 50,
- 'height' => 33,
- 'mime-type' => 'image/jpeg',
- ),
- );
-
- $this->assertEquals( $expected_array, $resized );
-
- // Now, verify real dimensions are as expected
- $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file'];
- $this->assertImageDimensions(
- $image_path,
- $expected_array[0]['width'],
- $expected_array[0]['height']
- );
- }
-
- /**
- * Ensure multi_resize doesn't create an image when
- * both height and weight are missing, null, or 0.
- *
- * ticket 26823
- */
- public function test_multi_resize_does_not_create() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $sizes_array = array(
- array(
- 'width' => 0,
- 'height' => 0,
- ),
- array(
- 'width' => 0,
- 'height' => 0,
- 'crop' => true,
- ),
- array(
- 'width' => null,
- 'height' => null,
- ),
- array(
- 'width' => null,
- 'height' => null,
- 'crop' => true,
- ),
- array(
- 'width' => '',
- 'height' => '',
- ),
- array(
- 'width' => '',
- 'height' => '',
- 'crop' => true,
- ),
- array(
- 'width' => 0,
- ),
- array(
- 'width' => 0,
- 'crop' => true,
- ),
- array(
- 'width' => null,
- ),
- array(
- 'width' => null,
- 'crop' => true,
- ),
- array(
- 'width' => '',
- ),
- array(
- 'width' => '',
- 'crop' => true,
- ),
- );
-
- $resized = $imagick_image_editor->multi_resize( $sizes_array );
-
- // If no images are generated, the returned array is empty.
- $this->assertEmpty( $resized );
- }
-
- /**
- * Test multi_resize with multiple sizes
- *
- * ticket 26823
- */
- public function test_multi_resize() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $sizes_array = array(
-
- /**
- * #0 - 10x10 resize, no cropping.
- * By aspect, should be 10x6 output.
- */
- array(
- 'width' => 10,
- 'height' => 10,
- 'crop' => false,
- ),
-
- /**
- * #1 - 75x50 resize, with cropping.
- * Output dimensions should be 75x50
- */
- array(
- 'width' => 75,
- 'height' => 50,
- 'crop' => true,
- ),
-
- /**
- * #2 - 20 pixel max height, no cropping.
- * By aspect, should be 30x20 output.
- */
- array(
- 'width' => 9999, # Arbitrary High Value
- 'height' => 20,
- 'crop' => false,
- ),
-
- /**
- * #3 - 45 pixel max height, with cropping.
- * By aspect, should be 45x400 output.
- */
- array(
- 'width' => 45,
- 'height' => 9999, # Arbitrary High Value
- 'crop' => true,
- ),
-
- /**
- * #4 - 50 pixel max width, no cropping.
- * By aspect, should be 50x33 output.
- */
- array(
- 'width' => 50,
- ),
-
- /**
- * #5 - 55 pixel max width, no cropping, null height
- * By aspect, should be 55x36 output.
- */
- array(
- 'width' => 55,
- 'height' => null,
- ),
-
- /**
- * #6 - 55 pixel max height, no cropping, no width specified.
- * By aspect, should be 82x55 output.
- */
- array(
- 'height' => 55,
- ),
-
- /**
- * #7 - 60 pixel max height, no cropping, null width.
- * By aspect, should be 90x60 output.
- */
- array(
- 'width' => null,
- 'height' => 60,
- ),
-
- /**
- * #8 - 70 pixel max height, no cropping, negative width.
- * By aspect, should be 105x70 output.
- */
- array(
- 'width' => -9999, # Arbitrary Negative Value
- 'height' => 70,
- ),
-
- /**
- * #9 - 200 pixel max width, no cropping, negative height.
- * By aspect, should be 200x133 output.
- */
- array(
- 'width' => 200,
- 'height' => -9999, # Arbitrary Negative Value
- ),
- );
-
- $resized = $imagick_image_editor->multi_resize( $sizes_array );
-
- $expected_array = array(
-
- // #0
- array(
- 'file' => 'waffles-10x7.jpg',
- 'width' => 10,
- 'height' => 7,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #1
- array(
- 'file' => 'waffles-75x50.jpg',
- 'width' => 75,
- 'height' => 50,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #2
- array(
- 'file' => 'waffles-30x20.jpg',
- 'width' => 30,
- 'height' => 20,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #3
- array(
- 'file' => 'waffles-45x400.jpg',
- 'width' => 45,
- 'height' => 400,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #4
- array(
- 'file' => 'waffles-50x33.jpg',
- 'width' => 50,
- 'height' => 33,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #5
- array(
- 'file' => 'waffles-55x37.jpg',
- 'width' => 55,
- 'height' => 37,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #6
- array(
- 'file' => 'waffles-83x55.jpg',
- 'width' => 83,
- 'height' => 55,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #7
- array(
- 'file' => 'waffles-90x60.jpg',
- 'width' => 90,
- 'height' => 60,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #8
- array(
- 'file' => 'waffles-105x70.jpg',
- 'width' => 105,
- 'height' => 70,
- 'mime-type' => 'image/jpeg',
- ),
-
- // #9
- array(
- 'file' => 'waffles-200x133.jpg',
- 'width' => 200,
- 'height' => 133,
- 'mime-type' => 'image/jpeg',
- ),
- );
-
- $this->assertNotNull( $resized );
- $this->assertEquals( $expected_array, $resized );
-
- foreach( $resized as $key => $image_data ){
- $image_path = DIR_TESTDATA . '/images/' . $image_data['file'];
-
- // Now, verify real dimensions are as expected
- $this->assertImageDimensions(
- $image_path,
- $expected_array[$key]['width'],
- $expected_array[$key]['height']
- );
- }
- }
-
- /**
- * Test resizing an image with cropping
- */
- public function test_resize_and_crop() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $imagick_image_editor->resize( 100, 50, true );
-
- $this->assertEquals(
- array(
- 'width' => 100,
- 'height' => 50,
- ),
- $imagick_image_editor->get_size()
- );
- }
-
- /**
- * Test cropping an image
- */
- public function test_crop() {
- $file = DIR_TESTDATA . '/images/gradient-square.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $imagick_image_editor->crop( 0, 0, 50, 50 );
-
- $this->assertEquals(
- array(
- 'width' => 50,
- 'height' => 50,
- ),
- $imagick_image_editor->get_size()
- );
- }
-
- /**
- * Test rotating an image 180 deg
- */
- public function test_rotate() {
- $file = DIR_TESTDATA . '/images/gradient-square.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $property = new ReflectionProperty( $imagick_image_editor, 'image' );
- $property->setAccessible( true );
-
- $color_top_left = $property->getValue( $imagick_image_editor )->getImagePixelColor( 1, 1 )->getColor();
-
- $imagick_image_editor->rotate( 180 );
-
- $this->assertEquals( $color_top_left, $property->getValue( $imagick_image_editor )->getImagePixelColor( 99, 99 )->getColor() );
- }
-
- /**
- * Test flipping an image
- */
- public function test_flip() {
- $file = DIR_TESTDATA . '/images/gradient-square.jpg';
-
- $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
- $imagick_image_editor->load();
-
- $property = new ReflectionProperty( $imagick_image_editor, 'image' );
- $property->setAccessible( true );
-
- $color_top_left = $property->getValue( $imagick_image_editor )->getImagePixelColor( 1, 1 )->getColor();
-
- $imagick_image_editor->flip( true, false );
-
- $this->assertEquals( $color_top_left, $property->getValue( $imagick_image_editor )->getImagePixelColor( 0, 99 )->getColor() );
- }
-
- /**
- * Test the image created with WP_Image_Editor_Imagick preserves alpha when resizing
- *
- * @ticket 24871
- */
- public function test_image_preserves_alpha_on_resize() {
- $file = DIR_TESTDATA . '/images/transparent.png';
-
- $editor = new WP_Image_Editor_Imagick( $file );
-
- $this->assertNotInstanceOf( 'WP_Error', $editor );
-
- $editor->load();
- $editor->resize( 5, 5 );
- $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
-
- $editor->save( $save_to_file );
-
- $im = new Imagick( $save_to_file );
- $pixel = $im->getImagePixelColor( 0, 0 );
- $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
-
- $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
-
- unlink( $save_to_file );
- }
-
- /**
- * Test the image created with WP_Image_Editor_Imagick preserves alpha with no resizing etc
- *
- * @ticket 24871
- */
- public function test_image_preserves_alpha() {
- $file = DIR_TESTDATA . '/images/transparent.png';
-
- $editor = new WP_Image_Editor_Imagick( $file );
-
- $this->assertNotInstanceOf( 'WP_Error', $editor );
-
- $editor->load();
-
- $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
-
- $editor->save( $save_to_file );
-
- $im = new Imagick( $save_to_file );
- $pixel = $im->getImagePixelColor( 0, 0 );
- $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
-
- $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
-
- unlink( $save_to_file );
- }
-
- /**
- *
- * @ticket 30596
- */
- public function test_image_preserves_alpha_on_rotate() {
- $file = DIR_TESTDATA . '/images/transparent.png';
-
- $pre_rotate_editor = new Imagick( $file );
- $pre_rotate_pixel = $pre_rotate_editor->getImagePixelColor( 0, 0 );
- $pre_rotate_alpha = $pre_rotate_pixel->getColorValue( imagick::COLOR_ALPHA );
- $save_to_file = tempnam( get_temp_dir(),'' ) . '.png';
- $pre_rotate_editor->writeImage( $save_to_file );
- $pre_rotate_editor->destroy();
-
- $image_editor = new WP_Image_Editor_Imagick( $save_to_file );
- $image_editor->load();
- $this->assertNotInstanceOf( 'WP_Error', $image_editor );
- $image_editor->rotate( 180 );
- $image_editor->save( $save_to_file );
-
- $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0, 0 ), $pre_rotate_alpha );
- unlink( $save_to_file );
- }
-
- /**
- * Test WP_Image_Editor_Imagick handles extension-less images
- * @ticket 39195
- */
- public function test_image_non_existent_extension() {
- $image_editor = new WP_Image_Editor_Imagick( DIR_TESTDATA.'/images/test-image-no-extension' );
- $result = $image_editor->load();
-
- $this->assertTrue( $result );
- }
-
- /**
- * Test resetting Exif orientation data on rotate
- *
- * @ticket 37140
- */
- public function test_remove_orientation_data_on_rotate() {
- $file = DIR_TESTDATA . "/images/test-image-upside-down.jpg";
- $data = wp_read_image_metadata( $file );
-
- // The orientation value 3 is equivalent to rotated upside down (180 degrees).
- $this->assertEquals( 3, intval( $data['orientation'] ), 'Orientation value read from does not match image file Exif data: ' . $file );
-
- $temp_file = wp_tempnam( $file );
- $image = wp_get_image_editor( $file );
-
- // Test a value that would not lead back to 1, as WP is resetting the value to 1 manually.
- $image->rotate( 90 );
- $ret = $image->save( $temp_file, 'image/jpeg' );
-
- $data = wp_read_image_metadata( $ret['path'] );
-
- // Make sure the image is no longer in The Upside Down Exif orientation.
- $this->assertEquals( 1, intval( $data['orientation'] ), 'Orientation Exif data was not updated after rotating image: ' . $file );
-
- // Remove both the generated file ending in .tmp and tmp.jpg due to wp_tempnam().
- unlink( $temp_file );
- unlink( $ret['path'] );
- }
-
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsimageintermediateSizephpfromrev41260trunktestsphpunittestsimageintermediate_sizephp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/image/intermediateSize.php (from rev 41260, trunk/tests/phpunit/tests/image/intermediate_size.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/intermediateSize.php (rev 0)
+++ trunk/tests/phpunit/tests/image/intermediateSize.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,261 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * @group image
+ * @group media
+ * @group upload
+ */
+class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
+ function tearDown() {
+ $this->remove_added_uploads();
+
+ remove_image_size( 'test-size' );
+ remove_image_size( 'false-height' );
+ remove_image_size( 'false-width' );
+ remove_image_size( 'off-by-one' );
+ parent::tearDown();
+ }
+
+ public function _make_attachment( $file, $parent_post_id = 0 ) {
+ $contents = file_get_contents( $file );
+ $upload = wp_upload_bits( basename( $file ), null, $contents );
+
+ return parent::_make_attachment( $upload, $parent_post_id );
+ }
+
+ function test_make_intermediate_size_no_size() {
+ $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
+
+ $this->assertFalse( $image );
+ }
+
+ function test_make_intermediate_size_width() {
+ if ( !function_exists( 'imagejpeg' ) )
+ $this->fail( 'jpeg support unavailable' );
+
+ $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 0, false );
+
+ $this->assertInternalType( 'array', $image );
+ }
+
+ function test_make_intermediate_size_height() {
+ if ( !function_exists( 'imagejpeg' ) )
+ $this->fail( 'jpeg support unavailable' );
+
+ $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 75, false );
+
+ $this->assertInternalType( 'array', $image );
+ }
+
+ function test_make_intermediate_size_successful() {
+ if ( !function_exists( 'imagejpeg' ) )
+ $this->fail( 'jpeg support unavailable' );
+
+ $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 75, true );
+
+ $this->assertInternalType( 'array', $image );
+ $this->assertEquals( 100, $image['width'] );
+ $this->assertEquals( 75, $image['height'] );
+ $this->assertEquals( 'image/jpeg', $image['mime-type'] );
+
+ $this->assertFalse( isset( $image['path'] ) );
+
+ unlink( DIR_TESTDATA . '/images/a2-small-100x75.jpg' );
+ }
+
+ /**
+ * @ticket 17626
+ */
+ function test_get_intermediate_sizes_by_name() {
+ add_image_size( 'test-size', 330, 220, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ // look for a size by name
+ $image = image_get_intermediate_size( $id, 'test-size' );
+
+ // cleanup
+ remove_image_size( 'test-size' );
+
+ // test for the expected string because the array will by definition
+ // return with the correct height and width attributes
+ $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 );
+ }
+
+ /**
+ * @ticket 17626
+ */
+ function test_get_intermediate_sizes_by_array_exact() {
+ // Only one dimention match shouldn't return false positive (see: 17626)
+ add_image_size( 'test-size', 330, 220, true );
+ add_image_size( 'false-height', 330, 400, true );
+ add_image_size( 'false-width', 600, 220, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ // look for a size by array that exists
+ // note: staying larger than 300px to miss default medium crop
+ $image = image_get_intermediate_size( $id, array( 330, 220 ) );
+
+ // test for the expected string because the array will by definition
+ // return with the correct height and width attributes
+ $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 );
+ }
+
+ /**
+ * @ticket 17626
+ */
+ function test_get_intermediate_sizes_by_array_nearest() {
+ // If an exact size is not found, it should be returned
+ // If not, find nearest size that is larger (see: 17626)
+ add_image_size( 'test-size', 450, 300, true );
+ add_image_size( 'false-height', 330, 100, true );
+ add_image_size( 'false-width', 150, 220, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ // look for a size by array that doesn't exist
+ // note: staying larger than 300px to miss default medium crop
+ $image = image_get_intermediate_size( $id, array( 330, 220 ) );
+
+ // you have to test for the string because the image will by definition
+ // return with the correct height and width attributes
+ $this->assertTrue( strpos( $image['file'], '450x300' ) > 0 );
+ }
+
+ /**
+ * @ticket 17626
+ */
+ function test_get_intermediate_sizes_by_array_nearest_false() {
+ // If an exact size is not found, it should be returned
+ // If not, find nearest size that is larger, otherwise return false (see: 17626)
+ add_image_size( 'false-height', 330, 100, true );
+ add_image_size( 'false-width', 150, 220, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ // look for a size by array that doesn't exist
+ // note: staying larger than 300px to miss default medium crop
+ $image = image_get_intermediate_size( $id, array( 330, 220 ) );
+
+ // you have to test for the string because the image will by definition
+ // return with the correct height and width attributes
+ $this->assertFalse( $image );
+ }
+
+ /**
+ * @ticket 17626
+ */
+ function test_get_intermediate_sizes_by_array_zero_height() {
+ // Generate random width
+ $random_w = rand( 300, 400 );
+
+ // Only one dimention match shouldn't return false positive (see: 17626)
+ add_image_size( 'test-size', $random_w, 0, false );
+ add_image_size( 'false-height', $random_w, 100, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ $original = wp_get_attachment_metadata( $id );
+ $image_w = $random_w;
+ $image_h = round( ( $image_w / $original['width'] ) * $original['height'] );
+
+ // look for a size by array that exists
+ // note: staying larger than 300px to miss default medium crop
+ $image = image_get_intermediate_size( $id, array( $random_w, 0 ) );
+
+ // test for the expected string because the array will by definition
+ // return with the correct height and width attributes
+ $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 );
+ }
+
+ /**
+ * @ticket 17626
+ * @ticket 34087
+ */
+ function test_get_intermediate_sizes_by_array_zero_width() {
+ // 202 is the smallest height that will trigger a miss for 'false-height'.
+ $height = 202;
+
+ // Only one dimention match shouldn't return false positive (see: 17626)
+ add_image_size( 'test-size', 0, $height, false );
+ add_image_size( 'false-height', 300, $height, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ $original = wp_get_attachment_metadata( $id );
+ $image_h = $height;
+ $image_w = round( ( $image_h / $original['height'] ) * $original['width'] );
+
+ // look for a size by array that exists
+ // note: staying larger than 300px to miss default medium crop
+ $image = image_get_intermediate_size( $id, array( 0, $height ) );
+
+ // test for the expected string because the array will by definition
+ // return with the correct height and width attributes
+ $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 );
+ }
+
+ /**
+ * @ticket 17626
+ * @ticket 34087
+ */
+ public function test_get_intermediate_sizes_should_match_size_with_off_by_one_aspect_ratio() {
+ // Original is 600x400. 300x201 is close enough to match.
+ $width = 300;
+ $height = 201;
+ add_image_size( 'off-by-one', $width, $height, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ $original = wp_get_attachment_metadata( $id );
+ $image_h = $height;
+ $image_w = round( ( $image_h / $original['height'] ) * $original['width'] );
+
+ // look for a size by array that exists
+ // note: staying larger than 300px to miss default medium crop
+ $image = image_get_intermediate_size( $id, array( 0, $height ) );
+
+ $this->assertTrue( strpos( $image['file'], $width . 'x' . $height ) > 0 );
+ }
+
+ /**
+ * @ticket 34384
+ */
+ public function test_get_intermediate_size_with_small_size_array() {
+ // Add a hard cropped size that matches the aspect ratio we're going to test.
+ add_image_size( 'test-size', 200, 100, true );
+
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ // Request a size by array that doesn't exist and is smaller than the 'thumbnail'
+ $image = image_get_intermediate_size( $id, array( 50, 25 ) );
+
+ // We should get the 'test-size' file and not the thumbnail.
+ $this->assertTrue( strpos( $image['file'], '200x100' ) > 0 );
+ }
+
+ /**
+ * @ticket 34384
+ */
+ public function test_get_intermediate_size_with_small_size_array_fallback() {
+ $file = DIR_TESTDATA . '/images/waffles.jpg';
+ $id = $this->_make_attachment( $file, 0 );
+
+ $original = wp_get_attachment_metadata( $id );
+ $thumbnail_file = $original['sizes']['thumbnail']['file'];
+
+ // Request a size by array that doesn't exist and is smaller than the 'thumbnail'
+ $image = image_get_intermediate_size( $id, array( 50, 25 ) );
+
+ // We should get the 'thumbnail' file as a fallback.
+ $this->assertSame( $image['file'], $thumbnail_file );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsimageintermediate_sizephp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/image/intermediate_size.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/intermediate_size.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/image/intermediate_size.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,261 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * @group image
- * @group media
- * @group upload
- */
-class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
- function tearDown() {
- $this->remove_added_uploads();
-
- remove_image_size( 'test-size' );
- remove_image_size( 'false-height' );
- remove_image_size( 'false-width' );
- remove_image_size( 'off-by-one' );
- parent::tearDown();
- }
-
- public function _make_attachment( $file, $parent_post_id = 0 ) {
- $contents = file_get_contents( $file );
- $upload = wp_upload_bits( basename( $file ), null, $contents );
-
- return parent::_make_attachment( $upload, $parent_post_id );
- }
-
- function test_make_intermediate_size_no_size() {
- $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
-
- $this->assertFalse( $image );
- }
-
- function test_make_intermediate_size_width() {
- if ( !function_exists( 'imagejpeg' ) )
- $this->fail( 'jpeg support unavailable' );
-
- $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 0, false );
-
- $this->assertInternalType( 'array', $image );
- }
-
- function test_make_intermediate_size_height() {
- if ( !function_exists( 'imagejpeg' ) )
- $this->fail( 'jpeg support unavailable' );
-
- $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 75, false );
-
- $this->assertInternalType( 'array', $image );
- }
-
- function test_make_intermediate_size_successful() {
- if ( !function_exists( 'imagejpeg' ) )
- $this->fail( 'jpeg support unavailable' );
-
- $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 75, true );
-
- $this->assertInternalType( 'array', $image );
- $this->assertEquals( 100, $image['width'] );
- $this->assertEquals( 75, $image['height'] );
- $this->assertEquals( 'image/jpeg', $image['mime-type'] );
-
- $this->assertFalse( isset( $image['path'] ) );
-
- unlink( DIR_TESTDATA . '/images/a2-small-100x75.jpg' );
- }
-
- /**
- * @ticket 17626
- */
- function test_get_intermediate_sizes_by_name() {
- add_image_size( 'test-size', 330, 220, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- // look for a size by name
- $image = image_get_intermediate_size( $id, 'test-size' );
-
- // cleanup
- remove_image_size( 'test-size' );
-
- // test for the expected string because the array will by definition
- // return with the correct height and width attributes
- $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 );
- }
-
- /**
- * @ticket 17626
- */
- function test_get_intermediate_sizes_by_array_exact() {
- // Only one dimention match shouldn't return false positive (see: 17626)
- add_image_size( 'test-size', 330, 220, true );
- add_image_size( 'false-height', 330, 400, true );
- add_image_size( 'false-width', 600, 220, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- // look for a size by array that exists
- // note: staying larger than 300px to miss default medium crop
- $image = image_get_intermediate_size( $id, array( 330, 220 ) );
-
- // test for the expected string because the array will by definition
- // return with the correct height and width attributes
- $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 );
- }
-
- /**
- * @ticket 17626
- */
- function test_get_intermediate_sizes_by_array_nearest() {
- // If an exact size is not found, it should be returned
- // If not, find nearest size that is larger (see: 17626)
- add_image_size( 'test-size', 450, 300, true );
- add_image_size( 'false-height', 330, 100, true );
- add_image_size( 'false-width', 150, 220, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- // look for a size by array that doesn't exist
- // note: staying larger than 300px to miss default medium crop
- $image = image_get_intermediate_size( $id, array( 330, 220 ) );
-
- // you have to test for the string because the image will by definition
- // return with the correct height and width attributes
- $this->assertTrue( strpos( $image['file'], '450x300' ) > 0 );
- }
-
- /**
- * @ticket 17626
- */
- function test_get_intermediate_sizes_by_array_nearest_false() {
- // If an exact size is not found, it should be returned
- // If not, find nearest size that is larger, otherwise return false (see: 17626)
- add_image_size( 'false-height', 330, 100, true );
- add_image_size( 'false-width', 150, 220, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- // look for a size by array that doesn't exist
- // note: staying larger than 300px to miss default medium crop
- $image = image_get_intermediate_size( $id, array( 330, 220 ) );
-
- // you have to test for the string because the image will by definition
- // return with the correct height and width attributes
- $this->assertFalse( $image );
- }
-
- /**
- * @ticket 17626
- */
- function test_get_intermediate_sizes_by_array_zero_height() {
- // Generate random width
- $random_w = rand( 300, 400 );
-
- // Only one dimention match shouldn't return false positive (see: 17626)
- add_image_size( 'test-size', $random_w, 0, false );
- add_image_size( 'false-height', $random_w, 100, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- $original = wp_get_attachment_metadata( $id );
- $image_w = $random_w;
- $image_h = round( ( $image_w / $original['width'] ) * $original['height'] );
-
- // look for a size by array that exists
- // note: staying larger than 300px to miss default medium crop
- $image = image_get_intermediate_size( $id, array( $random_w, 0 ) );
-
- // test for the expected string because the array will by definition
- // return with the correct height and width attributes
- $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 );
- }
-
- /**
- * @ticket 17626
- * @ticket 34087
- */
- function test_get_intermediate_sizes_by_array_zero_width() {
- // 202 is the smallest height that will trigger a miss for 'false-height'.
- $height = 202;
-
- // Only one dimention match shouldn't return false positive (see: 17626)
- add_image_size( 'test-size', 0, $height, false );
- add_image_size( 'false-height', 300, $height, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- $original = wp_get_attachment_metadata( $id );
- $image_h = $height;
- $image_w = round( ( $image_h / $original['height'] ) * $original['width'] );
-
- // look for a size by array that exists
- // note: staying larger than 300px to miss default medium crop
- $image = image_get_intermediate_size( $id, array( 0, $height ) );
-
- // test for the expected string because the array will by definition
- // return with the correct height and width attributes
- $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 );
- }
-
- /**
- * @ticket 17626
- * @ticket 34087
- */
- public function test_get_intermediate_sizes_should_match_size_with_off_by_one_aspect_ratio() {
- // Original is 600x400. 300x201 is close enough to match.
- $width = 300;
- $height = 201;
- add_image_size( 'off-by-one', $width, $height, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- $original = wp_get_attachment_metadata( $id );
- $image_h = $height;
- $image_w = round( ( $image_h / $original['height'] ) * $original['width'] );
-
- // look for a size by array that exists
- // note: staying larger than 300px to miss default medium crop
- $image = image_get_intermediate_size( $id, array( 0, $height ) );
-
- $this->assertTrue( strpos( $image['file'], $width . 'x' . $height ) > 0 );
- }
-
- /**
- * @ticket 34384
- */
- public function test_get_intermediate_size_with_small_size_array() {
- // Add a hard cropped size that matches the aspect ratio we're going to test.
- add_image_size( 'test-size', 200, 100, true );
-
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- // Request a size by array that doesn't exist and is smaller than the 'thumbnail'
- $image = image_get_intermediate_size( $id, array( 50, 25 ) );
-
- // We should get the 'test-size' file and not the thumbnail.
- $this->assertTrue( strpos( $image['file'], '200x100' ) > 0 );
- }
-
- /**
- * @ticket 34384
- */
- public function test_get_intermediate_size_with_small_size_array_fallback() {
- $file = DIR_TESTDATA . '/images/waffles.jpg';
- $id = $this->_make_attachment( $file, 0 );
-
- $original = wp_get_attachment_metadata( $id );
- $thumbnail_file = $original['sizes']['thumbnail']['file'];
-
- // Request a size by array that doesn't exist and is smaller than the 'thumbnail'
- $image = image_get_intermediate_size( $id, array( 50, 25 ) );
-
- // We should get the 'thumbnail' file as a fallback.
- $this->assertSame( $image['file'], $thumbnail_file );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsimageresizeGdphpfromrev41260trunktestsphpunittestsimageresize_gdphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/image/resizeGd.php (from rev 41260, trunk/tests/phpunit/tests/image/resize_gd.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/resizeGd.php (rev 0)
+++ trunk/tests/phpunit/tests/image/resizeGd.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,37 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group image
+ * @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 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() );
+ }
+
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsimageresizeImagickphpfromrev41260trunktestsphpunittestsimageresize_imagickphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/image/resizeImagick.php (from rev 41260, trunk/tests/phpunit/tests/image/resize_imagick.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/resizeImagick.php (rev 0)
+++ trunk/tests/phpunit/tests/image/resizeImagick.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,25 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group image
+ * @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 function setUp() {
+ require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
+ require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
+
+ parent::setUp();
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunktestsphpunittestsimageresize_gdphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/image/resize_gd.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/resize_gd.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/image/resize_gd.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,37 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group image
- * @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 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() );
- }
-
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsimageresize_imagickphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/image/resize_imagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/resize_imagick.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/image/resize_imagick.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,25 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group image
- * @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 function setUp() {
- require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
- require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
-
- parent::setUp();
- }
-}
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunktestsphpunittestsimagesiteIconphpfromrev41260trunktestsphpunittestsimagesite_iconphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/image/siteIcon.php (from rev 41260, trunk/tests/phpunit/tests/image/site_icon.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/siteIcon.php (rev 0)
+++ trunk/tests/phpunit/tests/image/siteIcon.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,171 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Tests for the WP_Site_Icon class.
+ *
+ * @group site_icon
+ */
+
+require_once( ABSPATH . 'wp-admin/includes/class-wp-site-icon.php' );
+
+class Tests_WP_Site_Icon extends WP_UnitTestCase {
+ protected $wp_site_icon;
+
+ public $attachment_id = 0;
+
+ function setUp() {
+ parent::setUp();
+
+ $this->wp_site_icon = new WP_Site_Icon();
+ }
+
+ function tearDown() {
+ $this->_remove_custom_logo();
+ $this->remove_added_uploads();
+ parent::tearDown();
+ }
+
+ function _remove_custom_logo() {
+ remove_theme_mod( 'custom_logo' );
+ }
+
+ function test_intermediate_image_sizes() {
+ $image_sizes = $this->wp_site_icon->intermediate_image_sizes( array() );
+
+ $sizes = array();
+ foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
+ $sizes[] = 'site_icon-' . $size;
+ }
+
+ $this->assertEquals( $sizes, $image_sizes );
+ }
+
+ function test_intermediate_image_sizes_with_filter() {
+ add_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
+ $image_sizes = $this->wp_site_icon->intermediate_image_sizes( array() );
+
+ $sizes = array();
+ foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
+ $sizes[] = 'site_icon-' . $size;
+ }
+
+ // Is our custom icon size there?
+ $this->assertContains( 'site_icon-321', $image_sizes );
+
+ // All icon sizes should be part of the array, including sizes added through the filter.
+ $this->assertEquals( $sizes, $image_sizes );
+
+ // Remove custom size.
+ unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] );
+ // Remove the filter we added
+ remove_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
+ }
+
+ function test_additional_sizes() {
+ $image_sizes = $this->wp_site_icon->additional_sizes( array() );
+
+ $sizes = array();
+ foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
+ $sizes[ 'site_icon-' . $size ] = array(
+ 'width ' => $size,
+ 'height' => $size,
+ 'crop' => true,
+ );
+ }
+
+ $this->assertEquals( $sizes, $image_sizes );
+ }
+
+ function test_additional_sizes_with_filter() {
+ add_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
+ $image_sizes = $this->wp_site_icon->additional_sizes( array() );
+
+ $sizes = array();
+ foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
+ $sizes[ 'site_icon-' . $size ] = array(
+ 'width ' => $size,
+ 'height' => $size,
+ 'crop' => true,
+ );
+ }
+
+ // Is our custom icon size there?
+ $this->assertArrayHasKey( 'site_icon-321', $image_sizes );
+
+ // All icon sizes should be part of the array, including sizes added through the filter.
+ $this->assertEquals( $sizes, $image_sizes );
+
+ // Remove custom size.
+ unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] );
+ }
+
+ function test_create_attachment_object() {
+ $attachment_id = $this->_insert_attachment();
+ $parent_url = get_post( $attachment_id )->guid;
+ $cropped = str_replace( basename( $parent_url ), 'cropped-test-image.jpg', $parent_url );
+
+ $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id );
+
+ $this->assertEquals( $object['post_title'], 'cropped-test-image.jpg' );
+ $this->assertEquals( $object['context'], 'site-icon' );
+ $this->assertEquals( $object['post_mime_type'], 'image/jpeg' );
+ $this->assertEquals( $object['post_content'], $cropped );
+ $this->assertEquals( $object['guid'], $cropped );
+ }
+
+ function test_insert_cropped_attachment() {
+ $attachment_id = $this->_insert_attachment();
+ $parent_url = get_post( $attachment_id )->guid;
+ $cropped = str_replace( basename( $parent_url ), 'cropped-test-image.jpg', $parent_url );
+
+ $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id );
+ $cropped_id = $this->wp_site_icon->insert_attachment( $object, $cropped );
+
+ $this->assertInternalType( 'int', $cropped_id );
+ $this->assertGreaterThan( 0, $cropped_id );
+ }
+
+ function test_delete_attachment_data() {
+ $attachment_id = $this->_insert_attachment();
+ update_option( 'site_icon', $attachment_id );
+
+ wp_delete_attachment( $attachment_id, true );
+
+ $this->assertFalse( get_option( 'site_icon', false ) );
+ }
+
+ /**
+ * @ticket 34368
+ */
+ function test_get_post_metadata() {
+ $attachment_id = $this->_insert_attachment();
+ update_option( 'site_icon', $attachment_id );
+
+ $this->wp_site_icon->get_post_metadata( '', $attachment_id, '_some_post_meta', true );
+ $this->assertFalse( has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
+
+ $this->wp_site_icon->get_post_metadata( '', $attachment_id, '_wp_attachment_backup_sizes', true );
+ $this->assertSame( 10, has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
+
+ wp_delete_attachment( $attachment_id, true );
+ }
+
+ function _custom_test_sizes( $sizes ) {
+ $sizes[] = 321;
+
+ return $sizes;
+ }
+
+ function _insert_attachment() {
+ if ( $this->attachment_id ) {
+ return $this->attachment_id;
+ }
+
+ $filename = DIR_TESTDATA . '/images/test-image.jpg';
+ $contents = file_get_contents( $filename );
+
+ $upload = wp_upload_bits( basename( $filename ), null, $contents );
+
+ $this->attachment_id = $this->_make_attachment( $upload );
+ return $this->attachment_id;
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsimagesite_iconphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/image/site_icon.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/site_icon.php 2017-08-17 23:36:53 UTC (rev 41260)
+++ trunk/tests/phpunit/tests/image/site_icon.php 2017-08-18 09:57:12 UTC (rev 41261)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,171 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * Tests for the WP_Site_Icon class.
- *
- * @group site_icon
- */
-
-require_once( ABSPATH . 'wp-admin/includes/class-wp-site-icon.php' );
-
-class Tests_WP_Site_Icon extends WP_UnitTestCase {
- protected $wp_site_icon;
-
- public $attachment_id = 0;
-
- function setUp() {
- parent::setUp();
-
- $this->wp_site_icon = new WP_Site_Icon();
- }
-
- function tearDown() {
- $this->_remove_custom_logo();
- $this->remove_added_uploads();
- parent::tearDown();
- }
-
- function _remove_custom_logo() {
- remove_theme_mod( 'custom_logo' );
- }
-
- function test_intermediate_image_sizes() {
- $image_sizes = $this->wp_site_icon->intermediate_image_sizes( array() );
-
- $sizes = array();
- foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
- $sizes[] = 'site_icon-' . $size;
- }
-
- $this->assertEquals( $sizes, $image_sizes );
- }
-
- function test_intermediate_image_sizes_with_filter() {
- add_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
- $image_sizes = $this->wp_site_icon->intermediate_image_sizes( array() );
-
- $sizes = array();
- foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
- $sizes[] = 'site_icon-' . $size;
- }
-
- // Is our custom icon size there?
- $this->assertContains( 'site_icon-321', $image_sizes );
-
- // All icon sizes should be part of the array, including sizes added through the filter.
- $this->assertEquals( $sizes, $image_sizes );
-
- // Remove custom size.
- unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] );
- // Remove the filter we added
- remove_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
- }
-
- function test_additional_sizes() {
- $image_sizes = $this->wp_site_icon->additional_sizes( array() );
-
- $sizes = array();
- foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
- $sizes[ 'site_icon-' . $size ] = array(
- 'width ' => $size,
- 'height' => $size,
- 'crop' => true,
- );
- }
-
- $this->assertEquals( $sizes, $image_sizes );
- }
-
- function test_additional_sizes_with_filter() {
- add_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
- $image_sizes = $this->wp_site_icon->additional_sizes( array() );
-
- $sizes = array();
- foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
- $sizes[ 'site_icon-' . $size ] = array(
- 'width ' => $size,
- 'height' => $size,
- 'crop' => true,
- );
- }
-
- // Is our custom icon size there?
- $this->assertArrayHasKey( 'site_icon-321', $image_sizes );
-
- // All icon sizes should be part of the array, including sizes added through the filter.
- $this->assertEquals( $sizes, $image_sizes );
-
- // Remove custom size.
- unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] );
- }
-
- function test_create_attachment_object() {
- $attachment_id = $this->_insert_attachment();
- $parent_url = get_post( $attachment_id )->guid;
- $cropped = str_replace( basename( $parent_url ), 'cropped-test-image.jpg', $parent_url );
-
- $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id );
-
- $this->assertEquals( $object['post_title'], 'cropped-test-image.jpg' );
- $this->assertEquals( $object['context'], 'site-icon' );
- $this->assertEquals( $object['post_mime_type'], 'image/jpeg' );
- $this->assertEquals( $object['post_content'], $cropped );
- $this->assertEquals( $object['guid'], $cropped );
- }
-
- function test_insert_cropped_attachment() {
- $attachment_id = $this->_insert_attachment();
- $parent_url = get_post( $attachment_id )->guid;
- $cropped = str_replace( basename( $parent_url ), 'cropped-test-image.jpg', $parent_url );
-
- $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id );
- $cropped_id = $this->wp_site_icon->insert_attachment( $object, $cropped );
-
- $this->assertInternalType( 'int', $cropped_id );
- $this->assertGreaterThan( 0, $cropped_id );
- }
-
- function test_delete_attachment_data() {
- $attachment_id = $this->_insert_attachment();
- update_option( 'site_icon', $attachment_id );
-
- wp_delete_attachment( $attachment_id, true );
-
- $this->assertFalse( get_option( 'site_icon', false ) );
- }
-
- /**
- * @ticket 34368
- */
- function test_get_post_metadata() {
- $attachment_id = $this->_insert_attachment();
- update_option( 'site_icon', $attachment_id );
-
- $this->wp_site_icon->get_post_metadata( '', $attachment_id, '_some_post_meta', true );
- $this->assertFalse( has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
-
- $this->wp_site_icon->get_post_metadata( '', $attachment_id, '_wp_attachment_backup_sizes', true );
- $this->assertSame( 10, has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
-
- wp_delete_attachment( $attachment_id, true );
- }
-
- function _custom_test_sizes( $sizes ) {
- $sizes[] = 321;
-
- return $sizes;
- }
-
- function _insert_attachment() {
- if ( $this->attachment_id ) {
- return $this->attachment_id;
- }
-
- $filename = DIR_TESTDATA . '/images/test-image.jpg';
- $contents = file_get_contents( $filename );
-
- $upload = wp_upload_bits( basename( $filename ), null, $contents );
-
- $this->attachment_id = $this->_make_attachment( $upload );
- return $this->attachment_id;
- }
-}
</del></span></pre>
</div>
</div>
</body>
</html>