From 5764d952e7a129f58b19b32a60ebc52bed9c90b8 Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Wed, 18 Jul 2018 16:16:59 -0600
Subject: [PATCH] unit tests that create tmp files should use
 sys_get_temp_dir() instead of hardcoding /tmp/

---
 tests/phpunit/tests/customize/manager.php                    | 4 ++--
 tests/phpunit/tests/rest-api/rest-attachments-controller.php | 4 ++--
 tests/phpunit/tests/widgets/media-gallery-widget.php         | 2 +-
 tests/phpunit/tests/widgets/media-image-widget.php           | 2 +-
 tests/phpunit/tests/widgets/media-widget.php                 | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php
index aad5d1f..4fff28b 100644
--- a/tests/phpunit/tests/customize/manager.php
+++ b/tests/phpunit/tests/customize/manager.php
@@ -60,10 +60,10 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
 		$this->undefined = new stdClass();
 
 		$orig_file       = DIR_TESTDATA . '/images/canola.jpg';
-		$this->test_file = '/tmp/canola.jpg';
+		$this->test_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'canola.jpg';
 		copy( $orig_file, $this->test_file );
 		$orig_file2       = DIR_TESTDATA . '/images/waffles.jpg';
-		$this->test_file2 = '/tmp/waffles.jpg';
+		$this->test_file2 = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'waffles.jpg';
 		copy( $orig_file2, $this->test_file2 );
 	}
 
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
index 2131e03..a73cd80 100644
--- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
@@ -68,10 +68,10 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
 		$role->add_cap( 'level_0' );
 
 		$orig_file       = DIR_TESTDATA . '/images/canola.jpg';
-		$this->test_file = '/tmp/canola.jpg';
+		$this->test_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'canola.jpg';
 		copy( $orig_file, $this->test_file );
 		$orig_file2       = DIR_TESTDATA . '/images/codeispoetry.png';
-		$this->test_file2 = '/tmp/codeispoetry.png';
+		$this->test_file2 = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'codeispoetry.jpg';
 		copy( $orig_file2, $this->test_file2 );
 	}
 
diff --git a/tests/phpunit/tests/widgets/media-gallery-widget.php b/tests/phpunit/tests/widgets/media-gallery-widget.php
index 401a788..aa69612 100644
--- a/tests/phpunit/tests/widgets/media-gallery-widget.php
+++ b/tests/phpunit/tests/widgets/media-gallery-widget.php
@@ -58,7 +58,7 @@ class Test_WP_Widget_Media_Gallery extends WP_UnitTestCase {
 
 		$attachments = array();
 		foreach ( array( 'canola.jpg', 'waffles.jpg' ) as $filename ) {
-			$test_image = '/tmp/' . $filename;
+			$test_image = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
 			copy( DIR_TESTDATA . '/images/canola.jpg', $test_image );
 			$attachment_id = self::factory()->attachment->create_object(
 				array(
diff --git a/tests/phpunit/tests/widgets/media-image-widget.php b/tests/phpunit/tests/widgets/media-image-widget.php
index d534e85..da16ff4 100644
--- a/tests/phpunit/tests/widgets/media-image-widget.php
+++ b/tests/phpunit/tests/widgets/media-image-widget.php
@@ -357,7 +357,7 @@ class Test_WP_Widget_Media_Image extends WP_UnitTestCase {
 	function test_render_media() {
 		$widget = new WP_Widget_Media_Image();
 
-		$test_image = '/tmp/canola.jpg';
+		$test_image = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'canola.jpg';
 		copy( DIR_TESTDATA . '/images/canola.jpg', $test_image );
 		$attachment_id = self::factory()->attachment->create_object(
 			array(
diff --git a/tests/phpunit/tests/widgets/media-widget.php b/tests/phpunit/tests/widgets/media-widget.php
index e165d86..622c62b 100644
--- a/tests/phpunit/tests/widgets/media-widget.php
+++ b/tests/phpunit/tests/widgets/media-widget.php
@@ -137,7 +137,7 @@ class Test_WP_Widget_Media extends WP_UnitTestCase {
 	 */
 	function test_is_attachment_with_mime_type() {
 
-		$test_image = '/tmp/canola.jpg';
+		$test_image = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'canola.jpg';
 		copy( DIR_TESTDATA . '/images/canola.jpg', $test_image );
 		$attachment_id = self::factory()->attachment->create_object(
 			array(
-- 
2.7.0.windows.1

