<!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>[49230] trunk: Media: Support Stream Wrappers In `WP_Image_Editor_Imagick`</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 { white-space: pre-line; 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/49230">49230</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/49230","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>mikeschroder</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-10-20 14:35:10 +0000 (Tue, 20 Oct 2020)</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'>Media: Support Stream Wrappers In `WP_Image_Editor_Imagick`

Since `WP_Image_Editor`'s introduction, stream wrappers have functioned in `WP_Image_Editor_GD`, but haven't been properly supported in `WP_Image_Editor_Imagick`.

- Detects stream wrappers and uses `file_put_contents()` along with `Imagick::read/getImageBlob()` for handling when necessary.
- Introduces private method, `WP_Image_Editor_Imagick::write_image` to handle detection and proper saving.
- Introduces `WP_Test_Stream` class for testing stream wrappers, along with new tests for Imagick's stream handling and a stream filename test.

Adds requirement for `Imagick::readImageBlob()`, available in Imagick >= 2.0.0, which aligns with the current requirement of Imagick >= 2.2.0.

Props p00ya, calin, joemcgill, pputzer, jimyaghi, mikeschroder.
Fixes <a href="https://core.trac.wordpress.org/ticket/42663">#42663</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpimageeditorimagickphp">trunk/src/wp-includes/class-wp-image-editor-imagick.php</a></li>
<li><a href="#trunksrcwpincludesclasswpimageeditorphp">trunk/src/wp-includes/class-wp-image-editor.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditorphp">trunk/tests/phpunit/tests/image/editor.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditorImagickphp">trunk/tests/phpunit/tests/image/editorImagick.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunitincludesclasswpteststreamphp">trunk/tests/phpunit/includes/class-wp-test-stream.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpimageeditorimagickphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-image-editor-imagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-image-editor-imagick.php   2020-10-20 14:16:27 UTC (rev 49229)
+++ trunk/src/wp-includes/class-wp-image-editor-imagick.php     2020-10-20 14:35:10 UTC (rev 49230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,6 +71,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'flipimage',
</span><span class="cx" style="display: block; padding: 0 10px">                        'flopimage',
</span><span class="cx" style="display: block; padding: 0 10px">                        'readimage',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'readimageblob',
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Now, test for deep requirements within Imagick.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -127,7 +128,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return true;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! is_file( $this->file ) && ! wp_is_stream( $this->file ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return new WP_Error( 'error_loading_image', __( 'File doesn&#8217;t exist?' ), $this->file );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -148,7 +149,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        return $pdf_loaded;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $this->image->readImage( $this->file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( wp_is_stream( $this->file ) ) {
+                                       // Due to reports of issues with streams with `Imagick::readImageFile()`, uses `Imagick::readImageBlob()` instead.
+                                       $this->image->readImageBlob( file_get_contents( $this->file ), $this->file );
+                               } else {
+                                       $this->image->readImage( $this->file );
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! $this->image->valid() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -682,8 +688,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $orig_format = $this->image->getImageFormat();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         } catch ( Exception $e ) {
+                       return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $write_image_result = $this->write_image( $this->image, $filename );
+               if ( is_wp_error( $write_image_result ) ) {
+                       return $write_image_result;
+               }
+
+               try {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Reset original format.
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->image->setImageFormat( $orig_format );
</span><span class="cx" style="display: block; padding: 0 10px">                } catch ( Exception $e ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -706,6 +720,37 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Writes an image to a file or stream.
+        *
+        * @since 5.6
+        *
+        * @param Imagick $image
+        * @param string  $filename The destination filename or stream URL.
+        *
+        * @return true|WP_Error
+        */
+       private function write_image( $image, $filename ) {
+               if ( wp_is_stream( $filename ) ) {
+                       /*
+                        * Due to reports of issues with streams with `Imagick::writeImageFile()` and `Imagick::writeImage()`, copies the blob instead.
+                        * Checks for exact type due to: https://www.php.net/manual/en/function.file-put-contents.php
+                        */
+                       if ( file_put_contents( $filename, $image->getImageBlob() ) === false ) {
+                               /* translators: %s: PHP function name. */
+                               return new WP_Error( 'image_save_error', sprintf( __( '%s failed while writing image to stream.' ), '<code>file_put_contents()</code>' ), $filename );
+                       } else {
+                               return true;
+                       }
+               } else {
+                       try {
+                               return $image->writeImage( $filename );
+                       } catch ( Exception $e ) {
+                               return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
+                       }
+               }
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Streams current image to browser.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 3.5.0
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpimageeditorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-image-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-image-editor.php   2020-10-20 14:16:27 UTC (rev 49229)
+++ trunk/src/wp-includes/class-wp-image-editor.php     2020-10-20 14:35:10 UTC (rev 49230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -365,9 +365,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $new_ext = strtolower( $extension ? $extension : $ext );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! is_null( $dest_path ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $_dest_path = realpath( $dest_path );
-                       if ( $_dest_path ) {
-                               $dir = $_dest_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( ! wp_is_stream( $dest_path ) ) {
+                               $_dest_path = realpath( $dest_path );
+                               if ( $_dest_path ) {
+                                       $dir = $_dest_path;
+                               }
+                       } else {
+                               $dir = $dest_path;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunitincludesclasswpteststreamphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/includes/class-wp-test-stream.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/class-wp-test-stream.php                             (rev 0)
+++ trunk/tests/phpunit/includes/class-wp-test-stream.php       2020-10-20 14:35:10 UTC (rev 49230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,248 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Class WP_Test_Stream.
+ *
+ * An in-memory streamWrapper implementation for testing streams.  Writes to a
+ * stream URL like "protocol://bucket/foo" will be stored in the static
+ * variable WP_Test_Stream::$data['bucket']['/foo'].
+ *
+ * Creating a directory at "protocol://bucket/foo" will store the string
+ * 'DIRECTORY' to the static variable WP_Test_Stream::$data['bucket']['/foo/']
+ * (note the trailing slash).
+ *
+ * This class can be used to test that code works with basic read/write streams,
+ * as such, operations such as seeking are not supported.
+ *
+ * This class does not register itself as a stream handler: test fixtures
+ * should make the appropriate call to stream_wrapper_register().
+ */
+class WP_Test_Stream {
+       const FILE_MODE      = 0100666;
+       const DIRECTORY_MODE = 040777;
+
+       /**
+        * In-memory storage for files and directories simulated by this wrapper.
+        */
+       static $data = array();
+
+       var $position;
+       var $file;
+       var $bucket;
+       var $data_ref;
+
+       /**
+        * Initializes internal state for reading the given URL.
+        *
+        * @param string $url A URL of the form "protocol://bucket/path".
+        */
+       private function open( $url ) {
+               $components = array_merge(
+                       array(
+                               'host' => '',
+                               'path' => '',
+                       ),
+                       parse_url( $url )
+               );
+
+               $this->bucket = $components['host'];
+               $this->file   = $components['path'] ? $components['path'] : '/';
+
+               if ( empty( $this->bucket ) ) {
+                       trigger_error( 'Cannot use an empty bucket name', E_USER_ERROR );
+               }
+
+               if ( ! isset( WP_Test_Stream::$data[ $this->bucket ] ) ) {
+                       WP_Test_Stream::$data[ $this->bucket ] = array();
+               }
+
+               $this->data_ref =& WP_Test_Stream::$data[ $this->bucket ][ $this->file ];
+
+               $this->position = 0;
+       }
+
+       /**
+        * Opens a URL.
+        *
+        * @see streamWrapper::stream_open
+        */
+       function stream_open( $path, $mode, $options, &$opened_path ) {
+               $this->open( $path );
+               return true;
+       }
+
+       /**
+        * Reads from a stream.
+        *
+        * @see streamWrapper::stream_read
+        */
+       function stream_read( $count ) {
+               if ( ! isset( $this->data_ref ) ) {
+                       return '';
+               }
+
+               $ret = substr( $this->data_ref, $this->position, $count );
+
+               $this->position += strlen( $ret );
+               return $ret;
+       }
+
+       /**
+        * Writes to a stream.
+        *
+        * @see streamWrapper::stream_write
+        */
+       function stream_write( $data ) {
+               if ( ! isset( $this->data_ref ) ) {
+                       $this->data_ref = '';
+               }
+
+               $left  = substr( $this->data_ref, 0, $this->position );
+               $right = substr( $this->data_ref, $this->position + strlen( $data ) );
+
+               WP_Test_Stream::$data[ $this->bucket ][ $this->file ] = $left . $data . $right;
+
+               $this->position += strlen( $data );
+               return strlen( $data );
+       }
+
+       /**
+        * Retrieves the current position of a stream.
+        *
+        * @see streamWrapper::stream_tell
+        */
+       function stream_tell() {
+               return $this->position;
+       }
+
+       /**
+        * Tests for end-of-file.
+        *
+        * @see streamWrapper::stream_eof
+        */
+       function stream_eof() {
+               if ( ! isset( $this->data_ref ) ) {
+                       return true;
+               }
+
+               return $this->position >= strlen( $this->data_ref );
+       }
+
+       /**
+        * Change stream metadata.
+        *
+        * @see streamWrapper::stream_metadata
+        */
+       function stream_metadata( $path, $option, $var ) {
+               $this->open( $path );
+               if ( STREAM_META_TOUCH === $option ) {
+                       if ( ! isset( $this->data_ref ) ) {
+                               $this->data_ref = '';
+                       }
+                       return true;
+               }
+               return false;
+       }
+
+       /**
+        * Creates a directory.
+        *
+        * @see streamWrapper::mkdir
+        */
+       function mkdir( $path, $mode, $options ) {
+               $this->open( $path );
+               $plainfile = rtrim( $this->file, '/' );
+
+               if ( isset( WP_Test_Stream::$data[ $this->bucket ][ $file ] ) ) {
+                       return false;
+               }
+               $dir_ref = & $this->get_directory_ref();
+               $dir_ref = 'DIRECTORY';
+               return true;
+       }
+
+       /**
+        * Creates a file metadata object, with defaults.
+        *
+        * @param array $stats Partial file metadata.
+        * @return array Complete file metadata.
+        */
+       private function make_stat( $stats ) {
+               $defaults = array(
+                       'dev'     => 0,
+                       'ino'     => 0,
+                       'mode'    => 0,
+                       'nlink'   => 0,
+                       'uid'     => 0,
+                       'gid'     => 0,
+                       'rdev'    => 0,
+                       'size'    => 0,
+                       'atime'   => 0,
+                       'mtime'   => 0,
+                       'ctime'   => 0,
+                       'blksize' => 0,
+                       'blocks'  => 0,
+               );
+
+               return array_merge( $defaults, $stats );
+       }
+
+       /**
+        * Retrieves information about a file.
+        *
+        * @see streamWrapper::stream_stat
+        */
+       public function stream_stat() {
+               $dir_ref = & $this->get_directory_ref();
+               if ( substr( $this->file, -1 ) === '/' || isset( $dir_ref ) ) {
+                       return $this->make_stat(
+                               array(
+                                       'mode' => WP_Test_Stream::DIRECTORY_MODE,
+                               )
+                       );
+               }
+
+               if ( ! isset( $this->data_ref ) ) {
+                       return false;
+               }
+
+               return $this->make_stat(
+                       array(
+                               'size' => strlen( $this->data_ref ),
+                               'mode' => WP_Test_Stream::FILE_MODE,
+                       )
+               );
+       }
+
+       /**
+        * Retrieves information about a file.
+        *
+        * @see streamWrapper::url_stat
+        */
+       public function url_stat( $path, $flags ) {
+               $this->open( $path );
+               return $this->stream_stat();
+       }
+
+       /**
+        * Deletes a file.
+        *
+        * @see streamWrapper::unlink
+        */
+       public function unlink( $path ) {
+               if ( ! isset( $this->data_ref ) ) {
+                       return false;
+               }
+               unset( WP_Test_Stream::$data[ $this->bucket ][ $this->file ] );
+               return true;
+       }
+
+       /**
+        * Interprets this stream's path as a directory, and returns the entry.
+        *
+        * @return A reference to the data entry for the directory.
+        */
+       private function &get_directory_ref() {
+               return WP_Test_Stream::$data[ $this->bucket ][ rtrim( $this->file, '/' ) . '/' ];
+       }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsimageeditorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editor.php        2020-10-20 14:16:27 UTC (rev 49229)
+++ trunk/tests/phpunit/tests/image/editor.php  2020-10-20 14:35:10 UTC (rev 49230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -143,6 +143,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Combo!
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // Test with a stream destination.
+               $this->assertSame( 'file://testing/path/canola-100x50.jpg', $editor->generate_filename( null, 'file://testing/path' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunktestsphpunittestsimageeditorImagickphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/editorImagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editorImagick.php 2020-10-20 14:16:27 UTC (rev 49229)
+++ trunk/tests/phpunit/tests/image/editorImagick.php   2020-10-20 14:35:10 UTC (rev 49230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,6 +16,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function setUp() {
</span><span class="cx" style="display: block; padding: 0 10px">                require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
</span><span class="cx" style="display: block; padding: 0 10px">                require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                parent::setUp();
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -574,4 +575,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">                unlink( $ret['path'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * Test that images can be loaded and written over streams
+        */
+       public function test_streams() {
+               stream_wrapper_register( 'wptest', 'WP_Test_Stream' );
+               WP_Test_Stream::$data = array(
+                       'Tests_Image_Editor_Imagick' => array(
+                               '/read.jpg' => file_get_contents( DIR_TESTDATA . '/images/waffles.jpg' ),
+                       ),
+               );
+
+               $file                 = 'wptest://Tests_Image_Editor_Imagick/read.jpg';
+               $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
+
+               $ret = $imagick_image_editor->load();
+               $this->assertNotWPError( $ret );
+
+               $temp_file = 'wptest://Tests_Image_Editor_Imagick/write.jpg';
+
+               $ret = $imagick_image_editor->save( $temp_file );
+               $this->assertNotWPError( $ret );
+
+               $this->assertSame( $temp_file, $ret['path'] );
+
+               if ( $temp_file !== $ret['path'] ) {
+                       unlink( $ret['path'] );
+               }
+               unlink( $temp_file );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>