summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-01-27 09:54:18 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-01-27 09:54:18 +0100
commit04e98e9890a453b19e4384270ef23ea8eec68481 (patch)
treea09e9dc05e9ce553d6b2682adf72f4772d87c0b5
parent8241180c6ce0cb19255d70a3394f891e08182542 (diff)
update config to use node based public filesystem
-rw-r--r--appinfo/application.php47
-rw-r--r--config/config.php14
-rw-r--r--tests/unit/config/ConfigTest.php72
3 files changed, 81 insertions, 52 deletions
diff --git a/appinfo/application.php b/appinfo/application.php
index dcb6893da..bb5c55816 100644
--- a/appinfo/application.php
+++ b/appinfo/application.php
@@ -18,27 +18,26 @@ require_once __DIR__ . '/autoload.php';
use HTMLPurifier;
use HTMLPurifier_Config;
-use \PicoFeed\Config\Config as PicoFeedConfig;
-use \PicoFeed\Reader\Reader as PicoFeedReader;
+use PicoFeed\Config\Config as PicoFeedConfig;
+use PicoFeed\Reader\Reader as PicoFeedReader;
-use \OC\Files\View;
-use \OCP\AppFramework\App;
+use OCP\AppFramework\App;
-use \OCA\News\Config\AppConfig;
-use \OCA\News\Config\Config;
+use OCA\News\Config\AppConfig;
+use OCA\News\Config\Config;
-use \OCA\News\Service\FeedService;
+use OCA\News\Service\FeedService;
-use \OCA\News\Db\MapperFactory;
+use OCA\News\Db\MapperFactory;
-use \OCA\News\Fetcher\Fetcher;
-use \OCA\News\Fetcher\FeedFetcher;
+use OCA\News\Fetcher\Fetcher;
+use OCA\News\Fetcher\FeedFetcher;
-use \OCA\News\ArticleEnhancer\Enhancer;
-use \OCA\News\ArticleEnhancer\XPathArticleEnhancer;
-use \OCA\News\ArticleEnhancer\RegexArticleEnhancer;
+use OCA\News\ArticleEnhancer\Enhancer;
+use OCA\News\ArticleEnhancer\XPathArticleEnhancer;
+use OCA\News\ArticleEnhancer\RegexArticleEnhancer;
-use \OCA\News\Explore\RecommendedSites;
+use OCA\News\Explore\RecommendedSites;
class Application extends App {
@@ -80,25 +79,23 @@ class Application extends App {
});
$container->registerService('DatabaseType', function($c) {
- return $c->query('OCP\\IConfig')->getSystemValue('dbtype');
+ return $c->query('OCP\IConfig')->getSystemValue('dbtype');
});
/**
* Utility
*/
- $container->registerService('ConfigView', function() {
- $view = new View('/news/config');
- if (!$view->file_exists('')) {
- $view->mkdir('');
+ $container->registerService('ConfigView', function($c) {
+ $fs = $c->query('OCP\Files\IRootFolder');
+ $path = '/news/config';
+ if ($fs->nodeExists($path)) {
+ return $fs->get($path);
+ } else {
+ return $fs->newFolder($path);
}
-
- return $view;
});
- $container->registerService('ConfigPath', function() {
- return 'config.ini';
- });
$container->registerService('OCA\News\Config\Config', function($c) {
$config = new Config(
@@ -106,7 +103,7 @@ class Application extends App {
$c->query('OCP\ILogger'),
$c->query('LoggerParameters')
);
- $config->read($c->query('ConfigPath'), true);
+ $config->read('config.ini', true);
return $config;
});
diff --git a/config/config.php b/config/config.php
index 4df8ba853..c02a8872c 100644
--- a/config/config.php
+++ b/config/config.php
@@ -13,7 +13,8 @@
namespace OCA\News\Config;
-use \OCP\ILogger;
+use OCP\ILogger;
+use OCP\Files\Folder;
class Config {
@@ -33,7 +34,8 @@ class Config {
private $exploreUrl;
- public function __construct($fileSystem, ILogger $logger,
+ public function __construct(Folder $fileSystem,
+ ILogger $logger,
$LoggerParameters) {
$this->fileSystem = $fileSystem;
$this->autoPurgeMinimumInterval = 60;
@@ -170,13 +172,13 @@ class Config {
public function read($configPath, $createIfNotExists=false) {
- if($createIfNotExists && !$this->fileSystem->file_exists($configPath)) {
-
+ if($createIfNotExists && !$this->fileSystem->nodeExists($configPath)) {
+ $this->fileSystem->newFile($configPath);
$this->write($configPath);
} else {
- $content = $this->fileSystem->file_get_contents($configPath);
+ $content = $this->fileSystem->get($configPath)->getContent();
$configValues = parse_ini_string($content);
if($configValues === false || count($configValues) === 0) {
@@ -223,7 +225,7 @@ class Config {
var_export($this->useCronUpdates, true);
;
- $this->fileSystem->file_put_contents($configPath, $ini);
+ $this->fileSystem->get($configPath)->putContent($ini);
}
diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php
index 5baeae3ba..d2444fcf4 100644
--- a/tests/unit/config/ConfigTest.php
+++ b/tests/unit/config/ConfigTest.php
@@ -13,8 +13,10 @@
namespace OCA\News\Config;
+use PHPUnit_Framework_TestCase;
-class ConfigTest extends \PHPUnit_Framework_TestCase {
+
+class ConfigTest extends PHPUnit_Framework_TestCase {
private $fileSystem;
private $config;
@@ -23,14 +25,10 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$this->logger = $this->getMockBuilder(
- '\OCP\ILogger')
+ 'OCP\ILogger')
->disableOriginalConstructor()
->getMock();
- $this->fileSystem = $this->getMock('FileSystem', [
- 'file_get_contents',
- 'file_put_contents',
- 'file_exists'
- ]);
+ $this->fileSystem = $this->getMockBuilder('OCP\Files\Folder')->getMock();
$this->loggerParams = ['hi'];
$this->config = new Config(
$this->fileSystem, $this->logger, $this->loggerParams
@@ -56,12 +54,17 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testRead () {
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->fileSystem->expects($this->once())
- ->method('file_get_contents')
+ ->method('get')
->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('getContent')
->will($this->returnValue(
- 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true')
- );
+ 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true'
+ ));
+
$this->config->read($this->configPath);
@@ -71,9 +74,13 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testReadIgnoresVeryLowPurgeInterval () {
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->fileSystem->expects($this->once())
- ->method('file_get_contents')
+ ->method('get')
->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('getContent')
->will($this->returnValue('autoPurgeMinimumInterval = 59'));
$this->config->read($this->configPath);
@@ -84,9 +91,13 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testReadBool () {
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->fileSystem->expects($this->once())
- ->method('file_get_contents')
+ ->method('get')
->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('getContent')
->will($this->returnValue(
'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false')
);
@@ -99,9 +110,13 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testReadLogsInvalidValue() {
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->fileSystem->expects($this->once())
- ->method('file_get_contents')
+ ->method('get')
->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('getContent')
->will($this->returnValue('autoPurgeCounts = 3'));
$this->logger->expects($this->once())
->method('warning')
@@ -114,9 +129,13 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testReadLogsInvalidINI() {
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->fileSystem->expects($this->once())
- ->method('file_get_contents')
+ ->method('get')
->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('getContent')
->will($this->returnValue(''));
$this->logger->expects($this->once())
->method('warning')
@@ -143,10 +162,14 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
$this->config->setMaxSize(399);
$this->config->setExploreUrl('http://google.de');
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->fileSystem->expects($this->once())
- ->method('file_put_contents')
- ->with($this->equalTo($this->configPath),
- $this->equalTo($json));
+ ->method('get')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('putContent')
+ ->with($this->equalTo($json));
$this->config->write($this->configPath);
}
@@ -159,7 +182,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testReadingNonExistentConfigWillWriteDefaults() {
$this->fileSystem->expects($this->once())
- ->method('file_exists')
+ ->method('nodeExists')
->with($this->equalTo($this->configPath))
->will($this->returnValue(false));
@@ -174,9 +197,16 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
'useCronUpdates = false';
$this->fileSystem->expects($this->once())
- ->method('file_put_contents')
- ->with($this->equalTo($this->configPath),
- $this->equalTo($json));
+ ->method('newFile')
+ ->with($this->equalTo($this->configPath));
+ $file = $this->getMockBuilder('OCP\Files\File')->getMock();
+ $this->fileSystem->expects($this->once())
+ ->method('get')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue($file));
+ $file->expects($this->once())
+ ->method('putContent')
+ ->with($this->equalTo($json));
$this->config->read($this->configPath, true);
}