| 1 |
<?php |
| 2 |
|
| 3 |
namespace MatthiasMullie\PathConverter\Tests; |
| 4 |
|
| 5 |
use MatthiasMullie\PathConverter\Converter; |
| 6 |
|
| 7 |
/** |
| 8 |
* Converter test case. |
| 9 |
*/ |
| 10 |
class ConverterTest extends \PHPUnit_Framework_TestCase |
| 11 |
{ |
| 12 |
/** |
| 13 |
* Test Converter, provided by dataProvider. |
| 14 |
* |
| 15 |
* @test |
| 16 |
* @dataProvider dataProvider |
| 17 |
*/ |
| 18 |
public function convert($relative, $from, $to, $expected) |
| 19 |
{ |
| 20 |
$converter = new Converter($from, $to); |
| 21 |
$result = $converter->convert($relative); |
| 22 |
|
| 23 |
$this->assertEquals($expected, $result); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* @return array [relative, from, to, expected result] |
| 28 |
*/ |
| 29 |
public function dataProvider() |
| 30 |
{ |
| 31 |
$tests = array(); |
| 32 |
|
| 33 |
$tests[] = array( |
| 34 |
'../images/img.jpg', |
| 35 |
'/home/forkcms/frontend/core/layout/css', |
| 36 |
'/home/forkcms/frontend/cache/minified_css', |
| 37 |
'../../core/layout/images/img.jpg', |
| 38 |
); |
| 39 |
|
| 40 |
$tests[] = array( |
| 41 |
'../../images/icon.gif', |
| 42 |
'/css/imports/', |
| 43 |
'/css/', |
| 44 |
'../images/icon.gif', |
| 45 |
); |
| 46 |
|
| 47 |
// absolute path - doesn't make sense :) |
| 48 |
$tests[] = array( |
| 49 |
'/home/username/file.txt', |
| 50 |
'/css/imports', |
| 51 |
'/css', |
| 52 |
'/home/username/file.txt', |
| 53 |
); |
| 54 |
|
| 55 |
$tests[] = array( |
| 56 |
'image.jpg', |
| 57 |
'tests/css/sample/convert_relative_path/source', |
| 58 |
'tests/css/sample/convert_relative_path/source', |
| 59 |
'image.jpg', |
| 60 |
); |
| 61 |
|
| 62 |
$tests[] = array( |
| 63 |
'../images/img.jpg', |
| 64 |
'C:/My Documents/forkcms/frontend/core/layout/css', |
| 65 |
'C:/My Documents/forkcms/frontend/cache/minified_css', |
| 66 |
'../../core/layout/images/img.jpg', |
| 67 |
); |
| 68 |
|
| 69 |
// https://github.com/forkcms/forkcms/issues/1186 |
| 70 |
$tests[] = array( |
| 71 |
'../images/img.jpg', |
| 72 |
'/Users/mathias/Documents/— Projecten/PROJECT_NAAM/Web/src/Backend/Core/Layout/Css/', |
| 73 |
'/Users/mathias/Documents/— Projecten/PROJECT_NAAM/Web/src/Backend/Cache/MinifiedCss/', |
| 74 |
'../../Core/Layout/images/img.jpg', |
| 75 |
); |
| 76 |
|
| 77 |
// https://github.com/matthiasmullie/path-converter/issues/1 |
| 78 |
$tests[] = array( |
| 79 |
'image.jpg', |
| 80 |
'/var/www/mysite.com/assets/some_random_folder_name/', |
| 81 |
'/var/www/mysite.com/assets/some_other_random_folder_name/', |
| 82 |
'../some_random_folder_name/image.jpg', |
| 83 |
); |
| 84 |
|
| 85 |
$tests[] = array( |
| 86 |
'image.jpg', |
| 87 |
'/var/www/', |
| 88 |
'/', |
| 89 |
'var/www/image.jpg', |
| 90 |
); |
| 91 |
|
| 92 |
$tests[] = array( |
| 93 |
'image.jpg', |
| 94 |
'/', |
| 95 |
'/var/www/', |
| 96 |
'../../image.jpg', |
| 97 |
); |
| 98 |
|
| 99 |
// https://github.com/matthiasmullie/path-converter/issues/4 |
| 100 |
$tests[] = array( |
| 101 |
'rotissanser-webfont.eot', |
| 102 |
'typo3temp/assets/compressed/../../../typo3conf/ext/user_merkl/Resources/Public/Fonts/webfontkit-rotissanser/stylesheet.css', |
| 103 |
'typo3temp/assets/compressed/merged-abce7d875ee92a78bd5e1871ef774fbe.css', |
| 104 |
'../../../typo3conf/ext/user_merkl/Resources/Public/Fonts/webfontkit-rotissanser/rotissanser-webfont.eot', |
| 105 |
); |
| 106 |
|
| 107 |
// https://github.com/matthiasmullie/path-converter/issues/6 |
| 108 |
$tests[] = array( |
| 109 |
'./../images/header-section/HeroImage.jpg', |
| 110 |
'/wordpress/wp-content/themes/racine/styles/', |
| 111 |
'/wordpress/wp-content/cache/min/', |
| 112 |
'../../themes/racine/images/header-section/HeroImage.jpg', |
| 113 |
); |
| 114 |
|
| 115 |
// https://github.com/matthiasmullie/path-converter/issues/6 |
| 116 |
$tests[] = array( |
| 117 |
'../images/./header-section/HeroImage2.jpg', |
| 118 |
'/wordpress/wp-content/themes/racine/styles/', |
| 119 |
'/wordpress/wp-content/cache/min/', |
| 120 |
'../../themes/racine/images/header-section/HeroImage2.jpg', |
| 121 |
); |
| 122 |
|
| 123 |
return $tests; |
| 124 |
} |
| 125 |
} |
| 126 |
|