<!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>[Tests][1123] trunk/tests/image: Fix unit tests for WP_Image_Editor.</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, #logmsg > ol { margin-left: 0; 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">
<dt>Revision</dt> <dd><a href="http://unit-tests.trac.wordpress.org/changeset/1123">1123</a></dd>
<dt>Author</dt> <dd>markoheijnen</dd>
<dt>Date</dt> <dd>2012-11-09 20:19:18 +0000 (Fri, 09 Nov 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix unit tests for WP_Image_Editor. After changes of ticket #WP6821</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsimageeditorphp">trunk/tests/image/editor.php</a></li>
<li><a href="#trunktestsimageresizephp">trunk/tests/image/resize.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsimagebasephp">trunk/tests/image/base.php</a></li>
<li><a href="#trunktestsimageintermediate_sizephp">trunk/tests/image/intermediate_size.php</a></li>
<li><a href="#trunktestsimageresize_gdphp">trunk/tests/image/resize_gd.php</a></li>
<li><a href="#trunktestsimageresize_imagickphp">trunk/tests/image/resize_imagick.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsimagebasephp"></a>
<div class="addfile"><h4>Added: trunk/tests/image/base.php (0 => 1123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/image/base.php                                (rev 0)
+++ trunk/tests/image/base.php        2012-11-09 20:19:18 UTC (rev 1123)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+&lt;?php
+
+/**
+ * @group image
+ */
+abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
+
+        /**
+         * Set the image editor engine according to the unit test's specification
+         */
+        public function setUp() {
+                $class = $this-&gt;editor_engine;
+                if ( ! call_user_func( array( $class, 'test' ) ) ) {
+                        $this-&gt;markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this-&gt;eitor_engine) );
+                }
+                add_filter( 'image_editor_class', array( $this, 'setEngine') );
+        }
+        
+        /**
+         * Undo the image editor override
+         */
+        public function tearDown() {
+                remove_filter( 'image_editor_class', array( $this, 'setEngine' ) );
+        }
+
+        /**
+         * Override the image editor engine
+         * @return string
+         */
+        public function setEngine() {
+                return $this-&gt;editor_engine;
+        }        
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunktestsimageeditorphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/image/editor.php (1122 => 1123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/image/editor.php        2012-11-09 15:43:44 UTC (rev 1122)
+++ trunk/tests/image/editor.php        2012-11-09 20:19:18 UTC (rev 1123)
</span><span class="lines">@@ -32,37 +32,24 @@
</span><span class="cx">                 ), $className, false );
</span><span class="cx"> 
</span><span class="cx">                 // Override the filters to set our own image editor
</span><del>-                add_filter( 'image_editor_class', array( $this, 'image_editor_class' ) );
-                add_filter( 'wp_editors', array( $this, 'wp_editors' ) );
-
-                // Un-cache the chosen image implementation
-                $this-&gt;_uncache_implementation();
</del><ins>+                add_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) );
+                add_filter( 'wp_image_editors', array( $this, 'wp_editors' ) );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * Tear down test fixture
</span><span class="cx">          */
</span><span class="cx">         public function tearDown() {
</span><del>-                remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) );
-                remove_filter( 'wp_editors', array( $this, 'wp_editors' ) );
</del><ins>+                remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) );
+                remove_filter( 'wp_image_editors', array( $this, 'wp_editors' ) );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Unset the static implementation cache
-         */
-        protected function _uncache_implementation() {
-                $class = new ReflectionClass( 'WP_Image_Editor' );
-                $var = $class-&gt;getProperty( 'implementation' );
-                $var-&gt;setAccessible( true );
-                $var-&gt;setValue( $class, null );
-        }
-
-        /**
</del><span class="cx">          * Override the wp_editors filter
</span><span class="cx">          * @return array
</span><span class="cx">          */
</span><span class="cx">         public function wp_editors() {
</span><del>-                return array( preg_replace('/^WP_Image_Editor_/', '', get_class( $this-&gt;editor ) ) );
</del><ins>+                return array( get_class( $this-&gt;editor ) );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -81,8 +68,8 @@
</span><span class="cx"> 
</span><span class="cx">                 // Swap out the PHPUnit mock with our custom mock
</span><span class="cx">                 $func = create_function( '', 'return &quot;WP_Image_Editor_Mock&quot;;');
</span><del>-                remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) );
-                add_filter( 'image_editor_class', $func );
</del><ins>+                remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) );
+                add_filter( 'wp_image_editor_class', $func );
</ins><span class="cx"> 
</span><span class="cx">                 // Set load() to return true
</span><span class="cx">                 WP_Image_Editor_Mock::$load_return = true;
</span><span class="lines">@@ -94,7 +81,7 @@
</span><span class="cx">                 $this-&gt;assertInstanceOf( 'WP_Image_Editor_Mock', $editor );
</span><span class="cx"> 
</span><span class="cx">                 // Remove our custom Mock
</span><del>-                remove_filter( 'image_editor_class', $func );
</del><ins>+                remove_filter( 'wp_image_editor_class', $func );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -105,8 +92,8 @@
</span><span class="cx"> 
</span><span class="cx">                 // Swap out the PHPUnit mock with our custom mock
</span><span class="cx">                 $func = create_function( '', 'return &quot;WP_Image_Editor_Mock&quot;;');
</span><del>-                remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) );
-                add_filter( 'image_editor_class', $func );
</del><ins>+                remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) );
+                add_filter( 'wp_image_editor_class', $func );
</ins><span class="cx"> 
</span><span class="cx">                 // Set load() to return true
</span><span class="cx">                 WP_Image_Editor_Mock::$load_return = new WP_Error();
</span><span class="lines">@@ -118,58 +105,10 @@
</span><span class="cx">                 $this-&gt;assertInstanceOf( 'WP_Error', $editor );
</span><span class="cx"> 
</span><span class="cx">                 // Remove our custom Mock
</span><del>-                remove_filter( 'image_editor_class', $func );
</del><ins>+                remove_filter( 'wp_image_editor_class', $func );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Test the &quot;test&quot; method
-         * @ticket 6821
-         */
-        public function test_test_returns_true() {
-
-                // $editor::test() returns true
-                $this-&gt;editor-&gt;staticExpects( $this-&gt;once() )
-                                     -&gt;method( 'test' )
-                                     -&gt;will( $this-&gt;returnValue( true ) );
-
-                // Load an image
-                $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );
-
-                // Everything should work
-                $this-&gt;assertInstanceOf( get_class( $this-&gt;editor ), $editor );
-        }
-
-        /**
-         * Test the &quot;test&quot; method returns false and the fallback editor is chosen
-         * @ticket 6821
-         */
-        public function test_test_returns_false() {
-
-                // $editor::test() returns true
-                $this-&gt;editor-&gt;staticExpects( $this-&gt;once() )
-                                     -&gt;method( 'test' )
-                                     -&gt;will( $this-&gt;returnValue( false ) );
-
-                // Set a fallback editor
-                $className = preg_replace('/^WP_Image_Editor_/', '', get_class( $this-&gt;editor ) );
-                $func = create_function( '', &quot;return array('$className', 'Mock');&quot; );
-                remove_filter( 'wp_editors', array( $this, 'wp_editors' ) );
-                remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) );
-                add_filter( 'wp_editors', $func );
-
-                // Load an image
-                WP_Image_Editor_Mock::$load_return = true;
-                $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );
-
-                // Everything should work
-                $this-&gt;assertInstanceOf( 'WP_Image_Editor_Mock', $editor );
-
-                // Unhook
-                remove_filter( 'image_editor_class', '__return_null' );
-                remove_filter( 'wp_editors', $func );
-        }
-
-        /**
</del><span class="cx">          * Test test_quality
</span><span class="cx">          * @ticket 6821
</span><span class="cx">          */
</span><span class="lines">@@ -255,7 +194,6 @@
</span><span class="cx">          * @ticket 6821
</span><span class="cx">          */
</span><span class="cx">         public function test_get_suffix() {
</span><del>-
</del><span class="cx">                 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );
</span><span class="cx"> 
</span><span class="cx">                 // Size should be false by default
</span></span></pre></div>
<a id="trunktestsimageintermediate_sizephp"></a>
<div class="addfile"><h4>Added: trunk/tests/image/intermediate_size.php (0 => 1123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/image/intermediate_size.php                                (rev 0)
+++ trunk/tests/image/intermediate_size.php        2012-11-09 20:19:18 UTC (rev 1123)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+&lt;?php
+
+/**
+ * @group image
+ * @group media
+ * @group upload
+ */
+class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
+        function test_make_intermediate_size_no_size() {
+                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
+
+                $this-&gt;assertFalse( $image );
+        }
+
+        function test_make_intermediate_size_width() {
+                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 0, false );
+
+                $this-&gt;assertInternalType( 'array', $image );
+        }
+
+        function test_make_intermediate_size_height() {
+                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 75, false );
+
+                $this-&gt;assertInternalType( 'array', $image );
+        }
+
+        function test_make_intermediate_size_successful() {
+                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 75, true );
+
+                $this-&gt;assertInternalType( 'array', $image );
+                $this-&gt;assertEquals( 100, $image['width'] );
+                $this-&gt;assertEquals( 75, $image['height'] );
+                $this-&gt;assertEquals( 'image/jpeg', $image['mime-type'] );
+
+                $this-&gt;assertFalse( isset( $image['path'] ) );
+        }
+}
</ins></span></pre></div>
<a id="trunktestsimageresizephp"></a>
<div class="modfile"><h4>Modified: trunk/tests/image/resize.php (1122 => 1123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/image/resize.php        2012-11-09 15:43:44 UTC (rev 1122)
+++ trunk/tests/image/resize.php        2012-11-09 20:19:18 UTC (rev 1123)
</span><span class="lines">@@ -5,15 +5,9 @@
</span><span class="cx">  * @group media
</span><span class="cx">  * @group upload
</span><span class="cx">  */
</span><del>-class Tests_Image_Resize extends WP_UnitTestCase {
</del><ins>+abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase {
</ins><span class="cx">         // image_resize( $file, $max_w, $max_h, $crop=false, $suffix=null, $dest_path=null, $jpeg_quality=75)
</span><span class="cx"> 
</span><del>-        function setUp() {
-                if ( ! extension_loaded( 'gd' ) )
-                        $this-&gt;markTestSkipped( 'The gd PHP extension is not loaded.' );
-                parent::setUp();
-        }
-
</del><span class="cx">         function test_resize_jpg() {
</span><span class="cx">                 $image = image_resize( DIR_TESTDATA.'/images/test-image.jpg', 25, 25 );
</span><span class="cx">                 $this-&gt;assertEquals( 'test-image-25x25.jpg', basename($image) );
</span><span class="lines">@@ -128,17 +122,9 @@
</span><span class="cx">          * @ticket 6821
</span><span class="cx">          */
</span><span class="cx">         public function test_resize_non_existent_image() {
</span><del>-                $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick');
-                foreach ( $classes as $class ) {
-                        if ( ! call_user_func( array( $class, 'test' ) ) ) {
-                                continue;
-                        }
-                        $filter = create_function( '', &quot;return '$class';&quot; );
-                        add_filter( 'image_editor_class', $filter );
-                        $image = image_resize( DIR_TESTDATA.'/images/test-non-existent-image.jpg', 25, 25 );
-                        $this-&gt;assertInstanceOf( 'WP_Error', $image );
-                        $this-&gt;assertEquals( 'error_loading_image', $image-&gt;get_error_code() );
-                }
</del><ins>+                $image = image_resize( DIR_TESTDATA.'/images/test-non-existent-image.jpg', 25, 25 );
+                $this-&gt;assertInstanceOf( 'WP_Error', $image );
+                $this-&gt;assertEquals( 'error_loading_image', $image-&gt;get_error_code() );
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         /**
</span><span class="lines">@@ -146,16 +132,8 @@
</span><span class="cx">          * @ticket 6821
</span><span class="cx">          */
</span><span class="cx">         public function test_resize_bad_image() {
</span><del>-                $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick');
-                foreach ( $classes as $class ) {
-                        if ( ! call_user_func( array( $class, 'test' ) ) ) {
-                                continue;
-                        }
-                        $filter = create_function( '', &quot;return '$class';&quot; );
-                        add_filter( 'image_editor_class', $filter );
-                        $image = image_resize( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
-                        $this-&gt;assertInstanceOf( 'WP_Error', $image );
-                        $this-&gt;assertEquals( 'invalid_image', $image-&gt;get_error_code() );
-                }
</del><ins>+                $image = image_resize( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
+                $this-&gt;assertInstanceOf( 'WP_Error', $image );
+                $this-&gt;assertEquals( 'invalid_image', $image-&gt;get_error_code() );
</ins><span class="cx">         }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunktestsimageresize_gdphp"></a>
<div class="addfile"><h4>Added: trunk/tests/image/resize_gd.php (0 => 1123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/image/resize_gd.php                                (rev 0)
+++ trunk/tests/image/resize_gd.php        2012-11-09 20:19:18 UTC (rev 1123)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+&lt;?php
+
+/**
+ * @group image
+ * @group media
+ * @group upload
+ */
+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';
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunktestsimageresize_imagickphp"></a>
<div class="addfile"><h4>Added: trunk/tests/image/resize_imagick.php (0 => 1123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/image/resize_imagick.php                                (rev 0)
+++ trunk/tests/image/resize_imagick.php        2012-11-09 20:19:18 UTC (rev 1123)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+&lt;?php
+
+/**
+ * @group image
+ * @group media
+ * @group upload
+ */
+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';
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>