|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\KI\CoreBundle\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Tests\KI\CoreBundle\WebTestCase; |
|
6
|
|
|
|
|
7
|
|
|
class ImageServiceTest extends WebTestCase |
|
8
|
|
|
{ |
|
9
|
|
|
protected $container; |
|
10
|
|
|
protected $service; |
|
11
|
|
|
protected $path; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::__construct(); |
|
16
|
|
|
$this->container = static::$kernel->getContainer(); |
|
17
|
|
|
$this->service = $this->container->get('ki_core.service.image'); |
|
18
|
|
|
$this->path = $this->container->getParameter('ki_core.images.directory'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testUploadBase64() |
|
22
|
|
|
{ |
|
23
|
|
|
$imgResult = $this->service->uploadFromBase64($this->base64); |
|
24
|
|
|
$this->assertTrue($imgResult['image'] !== null); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testExtUploadBase64() |
|
28
|
|
|
{ |
|
29
|
|
|
$result = $this->service->uploadFromBase64($this->base64); |
|
30
|
|
|
$this->assertEquals($result['extension'], 'png'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testUploadUrl() |
|
34
|
|
|
{ |
|
35
|
|
|
$url = 'https://upont.enpc.fr/img/favicon.png'; |
|
36
|
|
|
$result = $this->service->uploadFromUrl($url); |
|
37
|
|
|
$this->assertTrue($result['image'] !== null); |
|
38
|
|
|
$this->assertEquals($result['extension'], 'png'); |
|
39
|
|
|
|
|
40
|
|
|
$url = 'http://ia.media-imdb.com/images/M/MV5BMTg2OTIwNTQ2OF5BMl5BanBnXkFtZTcwNTA4NDAwMQ@@._V1_SX300.jpg'; |
|
41
|
|
|
$result = $this->service->uploadFromUrl($url); |
|
42
|
|
|
$this->assertTrue($result['image'] !== null); |
|
43
|
|
|
$this->assertEquals($result['extension'], 'jpeg'); |
|
44
|
|
|
|
|
45
|
|
|
$url = 'http://akamai-b.cdn.cddbp.net/cds/2.0/cover/FCBA/FCB8/A360/ACE4_medium_front.jpg'; |
|
46
|
|
|
$result = $this->service->uploadFromUrl($url); |
|
47
|
|
|
$this->assertTrue($result['image'] !== null); |
|
48
|
|
|
$this->assertEquals($result['extension'], 'jpeg'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testFailUploadUrl() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->setExpectedException('Exception'); |
|
54
|
|
|
$url = 'httzpqq//wsqdqww.youtube.com/yt/brand/media/image/YouTube-logo-full_color.png'; |
|
55
|
|
|
$result = $this->service->uploadFromUrl($url); |
|
56
|
|
|
$this->assertEquals($result, null); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected $base64 = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASAQMAAAByySynAAAABlBMVEUAAAD///+l2Z/dAAAAP0lEQVQImWNgPm9gwAAmbM4bH4AQzAdAYiDC/rzxByTi/+f/cIL5AwPnZGYGIGHMwGA5mdkASNgbMNgJ80AIAMCSHqNvm2VtAAAAAElFTkSuQmCC'; |
|
60
|
|
|
} |
|
61
|
|
|
|