| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Assetic package, an OpenSky project. |
| 5 |
* |
| 6 |
* (c) 2010-2014 OpenSky Project Inc |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Assetic\Test\Util; |
| 13 |
|
| 14 |
use Assetic\Util\VarUtils; |
| 15 |
|
| 16 |
class VarUtilsTest extends \PHPUnit_Framework_TestCase |
| 17 |
{ |
| 18 |
public function testResolve() |
| 19 |
{ |
| 20 |
$template = '{foo}bar'; |
| 21 |
$vars = array('foo'); |
| 22 |
$values = array('foo' => 'foo'); |
| 23 |
|
| 24 |
$this->assertEquals('foobar', VarUtils::resolve($template, $vars, $values)); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* @dataProvider getCombinationTests |
| 29 |
*/ |
| 30 |
public function testGetCombinations($vars, $expected) |
| 31 |
{ |
| 32 |
$actual = VarUtils::getCombinations( |
| 33 |
$vars, |
| 34 |
array( |
| 35 |
'locale' => array('en', 'de', 'fr'), |
| 36 |
'browser' => array('ie', 'firefox', 'other'), |
| 37 |
'gzip' => array('gzip', ''), |
| 38 |
) |
| 39 |
); |
| 40 |
|
| 41 |
$this->assertEquals($expected, $actual); |
| 42 |
} |
| 43 |
|
| 44 |
public function getCombinationTests() |
| 45 |
{ |
| 46 |
$tests = array(); |
| 47 |
|
| 48 |
// no variables |
| 49 |
$tests[] = array( |
| 50 |
array(), |
| 51 |
array(array()), |
| 52 |
); |
| 53 |
|
| 54 |
// one variables |
| 55 |
$tests[] = array( |
| 56 |
array('locale'), |
| 57 |
array( |
| 58 |
array('locale' => 'en'), |
| 59 |
array('locale' => 'de'), |
| 60 |
array('locale' => 'fr'), |
| 61 |
), |
| 62 |
); |
| 63 |
|
| 64 |
// two variables |
| 65 |
$tests[] = array( |
| 66 |
array('locale', 'browser'), |
| 67 |
array( |
| 68 |
array('locale' => 'en', 'browser' => 'ie'), |
| 69 |
array('locale' => 'de', 'browser' => 'ie'), |
| 70 |
array('locale' => 'fr', 'browser' => 'ie'), |
| 71 |
array('locale' => 'en', 'browser' => 'firefox'), |
| 72 |
array('locale' => 'de', 'browser' => 'firefox'), |
| 73 |
array('locale' => 'fr', 'browser' => 'firefox'), |
| 74 |
array('locale' => 'en', 'browser' => 'other'), |
| 75 |
array('locale' => 'de', 'browser' => 'other'), |
| 76 |
array('locale' => 'fr', 'browser' => 'other'), |
| 77 |
), |
| 78 |
); |
| 79 |
|
| 80 |
// three variables |
| 81 |
$tests[] = array( |
| 82 |
array('locale', 'browser', 'gzip'), |
| 83 |
array( |
| 84 |
array('locale' => 'en', 'browser' => 'ie', 'gzip' => 'gzip'), |
| 85 |
array('locale' => 'de', 'browser' => 'ie', 'gzip' => 'gzip'), |
| 86 |
array('locale' => 'fr', 'browser' => 'ie', 'gzip' => 'gzip'), |
| 87 |
array('locale' => 'en', 'browser' => 'firefox', 'gzip' => 'gzip'), |
| 88 |
array('locale' => 'de', 'browser' => 'firefox', 'gzip' => 'gzip'), |
| 89 |
array('locale' => 'fr', 'browser' => 'firefox', 'gzip' => 'gzip'), |
| 90 |
array('locale' => 'en', 'browser' => 'other', 'gzip' => 'gzip'), |
| 91 |
array('locale' => 'de', 'browser' => 'other', 'gzip' => 'gzip'), |
| 92 |
array('locale' => 'fr', 'browser' => 'other', 'gzip' => 'gzip'), |
| 93 |
array('locale' => 'en', 'browser' => 'ie', 'gzip' => ''), |
| 94 |
array('locale' => 'de', 'browser' => 'ie', 'gzip' => ''), |
| 95 |
array('locale' => 'fr', 'browser' => 'ie', 'gzip' => ''), |
| 96 |
array('locale' => 'en', 'browser' => 'firefox', 'gzip' => ''), |
| 97 |
array('locale' => 'de', 'browser' => 'firefox', 'gzip' => ''), |
| 98 |
array('locale' => 'fr', 'browser' => 'firefox', 'gzip' => ''), |
| 99 |
array('locale' => 'en', 'browser' => 'other', 'gzip' => ''), |
| 100 |
array('locale' => 'de', 'browser' => 'other', 'gzip' => ''), |
| 101 |
array('locale' => 'fr', 'browser' => 'other', 'gzip' => ''), |
| 102 |
), |
| 103 |
); |
| 104 |
|
| 105 |
return $tests; |
| 106 |
} |
| 107 |
} |
| 108 |
|