Conditions | 2 |
Paths | 1 |
Total Lines | 38 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function testTransliterate() |
||
20 | { |
||
21 | // Mock the repository so it returns the mock of the Image repository. |
||
22 | $fileToObject = $this->getMockBuilder(FileToObject::class) |
||
23 | ->disableOriginalConstructor() |
||
24 | ->getMock(); |
||
25 | |||
26 | $fileToObject->expects($this->any()) |
||
27 | ->method('getObjectFromFilename') |
||
28 | ->will( |
||
29 | $this->returnCallback( |
||
30 | function ($filename) { |
||
31 | $existingFilenames = [ |
||
32 | 'test.jpg', |
||
33 | 'test_1.jpg', |
||
34 | ]; |
||
35 | if (in_array($filename, $existingFilenames)) { |
||
36 | $image = new TestImage(); |
||
37 | |||
38 | return $image; |
||
39 | } |
||
40 | else { |
||
41 | return null; |
||
42 | } |
||
43 | } |
||
44 | ) |
||
45 | ); |
||
46 | |||
47 | $transliterator = new FilenameTransliterator($fileToObject); |
||
48 | |||
49 | // Test that characters are replaced |
||
50 | $filename = $transliterator->transliterate('a file name-with £disallowed characters.jpg'); |
||
51 | $this->assertEquals('a_file_name_with_disallowed_characters.jpg', $filename); |
||
52 | |||
53 | // Test that filename that already exist are appended with a number. |
||
54 | $filename = $transliterator->transliterate('test.jpg'); |
||
55 | $this->assertEquals('test_2.jpg', $filename); |
||
56 | } |
||
57 | } |
||
58 |