*/
public function analyze() {
$this->analysePhpVersion();
+ $this->analyseSupportedDatabases();
return $this->missing;
}
}
}
+ private function analyseSupportedDatabases() {
+ if (!array_key_exists('database', $this->dependencies)) {
+ return;
+ }
+
+ $supportedDatabases = $this->dependencies['database'];
+ if (empty($supportedDatabases)) {
+ return;
+ }
+ $currentDatabase = $this->system->getDatabase();
+ if (!in_array($currentDatabase, $supportedDatabases)) {
+ $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
+ }
+ }
+
}
namespace OC\App;
+use OCP\IConfig;
+
class Platform {
+
+ function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
public function getPhpVersion() {
return phpversion();
}
+
+ public function getDatabase() {
+ $dbType = $this->config->getSystemValue('dbtype', 'sqlite');
+ if ($dbType === 'sqlite3') {
+ $dbType = 'sqlite';
+ }
+
+ return $dbType;
+ }
}
$app['canUnInstall'] = !$app['active'] && $app['removable'];
// analyse dependencies
- $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform(), $this->l10n);
+ $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform($this->config), $this->l10n);
$missing = $dependencyAnalyzer->analyze();
$app['canInstall'] = empty($missing);
public function setUp() {
$this->platformMock = $this->getMockBuilder('\OC\App\Platform')
+ ->disableOriginalConstructor()
->getMock();
$this->platformMock->expects($this->any())
->method('getPhpVersion')
->will( $this->returnValue('5.4.3'));
+ $this->platformMock->expects($this->any())
+ ->method('getDatabase')
+ ->will( $this->returnValue('mysql'));
$this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()
->getMock();
$this->assertEquals($expectedMissing, $missing);
}
+ /**
+ * @dataProvider providesDatabases
+ */
+ public function testDatabases($expectedMissing, $databases) {
+ $app = array(
+ 'dependencies' => array(
+ )
+ );
+ if (!is_null($databases)) {
+ $app['dependencies']['database'] = $databases;
+ }
+ $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()),
+ array(array('Following databases are supported: sqlite, postgres'), array('sqlite', 'postgres')),
+ );
+ }
+
function providesPhpVersion() {
return array(
array(array(), null, null),