Skip to content

Commit 3a1deee

Browse files
authored
Merge pull request #1229 from timber/1227_image_test_fix
1227 image test fix
2 parents 3a59648 + bf29fba commit 3a1deee

2 files changed

Lines changed: 35 additions & 21 deletions

File tree

lib/ImageHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ private static function analyze_url( $url ) {
355355
$upload_dir = wp_upload_dir();
356356
$tmp = $url;
357357
if ( 0 === strpos($tmp, ABSPATH) ) {
358-
// we've been given a dir, not an url
358+
// we've been given a dir, not an url
359359
$result['absolute'] = true;
360360
if ( 0 === strpos($tmp, $upload_dir['basedir']) ) {
361361
$result['base'] = self::BASE_UPLOADS; // upload based
@@ -367,7 +367,7 @@ private static function analyze_url( $url ) {
367367
}
368368
} else {
369369
if ( !$result['absolute'] ) {
370-
$tmp = get_home_url().$tmp;
370+
$tmp = site_url().$tmp;
371371
}
372372
if ( 0 === strpos($tmp, $upload_dir['baseurl']) ) {
373373
$result['base'] = self::BASE_UPLOADS; // upload based

tests/test-timber-image-resize.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,33 +113,47 @@ function testCropHeight() {
113113
$this->assertTrue( $is_sized );
114114
}
115115

116-
function testWPMLurls() {
116+
function testWPMLurlRemote() {
117117
// this test replicates the url issue caused by the WPML language identifier in the url
118118
// However, WPML can't be installed with composer so this test mocks the WPML plugin
119119

120120
// WPML uses a filter to alter the home_url
121121
$home_url_filter = function( $url ) { return $url.'/en'; };
122122
add_filter( 'home_url', $home_url_filter, -10, 4 );
123123

124+
$img = 'https://raw.githubusercontent.com/timber/timber/master/tests/assets/arch-2night.jpg';
124125
// test with a local and external file
125-
foreach ( array(
126-
'arch.jpg',
127-
'https://raw.githubusercontent.com/timber/timber/master/tests/assets/arch-2night.jpg'
128-
) as $img ) {
129-
130-
// copy image if it's local
131-
if ( strpos($img, '://') === false ) {
132-
$img = TestTimberImage::copyTestImage($img);
133-
}
134-
135-
$resized = TimberImageHelper::resize($img, 50, 50);
136-
137-
// make sure the base url has not been duplicated (https://github.com/timber/timber/issues/405)
138-
$this->assertLessThanOrEqual( 1, substr_count($resized, 'example.org') );
139-
// make sure the image has been resized
140-
$resized = TimberUrlHelper::url_to_file_system( $resized );
141-
$this->assertTrue( TestTimberImage::checkSize($resized, 50, 50), 'image should be resized' );
142-
}
126+
127+
$resized = TimberImageHelper::resize($img, 50, 50);
128+
129+
// make sure the base url has not been duplicated (https://github.com/timber/timber/issues/405)
130+
$this->assertLessThanOrEqual( 1, substr_count($resized, 'example.org') );
131+
// make sure the image has been resized
132+
$resized = TimberUrlHelper::url_to_file_system( $resized );
133+
$this->assertTrue( TestTimberImage::checkSize($resized, 50, 50), 'image should be resized' );
134+
135+
}
136+
137+
function testWPMLurlLocal() {
138+
// this test replicates the url issue caused by the WPML language identifier in the url
139+
// However, WPML can't be installed with composer so this test mocks the WPML plugin
140+
141+
// WPML uses a filter to alter the home_url
142+
$home_url_filter = function( $url ) { return $url.'/en'; };
143+
add_filter( 'home_url', $home_url_filter, -10, 4 );
144+
145+
// test with a local and external file
146+
$img = 'arch.jpg';
147+
$img = TestTimberImage::copyTestImage($img);
148+
149+
$resized = TimberImageHelper::resize($img, 50, 50);
150+
151+
// make sure the base url has not been duplicated (https://github.com/timber/timber/issues/405)
152+
$this->assertLessThanOrEqual( 1, substr_count($resized, 'example.org') );
153+
// make sure the image has been resized
154+
$resized = TimberUrlHelper::url_to_file_system( $resized );
155+
$this->assertTrue( TestTimberImage::checkSize($resized, 50, 50), 'image should be resized' );
156+
143157
}
144158

145159
}

0 commit comments

Comments
 (0)