2014-12-01 23:47:22 +03:00
|
|
|
<?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')
|
2014-12-02 01:43:27 +03:00
|
|
|
->disableOriginalConstructor()
|
2014-12-01 23:47:22 +03:00
|
|
|
->getMock();
|
|
|
|
$this->platformMock->expects($this->any())
|
|
|
|
->method('getPhpVersion')
|
|
|
|
->will( $this->returnValue('5.4.3'));
|
2014-12-02 01:43:27 +03:00
|
|
|
$this->platformMock->expects($this->any())
|
|
|
|
->method('getDatabase')
|
|
|
|
->will( $this->returnValue('mysql'));
|
2014-12-01 23:47:22 +03:00
|
|
|
$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)) {
|
2014-12-02 13:49:31 +03:00
|
|
|
$app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
|
2014-12-01 23:47:22 +03:00
|
|
|
}
|
|
|
|
if (!is_null($maxVersion)) {
|
2014-12-02 13:49:31 +03:00
|
|
|
$app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
|
2014-12-01 23:47:22 +03:00
|
|
|
}
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2014-12-02 01:43:27 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider providesDatabases
|
|
|
|
*/
|
|
|
|
public function testDatabases($expectedMissing, $databases) {
|
|
|
|
$app = array(
|
|
|
|
'dependencies' => array(
|
|
|
|
)
|
|
|
|
);
|
|
|
|
if (!is_null($databases)) {
|
2014-12-02 17:14:48 +03:00
|
|
|
$app['dependencies']['database'] = $databases;
|
2014-12-02 01:43:27 +03:00
|
|
|
}
|
|
|
|
$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 providesDatabases() {
|
|
|
|
return array(
|
|
|
|
// non BC - in case on databases are defined -> all are supported
|
|
|
|
array(array(), null),
|
|
|
|
array(array(), array()),
|
2014-12-02 13:49:31 +03:00
|
|
|
array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
|
2014-12-02 01:43:27 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
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'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|