forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-image-retina.php
100 lines (86 loc) · 3.59 KB
/
test-timber-image-retina.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @group posts-api
* @group attachments
*/
class TestTimberImageRetina extends Timber_UnitTestCase
{
public function testImageRetina()
{
$file = TestTimberImage::copyTestAttachment();
$retina_url = Timber\ImageHelper::retina_resize($file);
$this->assertEquals('arch@2x.jpg', basename($retina_url));
}
public function testImageBiggerRetina()
{
$file = TestTimberImage::copyTestAttachment();
$retina_url = Timber\ImageHelper::retina_resize($file, 3);
$this->assertEquals('arch@3x.jpg', basename($retina_url));
}
public function testImageRetinaFilter()
{
$filename = TestTimberImage::copyTestAttachment('eastern.jpg');
$wp_filetype = wp_check_filetype(basename($filename), null);
$post_id = $this->factory->post->create([
'post_title' => 'Thing One',
]);
$attachment = [
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_excerpt' => '',
'post_status' => 'inherit',
];
$attach_id = wp_insert_attachment($attachment, $filename, $post_id);
add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
$retina_url = Timber::compile_string('{{post.thumbnail.src|retina}}', [
'post' => Timber::get_post($post_id),
]);
$this->assertEquals('eastern@2x.jpg', basename($retina_url));
}
public function testImageRetinaFloatFilter()
{
$filename = TestTimberImage::copyTestAttachment('eastern.jpg');
$wp_filetype = wp_check_filetype(basename($filename), null);
$post_id = $this->factory->post->create([
'post_title' => 'Thing One',
]);
$attachment = [
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_excerpt' => '',
'post_status' => 'inherit',
];
$attach_id = wp_insert_attachment($attachment, $filename, $post_id);
add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
$compiled = Timber::compile_string('{{post.thumbnail.src|retina(1.5)}}', [
'post' => Timber::get_post($post_id),
]);
$this->assertEquals('eastern@1.5x.jpg', basename($compiled));
}
public function testImageResizeRetinaFilter()
{
$filename = TestTimberImage::copyTestAttachment('eastern.jpg');
$wp_filetype = wp_check_filetype(basename($filename), null);
$post_id = $this->factory->post->create();
$attachment = [
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_excerpt' => '',
'post_status' => 'inherit',
];
$attach_id = wp_insert_attachment($attachment, $filename, $post_id);
add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
$compiled = Timber::compile_string('{{post.thumbnail.src|resize(100, 50)|retina(3)}}', [
'post' => Timber::get_post($post_id),
]);
$this->assertEquals('eastern-100x50-c-default@3x.jpg', basename($compiled));
}
public function testImageResizeRetinaFilterNotAnImage()
{
self::enable_error_log(false);
$str = 'Image? {{"/wp-content/uploads/2016/07/stuff.jpg"|retina(3)}}';
$compiled = Timber::compile_string($str);
$this->assertEquals('Image? /wp-content/uploads/2016/07/stuff.jpg', $compiled);
self::enable_error_log(true);
}
}