mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root. see #25088. git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
149
tests/phpunit/tests/image/editor.php
Normal file
149
tests/phpunit/tests/image/editor.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test the WP_Image_Editor base class
|
||||
* @group image
|
||||
* @group media
|
||||
*/
|
||||
class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||
public $editor_engine = 'WP_Image_Editor_Mock';
|
||||
|
||||
/**
|
||||
* Setup test fixture
|
||||
*/
|
||||
public function setup() {
|
||||
require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
|
||||
|
||||
include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' );
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wp_get_image_editor() where load returns true
|
||||
* @ticket 6821
|
||||
*/
|
||||
public function test_get_editor_load_returns_true() {
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
$this->assertInstanceOf( 'WP_Image_Editor_Mock', $editor );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wp_get_image_editor() where load returns false
|
||||
* @ticket 6821
|
||||
*/
|
||||
public function test_get_editor_load_returns_false() {
|
||||
WP_Image_Editor_Mock::$load_return = new WP_Error();
|
||||
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
$this->assertInstanceOf( 'WP_Error', $editor );
|
||||
|
||||
WP_Image_Editor_Mock::$load_return = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test test_quality
|
||||
* @ticket 6821
|
||||
*/
|
||||
public function test_set_quality() {
|
||||
|
||||
// Get an editor
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
// Make quality readable
|
||||
$property = new ReflectionProperty( $editor, 'quality' );
|
||||
$property->setAccessible( true );
|
||||
|
||||
// Ensure set_quality works
|
||||
$this->assertTrue( $editor->set_quality( 75 ) );
|
||||
$this->assertEquals( 75, $property->getValue( $editor ) );
|
||||
|
||||
// Ensure the quality filter works
|
||||
$func = create_function( '', "return 100;");
|
||||
add_filter( 'wp_editor_set_quality', $func );
|
||||
$this->assertTrue( $editor->set_quality( 75 ) );
|
||||
$this->assertEquals( 100, $property->getValue( $editor ) );
|
||||
|
||||
// Clean up
|
||||
remove_filter( 'wp_editor_set_quality', $func );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test generate_filename
|
||||
* @ticket 6821
|
||||
*/
|
||||
public function test_generate_filename() {
|
||||
|
||||
// Get an editor
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
$property = new ReflectionProperty( $editor, 'size' );
|
||||
$property->setAccessible( true );
|
||||
$property->setValue( $editor, array(
|
||||
'height' => 50,
|
||||
'width' => 100
|
||||
));
|
||||
|
||||
// Test with no parameters
|
||||
$this->assertEquals( 'canola-100x50.jpg', basename( $editor->generate_filename() ) );
|
||||
|
||||
// Test with a suffix only
|
||||
$this->assertEquals( 'canola-new.jpg', basename( $editor->generate_filename( 'new' ) ) );
|
||||
|
||||
// Test with a destination dir only
|
||||
$this->assertEquals(trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) );
|
||||
|
||||
// Test with a suffix only
|
||||
$this->assertEquals( 'canola-100x50.png', basename( $editor->generate_filename( null, null, 'png' ) ) );
|
||||
|
||||
// Combo!
|
||||
$this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_size
|
||||
* @ticket 6821
|
||||
*/
|
||||
public function test_get_size() {
|
||||
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
// Size should be false by default
|
||||
$this->assertNull( $editor->get_size() );
|
||||
|
||||
// Set a size
|
||||
$size = array(
|
||||
'height' => 50,
|
||||
'width' => 100
|
||||
);
|
||||
$property = new ReflectionProperty( $editor, 'size' );
|
||||
$property->setAccessible( true );
|
||||
$property->setValue( $editor, $size );
|
||||
|
||||
$this->assertEquals( $size, $editor->get_size() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_suffix
|
||||
* @ticket 6821
|
||||
*/
|
||||
public function test_get_suffix() {
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
// Size should be false by default
|
||||
$this->assertFalse( $editor->get_suffix() );
|
||||
|
||||
// Set a size
|
||||
$size = array(
|
||||
'height' => 50,
|
||||
'width' => 100
|
||||
);
|
||||
$property = new ReflectionProperty( $editor, 'size' );
|
||||
$property->setAccessible( true );
|
||||
$property->setValue( $editor, $size );
|
||||
|
||||
$this->assertEquals( '100x50', $editor->get_suffix() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user