Changeset 29120
- Timestamp:
- 07/12/2014 07:08:15 AM (10 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r28943 r29120 12 12 protected $caught_doing_it_wrong = array(); 13 13 14 protected static $ignore_files; 15 14 16 /** 15 17 * @var WP_UnitTest_Factory … … 19 21 function setUp() { 20 22 set_time_limit(0); 23 24 if ( ! self::$ignore_files ) { 25 self::$ignore_files = $this->scan_user_uploads(); 26 } 21 27 22 28 global $wpdb; … … 326 332 $this->assertTrue( $passed, $message ); 327 333 } 334 335 function unlink( $file ) { 336 $exists = is_file( $file ); 337 if ( $exists && ! in_array( $file, self::$ignore_files ) ) { 338 //error_log( $file ); 339 unlink( $file ); 340 } elseif ( ! $exists ) { 341 $this->fail( "Trying to delete a file that doesn't exist: $file" ); 342 } 343 } 344 345 function rmdir( $path ) { 346 $files = $this->files_in_dir( $path ); 347 foreach ( $files as $file ) { 348 if ( ! in_array( $file, self::$ignore_files ) ) { 349 $this->unlink( $file ); 350 } 351 } 352 } 353 354 function remove_added_uploads() { 355 // Remove all uploads. 356 $uploads = wp_upload_dir(); 357 $this->rmdir( $uploads['basedir'] ); 358 } 359 360 function files_in_dir( $dir ) { 361 $files = array(); 362 363 $iterator = new RecursiveDirectoryIterator( $dir ); 364 $objects = new RecursiveIteratorIterator( $iterator ); 365 foreach ( $objects as $name => $object ) { 366 if ( is_file( $name ) ) { 367 $files[] = $name; 368 } 369 } 370 371 return $files; 372 } 373 374 function scan_user_uploads() { 375 static $files = array(); 376 if ( ! empty( $files ) ) { 377 return $files; 378 } 379 380 $uploads = wp_upload_dir(); 381 $files = $this->files_in_dir( $uploads['basedir'] ); 382 return $files; 383 } 328 384 } -
trunk/tests/phpunit/includes/utils.php
r28797 r29120 314 314 } 315 315 316 function _rmdir( $path ) {317 if ( in_array(basename( $path ), array( '.', '..' ) ) ) {318 return;319 } elseif ( is_file( $path ) ) {320 unlink( $path );321 } elseif ( is_dir( $path ) ) {322 foreach ( scandir( $path ) as $file )323 _rmdir( $path . '/' . $file );324 rmdir( $path );325 }326 }327 328 316 /** 329 317 * Removes the post type and its taxonomy associations. -
trunk/tests/phpunit/tests/ajax/MediaEdit.php
r26088 r29120 33 33 public function tearDown() { 34 34 // Cleanup 35 foreach ( $this->_ids as $id){36 wp_delete_attachment( $id, true);35 foreach ( $this->_ids as $id ) { 36 wp_delete_attachment( $id, true ); 37 37 } 38 39 $uploads = wp_upload_dir();40 foreach ( scandir( $uploads['basedir'] ) as $file )41 _rmdir( $uploads['basedir'] . '/' . $file );42 38 43 39 parent::tearDown(); -
trunk/tests/phpunit/tests/functions/deprecated.php
r25409 r29120 149 149 wp_save_image_file( $file, $img, 'image/jpeg', 1 ); 150 150 imagedestroy( $img ); 151 @unlink($file);151 unlink( $file ); 152 152 153 153 // Check if the arg was deprecated … … 170 170 wp_save_image_file( $file, $img, 'image/jpeg', 1 ); 171 171 unset( $img ); 172 @unlink($file);172 unlink( $file ); 173 173 174 174 // Check if the arg was deprecated -
trunk/tests/phpunit/tests/http/base.php
r25224 r29120 285 285 $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) ); 286 286 } 287 288 287 288 289 289 } -
trunk/tests/phpunit/tests/image/base.php
r27794 r29120 10 10 */ 11 11 public function setUp() { 12 parent::setUp(); 13 12 14 if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) { 13 15 $this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) ); … … 21 23 */ 22 24 public function tearDown() { 25 parent::tearDown(); 26 23 27 remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 ); 24 28 } … … 34 38 /** 35 39 * Helper assertion for testing alpha on images 36 * 40 * 37 41 * @param string $image_path 38 42 * @param array $point array(x,y) -
trunk/tests/phpunit/tests/image/editor_gd.php
r27794 r29120 7 7 * @group wp-image-editor-gd 8 8 */ 9 require_once( dirname( __FILE__ ) . '/base.php' ); 9 10 10 11 class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { … … 19 20 } 20 21 21 public function shutDown() {22 public function tearDown() { 22 23 $folder = DIR_TESTDATA . '/images/waffles-*.jpg'; 23 24 … … 26 27 } 27 28 28 parent::shutDown(); 29 $this->remove_added_uploads(); 30 31 parent::tearDown(); 29 32 } 30 33 … … 468 471 469 472 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 473 474 unlink( $save_to_file ); 470 475 } 471 476 … … 486 491 487 492 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 493 494 unlink( $save_to_file ); 488 495 } 489 496 } -
trunk/tests/phpunit/tests/image/editor_imagick.php
r27794 r29120 7 7 * @group wp-image-editor-imagick 8 8 */ 9 require_once( dirname( __FILE__ ) . '/base.php' ); 9 10 10 11 class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { … … 19 20 } 20 21 21 public function shutDown() {22 public function tearDown() { 22 23 $folder = DIR_TESTDATA . '/images/waffles-*.jpg'; 23 24 … … 26 27 } 27 28 28 parent::shutDown(); 29 $this->remove_added_uploads(); 30 31 parent::tearDown(); 29 32 } 30 33 … … 464 467 $editor->resize( 5, 5 ); 465 468 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 466 469 467 470 $editor->save( $save_to_file ); 468 471 469 472 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 473 474 unlink( $save_to_file ); 470 475 } 471 476 … … 486 491 487 492 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 493 494 unlink( $save_to_file ); 488 495 } 489 496 } -
trunk/tests/phpunit/tests/image/functions.php
r28603 r29120 89 89 $files = array( 90 90 // 'test-image-cmyk.jpg', Allowed in r9727 91 // 'test-image.bmp', Allowed in r28589 91 // 'test-image.bmp', Allowed in r28589 92 92 // 'test-image-grayscale.jpg', Allowed in r9727 93 93 'test-image.pct', … … 145 145 146 146 // Clean up 147 @unlink( $file );148 @unlink( $ret['path'] );147 unlink( $file ); 148 unlink( $ret['path'] ); 149 149 } 150 150 … … 186 186 187 187 // Clean up 188 @unlink( $file );189 @unlink( $ret['path'] );188 unlink( $file ); 189 unlink( $ret['path'] ); 190 190 unset( $img ); 191 191 } … … 232 232 $this->assertNotInstanceOf( 'WP_Error', $ret ); 233 233 $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); 234 @unlink( $file ); 235 @unlink( $ret['path'] ); 234 unlink( $ret['path'] ); 236 235 } 237 236 -
trunk/tests/phpunit/tests/image/intermediate_size.php
r25507 r29120 1 1 <?php 2 3 2 /** 4 3 * @group image … … 7 6 */ 8 7 class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 8 function tearDown() { 9 $this->remove_added_uploads(); 10 parent::tearDown(); 11 } 12 9 13 function test_make_intermediate_size_no_size() { 10 14 $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false ); -
trunk/tests/phpunit/tests/image/resize.php
r25002 r29120 5 5 * @group media 6 6 * @group upload 7 * @group resize 7 8 */ 9 require_once( dirname( __FILE__ ) . '/base.php' ); 10 8 11 abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase { 9 12 … … 109 112 $this->assertEquals( IMAGETYPE_JPEG, $type ); 110 113 111 unlink( $image);114 unlink( $image ); 112 115 } 113 116 -
trunk/tests/phpunit/tests/image/resize_gd.php
r25002 r29120 5 5 * @group media 6 6 * @group upload 7 * @group resize 7 8 */ 9 require_once( dirname( __FILE__ ) . '/resize.php' ); 10 8 11 class Test_Image_Resize_GD extends WP_Tests_Image_Resize_UnitTestCase { 9 12 … … 13 16 */ 14 17 public $editor_engine = 'WP_Image_Editor_GD'; 18 19 public function setUp() { 20 require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 21 require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' ); 22 23 parent::setUp(); 24 } 15 25 } -
trunk/tests/phpunit/tests/image/resize_imagick.php
r25002 r29120 5 5 * @group media 6 6 * @group upload 7 * @group resize 7 8 */ 9 require_once( dirname( __FILE__ ) . '/resize.php' ); 10 8 11 class Test_Image_Resize_Imagick extends WP_Tests_Image_Resize_UnitTestCase { 9 12 … … 13 16 */ 14 17 public $editor_engine = 'WP_Image_Editor_Imagick'; 18 19 public function setUp() { 20 require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 21 require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' ); 22 23 parent::setUp(); 24 } 15 25 } -
trunk/tests/phpunit/tests/post/attachments.php
r28788 r29120 10 10 function tearDown() { 11 11 // Remove all uploads. 12 $uploads = wp_upload_dir(); 13 foreach ( scandir( $uploads['basedir'] ) as $file ) 14 _rmdir( $uploads['basedir'] . '/' . $file ); 15 12 $this->remove_added_uploads(); 16 13 parent::tearDown(); 17 14 } -
trunk/tests/phpunit/tests/upload.php
r26552 r29120 23 23 24 24 function tearDown() { 25 $this->remove_added_uploads(); 26 25 27 parent::tearDown(); 26 27 // Remove year/month folders created by wp_upload_dir().28 $uploads = wp_upload_dir();29 foreach ( scandir( $uploads['basedir'] ) as $file )30 _rmdir( $uploads['basedir'] . '/' . $file );31 _rmdir( ABSPATH . 'foo/' );32 28 } 33 29
Note: See TracChangeset
for help on using the changeset viewer.