Skip to content
Prev Previous commit
Next Next commit
Replaces ->factory and ->factory() references with self::factory()
  • Loading branch information
mukeshpanchal27 committed Nov 7, 2022
commit 3ec7d40ebba04c02d3ace8858f3537b8bfee96f6
2 changes: 1 addition & 1 deletion tests/admin/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function test_perflab_add_modules_page() {
remove_all_filters( 'plugin_action_links_' . plugin_basename( PERFLAB_MAIN_FILE ) );

// Rely on current user to be an administrator (with 'manage_options' capability).
$user_id = $this->factory()->user->create( array( 'role' => 'administrator' ) );
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $user_id );
$hook_suffix = perflab_add_modules_page();
$this->assertSame( get_plugin_page_hookname( PERFLAB_MODULES_SCREEN, 'options-general.php' ), $hook_suffix );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static function () {
*/
public function test_get_dominant_color( $image_path, $expected_color, $expected_transparency ) {

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
Expand All @@ -50,7 +50,7 @@ public function test_get_dominant_color( $image_path, $expected_color, $expected
*/
public function test_get_dominant_color_invalid( $image_path, $expected_color, $expected_transparency ) {

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
Expand All @@ -68,7 +68,7 @@ public function test_get_dominant_color_invalid( $image_path, $expected_color, $
*/
public function test_get_dominant_color_none_images( $image_path ) {

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static function () {
*/
public function test_get_dominant_color( $image_path, $expected_color, $expected_transparency ) {

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
Expand All @@ -52,7 +52,7 @@ public function test_get_dominant_color( $image_path, $expected_color, $expected
*/
public function test_get_dominant_color_invalid( $image_path, $expected_color, $expected_transparency ) {

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
Expand All @@ -70,7 +70,7 @@ public function test_get_dominant_color_invalid( $image_path, $expected_color, $
*/
public function test_get_dominant_color_none_images( $image_path ) {

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
Expand Down
10 changes: 5 additions & 5 deletions tests/modules/images/dominant-color/dominant-color-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function test_dominant_color_metadata( $image_path, $expected_color, $exp
$this->assertEmpty( $dominant_color_metadata );

// Creating attachment.
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$dominant_color_metadata = dominant_color_metadata( array(), $attachment_id );
$this->assertArrayHasKey( 'dominant_color', $dominant_color_metadata );
Expand All @@ -39,7 +39,7 @@ public function test_dominant_color_metadata( $image_path, $expected_color, $exp
*/
public function test_dominant_color_get_dominant_color( $image_path, $expected_color, $expected_transparency ) {
// Creating attachment.
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
$this->assertContains( dominant_color_get_dominant_color( $attachment_id ), $expected_color );
}

Expand All @@ -55,7 +55,7 @@ public function test_has_transparency_metadata( $image_path, $expected_color, $e
$transparency_metadata = dominant_color_metadata( array(), 1 );
$this->assertEmpty( $transparency_metadata );

$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$transparency_metadata = dominant_color_metadata( array(), $attachment_id );
$this->assertArrayHasKey( 'has_transparency', $transparency_metadata );
Expand All @@ -71,7 +71,7 @@ public function test_has_transparency_metadata( $image_path, $expected_color, $e
*/
public function test_dominant_color_has_transparency( $image_path, $expected_color, $expected_transparency ) {
// Creating attachment.
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
$this->assertSame( $expected_transparency, dominant_color_has_transparency( $attachment_id ) );
}

Expand All @@ -83,7 +83,7 @@ public function test_dominant_color_has_transparency( $image_path, $expected_col
* @covers ::dominant_color_img_tag_add_dominant_color
*/
public function test_tag_add_adjust_to_image_attributes( $image_path, $expected_color, $expected_transparency ) {
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

list( $src, $width, $height ) = wp_get_attachment_image_src( $attachment_id );
Expand Down
34 changes: 17 additions & 17 deletions tests/modules/images/webp-uploads/helper-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi

add_filter( 'wp_image_editors', '__return_empty_array' );
yield 'when no editor is present' => array(
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
'medium',
array(),
'image/avif',
);

remove_filter( 'wp_image_editors', '__return_empty_array' );
yield 'when using a mime that is not supported' => array(
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
'medium',
array(),
'image/avif',
);

yield 'when no dimension is provided' => array(
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
'medium',
array(),
'image/webp',
);

yield 'when both dimensions are negative numbers' => array(
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
'medium',
array(
'width' => -10,
Expand All @@ -63,7 +63,7 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi
);

yield 'when both dimensions are zero' => array(
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
'medium',
array(
'width' => 0,
Expand All @@ -82,7 +82,7 @@ public function it_should_create_an_image_with_the_default_suffix_in_the_same_lo
// Create JPEG and WebP so that both versions are generated.
$this->opt_in_to_jpeg_and_webp();

$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$size_data = array(
'width' => 300,
'height' => 300,
Expand All @@ -107,7 +107,7 @@ public function it_should_create_an_image_with_the_default_suffix_in_the_same_lo
* @test
*/
public function it_should_create_a_file_in_the_specified_location_with_the_specified_name() {
$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$size_data = array(
'width' => 300,
'height' => 300,
Expand All @@ -131,7 +131,7 @@ public function it_should_create_a_file_in_the_specified_location_with_the_speci
* @test
*/
public function it_should_prevent_processing_an_image_with_corrupted_metadata( callable $callback, $size ) {
$attachment_id = $this->factory->attachment->create_upload_object(
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp'
);
$metadata = wp_get_attachment_metadata( $attachment_id );
Expand Down Expand Up @@ -175,7 +175,7 @@ function ( $metadata ) {
* @test
*/
public function it_should_prevent_to_create_an_image_size_when_attached_file_does_not_exists() {
$attachment_id = $this->factory->attachment->create_upload_object(
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
);
$file = get_attached_file( $attachment_id );
Expand All @@ -199,7 +199,7 @@ public function it_should_prevent_to_create_an_image_size_when_attached_file_doe
* @test
*/
public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_not_exists() {
$attachment_id = $this->factory->attachment->create_upload_object(
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
);

Expand All @@ -216,7 +216,7 @@ public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_n
* @test
*/
public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_wordpress() {
$attachment_id = $this->factory->attachment->create_upload_object(
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
);
$result = webp_uploads_generate_image_size( $attachment_id, 'medium', 'image/avif' );
Expand All @@ -231,7 +231,7 @@ public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_word
*/
public function it_should_prevent_to_process_an_image_when_the_editor_does_not_support_the_format() {
// Make sure no editor is available.
$attachment_id = $this->factory->attachment->create_upload_object(
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
);

Expand All @@ -255,7 +255,7 @@ function () {
public function it_should_create_an_image_with_filter_webp_uploads_pre_generate_additional_image_source() {
remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' );

$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );

add_filter(
'webp_uploads_pre_generate_additional_image_source',
Expand Down Expand Up @@ -289,7 +289,7 @@ function () {
public function it_should_use_filesize_when_filter_webp_uploads_pre_generate_additional_image_source_returns_filesize() {
remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' );

$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );

add_filter(
'webp_uploads_pre_generate_additional_image_source',
Expand Down Expand Up @@ -324,7 +324,7 @@ function () {
public function it_should_return_an_error_when_filter_webp_uploads_pre_generate_additional_image_source_returns_wp_error() {
remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' );

$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );

add_filter(
'webp_uploads_pre_generate_additional_image_source',
Expand Down Expand Up @@ -547,8 +547,8 @@ private function mock_empty_action( $action ) {
* @test
*/
public function it_should_add_original_image_extension_to_the_webp_file_name_to_ensure_it_is_unique( $jpeg_image, $jpg_image ) {
$jpeg_image_attachment_id = $this->factory->attachment->create_upload_object( $jpeg_image );
$jpg_image_attachment_id = $this->factory->attachment->create_upload_object( $jpg_image );
$jpeg_image_attachment_id = self::factory()->attachment->create_upload_object( $jpeg_image );
$jpg_image_attachment_id = self::factory()->attachment->create_upload_object( $jpg_image );

$size_data = array(
'width' => 300,
Expand Down
Loading