GadgetFeatureRegistry = new TestGadgetFeatureRegistry(Config::get('features_path'));
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown() {
unset($_SERVER['HTTP_HOST']);
$this->GadgetFeatureRegistry = null;
parent::tearDown();
}
/**
* Tests GadgetFeatureRegistry->__construct()
*/
public function test__construct() {
$this->GadgetFeatureRegistry->__construct(Config::get('features_path'));
}
public function testParseFeatureFileWithContainerGadgetAndAll() {
$content = '
featureName
dependency1
dependency2
';
$basePath = '/path';
$feature = $this->GadgetFeatureRegistry->_parse($content, $basePath);
$expected = array(
'deps' => array(
'dependency1' => 'dependency1',
'dependency2' => 'dependency2',
),
'basePath' => '/path',
'name' => 'featureName',
'gadgetJs' => array(
array(
'type' => 'FILE',
'content' => 'gadgetFile1.js',
),
array(
'type' => 'FILE',
'content' => 'gadgetFile2.js',
),
array(
'type' => 'INLINE',
'content' => 'alert(1);',
),
array(
'type' => 'URL',
'content' => 'http://localhost/gadgets/resources/example.com/file.js',
),
),
'containerJs' => array(
array(
'type' => 'FILE',
'content' => 'containerFile1.js',
),
array(
'type' => 'FILE',
'content' => 'containerFile2.js',
),
array(
'type' => 'URL',
'content' => 'http://example.com/file.js',
),
)
);
$this->assertEquals($expected, $feature);
}
public function testParseFeatureFileWithContainerAndAllBlock() {
$content = '
featureName
dependency1
dependency2
';
$basePath = '/path';
$feature = $this->GadgetFeatureRegistry->_parse($content, $basePath);
$expected = array(
'deps' => array(
'dependency1' => 'dependency1',
'dependency2' => 'dependency2',
),
'basePath' => '/path',
'name' => 'featureName',
'gadgetJs' => array(
array(
'type' => 'FILE',
'content' => 'file1.js',
),
array(
'type' => 'FILE',
'content' => 'file2.js',
),
array(
'type' => 'URL',
'content' => 'https://example.com/file.js',
),
),
'containerJs' => array(
array(
'type' => 'FILE',
'content' => 'file1.js',
),
array(
'type' => 'FILE',
'content' => 'file2.js',
),
array(
'type' => 'URL',
'content' => 'https://example.com/file.js',
),
)
);
$this->assertEquals($expected, $feature);
}
public function testParseFeatureFileWithAllBlock() {
$content = '
featureName
dependency1
dependency2
';
$basePath = '/path';
$feature = $this->GadgetFeatureRegistry->_parse($content, $basePath);
$expected = array(
'deps' => array(
'dependency1' => 'dependency1',
'dependency2' => 'dependency2',
),
'basePath' => '/path',
'name' => 'featureName',
'gadgetJs' => array(
array(
'type' => 'FILE',
'content' => 'file1.js',
),
array(
'type' => 'FILE',
'content' => 'file2.js',
),
array(
'type' => 'URL',
'content' => 'https://example.com/file.js',
),
),
'containerJs' => array(
array(
'type' => 'FILE',
'content' => 'containerFile1.js',
),
array(
'type' => 'FILE',
'content' => 'containerFile2.js',
),
array(
'type' => 'URL',
'content' => 'http://example.com/file.js',
),
)
);
$this->assertEquals($expected, $feature);
}
}
class TestGadgetFeatureRegistry extends GadgetFeatureRegistry
{
public function _parse($content, $basePath) {
return $this->parse($content, $basePath);
}
}