diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-01 21:47:22 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-04 11:40:33 +0100 |
commit | b469e9f6fb83758ad91b8e41d81319ab3a73f098 (patch) | |
tree | 5ccc10851661957739d893d914c278e1b18ff409 /tests/lib/app | |
parent | f74d568bdac14390a787a71f91571d84662f1fbe (diff) | |
download | nextcloud-server-b469e9f6fb83758ad91b8e41d81319ab3a73f098.tar.gz nextcloud-server-b469e9f6fb83758ad91b8e41d81319ab3a73f098.zip |
introduce dependency analyzer to take care of app dependencies
some more unit tests on xml info parser
Diffstat (limited to 'tests/lib/app')
-rw-r--r-- | tests/lib/app/dependencyanalyzer.php | 77 | ||||
-rw-r--r-- | tests/lib/app/infoparser.php | 21 |
2 files changed, 92 insertions, 6 deletions
diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php new file mode 100644 index 00000000000..d0c2919f47a --- /dev/null +++ b/tests/lib/app/dependencyanalyzer.php @@ -0,0 +1,77 @@ +<?php + +/** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * later. + * See the COPYING-README file. + */ + +namespace Test\App; + +use OC; +use OC\App\Platform; +use OCP\IL10N; + +class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { + + /** + * @var Platform + */ + private $platformMock; + + /** + * @var IL10N + */ + private $l10nMock; + + public function setUp() { + $this->platformMock = $this->getMockBuilder('\OC\App\Platform') + ->getMock(); + $this->platformMock->expects($this->any()) + ->method('getPhpVersion') + ->will( $this->returnValue('5.4.3')); + $this->l10nMock = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor() + ->getMock(); + $this->l10nMock->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($text, $parameters = array()) { + return vsprintf($text, $parameters); + })); + } + + /** + * @dataProvider providesPhpVersion + */ + public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) { + $app = array( + 'dependencies' => array( + 'php' => array() + ) + ); + if (!is_null($minVersion)) { + $app['dependencies']['php']['min-version'] = $minVersion; + } + if (!is_null($maxVersion)) { + $app['dependencies']['php']['max-version'] = $maxVersion; + } + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals(count($expectedMissing), count($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + function providesPhpVersion() { + return array( + array(array(), null, null), + array(array(), '5.4', null), + array(array(), null, '5.5'), + array(array(), '5.4', '5.5'), + array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null), + array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'), + ); + } +} diff --git a/tests/lib/app/infoparser.php b/tests/lib/app/infoparser.php index 277e1582e45..20668c05086 100644 --- a/tests/lib/app/infoparser.php +++ b/tests/lib/app/infoparser.php @@ -39,15 +39,24 @@ class InfoParser extends \PHPUnit_Framework_TestCase { $this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator); } - public function testParsingValidXml() { - $expectedData = json_decode(file_get_contents(OC::$SERVERROOT.'/tests/data/app/expected-info.json'), true); - $data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/valid-info.xml'); + /** + * @dataProvider providesInfoXml + */ + public function testParsingValidXml($expectedJson, $xmlFile) { + $expectedData = null; + if (!is_null($expectedJson)) { + $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true); + } + $data = $this->parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile"); $this->assertEquals($expectedData, $data); } - public function testParsingInvalidXml() { - $data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/invalid-info.xml'); - $this->assertNull($data); + function providesInfoXml() { + return array( + array('expected-info.json', 'valid-info.xml'), + array('strange-types-info.json', 'strange-types-info.xml'), + array(null, 'invalid-info.xml'), + ); } } |