From 42d69a95f3276a2d6089ca68f635c4e2f6aa7a23 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 21 Oct 2014 16:45:36 +0200 Subject: convert tabs indention to indention with 4 spaces because of mixing of both variants in code and better readability on github and websites because you cant set the indention width there and 8 spaces will be used for a tab --- tests/unit/config/AppConfigTest.php | 340 +++++++++++++++++------------------ tests/unit/config/ConfigTest.php | 350 ++++++++++++++++++------------------ 2 files changed, 345 insertions(+), 345 deletions(-) (limited to 'tests/unit/config') diff --git a/tests/unit/config/AppConfigTest.php b/tests/unit/config/AppConfigTest.php index 34ab2738a..01bacbf5c 100644 --- a/tests/unit/config/AppConfigTest.php +++ b/tests/unit/config/AppConfigTest.php @@ -16,174 +16,174 @@ namespace OCA\News\Config; class AppConfigTest extends \PHPUnit_Framework_TestCase { - private $nav; - private $config; - private $url; - - public function setUp() { - $this->nav = $this->getMockBuilder('\OCP\INavigationManager') - ->disableOriginalConstructor() - ->getMock(); - $this->url = $this->getMockBuilder('\OCP\IURLGenerator') - ->disableOriginalConstructor() - ->getMock(); - $phpVersion = '5.3'; - $ownCloudVersion = '6.0.3'; - $installedExtensions = ['curl' => '4.3']; - $databaseType = 'oracle'; - - $this->config = new AppConfig($this->nav, $this->url, $phpVersion, - $ownCloudVersion, $installedExtensions, $databaseType); - } - - public function testGetId() { - $this->config->loadConfig(__DIR__ . '/../../../appinfo/app.json'); - $this->assertEquals('news', $this->config->getConfig('id')); - } - - - public function testGetConfig() { - $config = file_get_contents(__DIR__ . '/../../../appinfo/app.json'); - $config = json_decode($config, true); - $this->config->loadConfig($config); - $config['navigation'] = [ - 'id' => 'news', - 'order' => 10, - 'route' => 'news.page.index', - 'icon' => 'app.svg', - 'name' => 'News', - ]; - $this->assertEquals($config, $this->config->getConfig()); - } - - - public function testNoNavigation() { - $this->config->loadConfig([]); - - $this->nav->expects($this->never()) - ->method('add'); - } - - - public function testDefaultNavigation() { - $expected = [ - 'id' => 'news', - 'href' => 'news.page.index', - 'order' => 10, - 'icon' => 'app.svg', - 'name' => 'News' - ]; - - $this->url->expects($this->once()) - ->method('linkToRoute') - ->with($this->equalTo('news.page.index')) - ->will($this->returnValue('news.page.index')); - - $this->url->expects($this->once()) - ->method('imagePath') - ->with($this->equalTo('news'), - $this->equalTo('app.svg')) - ->will($this->returnValue('app.svg')); - - $this->nav->expects($this->once()) - ->method('add') - ->with($this->equalTo($expected)); - - $this->config->loadConfig([ - 'id' => 'news', - 'name' => 'News', - 'navigation' => [] - ]); - $this->config->registerNavigation(); - } - - - public function testCustomNavigation() { - $expected = [ - 'id' => 'abc', - 'href' => 'abc.page.index', - 'order' => 1, - 'icon' => 'test.svg', - 'name' => 'haha' - ]; - - $this->url->expects($this->once()) - ->method('linkToRoute') - ->with($this->equalTo('abc.page.index')) - ->will($this->returnValue('abc.page.index')); - - $this->url->expects($this->once()) - ->method('imagePath') - ->with($this->equalTo('abc'), - $this->equalTo('test.svg')) - ->will($this->returnValue('test.svg')); - - $this->nav->expects($this->once()) - ->method('add') - ->with($this->equalTo($expected)); - - $this->config->loadConfig([ - 'id' => 'abc', - 'name' => 'News', - 'navigation' => $expected - ]); - $this->config->registerNavigation(); - } - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testPHPVersion() { - $this->config->loadConfig([ - 'dependencies' => [ - 'php' => '5.7' - ] - ]); - $this->config->testDependencies(); - } - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testLibsVersion() { - $this->config->loadConfig([ - 'dependencies' => [ - 'libs' => [ - 'curl' => '>=4.3,<=4.3' - ] - ] - ]); - $this->config->testDependencies(); - } - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testLibsExistence() { - $this->config->loadConfig([ - 'dependencies' => [ - 'libs' => [ - 'dope' => '>=4.3,<=4.3' - ] - ] - ]); - $this->config->testDependencies(); - } - - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testSupportedDb() { - $this->config->loadConfig([ - 'dependencies' => [ - "databases" => ['pgsql', 'sqlite'] - ] - ]); - $this->config->testDependencies(); - } + private $nav; + private $config; + private $url; + + public function setUp() { + $this->nav = $this->getMockBuilder('\OCP\INavigationManager') + ->disableOriginalConstructor() + ->getMock(); + $this->url = $this->getMockBuilder('\OCP\IURLGenerator') + ->disableOriginalConstructor() + ->getMock(); + $phpVersion = '5.3'; + $ownCloudVersion = '6.0.3'; + $installedExtensions = ['curl' => '4.3']; + $databaseType = 'oracle'; + + $this->config = new AppConfig($this->nav, $this->url, $phpVersion, + $ownCloudVersion, $installedExtensions, $databaseType); + } + + public function testGetId() { + $this->config->loadConfig(__DIR__ . '/../../../appinfo/app.json'); + $this->assertEquals('news', $this->config->getConfig('id')); + } + + + public function testGetConfig() { + $config = file_get_contents(__DIR__ . '/../../../appinfo/app.json'); + $config = json_decode($config, true); + $this->config->loadConfig($config); + $config['navigation'] = [ + 'id' => 'news', + 'order' => 10, + 'route' => 'news.page.index', + 'icon' => 'app.svg', + 'name' => 'News', + ]; + $this->assertEquals($config, $this->config->getConfig()); + } + + + public function testNoNavigation() { + $this->config->loadConfig([]); + + $this->nav->expects($this->never()) + ->method('add'); + } + + + public function testDefaultNavigation() { + $expected = [ + 'id' => 'news', + 'href' => 'news.page.index', + 'order' => 10, + 'icon' => 'app.svg', + 'name' => 'News' + ]; + + $this->url->expects($this->once()) + ->method('linkToRoute') + ->with($this->equalTo('news.page.index')) + ->will($this->returnValue('news.page.index')); + + $this->url->expects($this->once()) + ->method('imagePath') + ->with($this->equalTo('news'), + $this->equalTo('app.svg')) + ->will($this->returnValue('app.svg')); + + $this->nav->expects($this->once()) + ->method('add') + ->with($this->equalTo($expected)); + + $this->config->loadConfig([ + 'id' => 'news', + 'name' => 'News', + 'navigation' => [] + ]); + $this->config->registerNavigation(); + } + + + public function testCustomNavigation() { + $expected = [ + 'id' => 'abc', + 'href' => 'abc.page.index', + 'order' => 1, + 'icon' => 'test.svg', + 'name' => 'haha' + ]; + + $this->url->expects($this->once()) + ->method('linkToRoute') + ->with($this->equalTo('abc.page.index')) + ->will($this->returnValue('abc.page.index')); + + $this->url->expects($this->once()) + ->method('imagePath') + ->with($this->equalTo('abc'), + $this->equalTo('test.svg')) + ->will($this->returnValue('test.svg')); + + $this->nav->expects($this->once()) + ->method('add') + ->with($this->equalTo($expected)); + + $this->config->loadConfig([ + 'id' => 'abc', + 'name' => 'News', + 'navigation' => $expected + ]); + $this->config->registerNavigation(); + } + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testPHPVersion() { + $this->config->loadConfig([ + 'dependencies' => [ + 'php' => '5.7' + ] + ]); + $this->config->testDependencies(); + } + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testLibsVersion() { + $this->config->loadConfig([ + 'dependencies' => [ + 'libs' => [ + 'curl' => '>=4.3,<=4.3' + ] + ] + ]); + $this->config->testDependencies(); + } + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testLibsExistence() { + $this->config->loadConfig([ + 'dependencies' => [ + 'libs' => [ + 'dope' => '>=4.3,<=4.3' + ] + ] + ]); + $this->config->testDependencies(); + } + + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testSupportedDb() { + $this->config->loadConfig([ + 'dependencies' => [ + "databases" => ['pgsql', 'sqlite'] + ] + ]); + $this->config->testDependencies(); + } } \ No newline at end of file diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php index b03eeb325..6a2b07c71 100644 --- a/tests/unit/config/ConfigTest.php +++ b/tests/unit/config/ConfigTest.php @@ -16,200 +16,200 @@ namespace OCA\News\Config; class ConfigTest extends \PHPUnit_Framework_TestCase { - private $fileSystem; - private $config; - private $configPath; - private $loggerParams; - - public function setUp() { - $this->logger = $this->getMockBuilder( - '\OCP\ILogger') - ->disableOriginalConstructor() - ->getMock(); - $this->fileSystem = $this->getMock('FileSystem', [ - 'file_get_contents', - 'file_put_contents', - 'file_exists' - ]); - $this->loggerParams = ['hi']; - $this->config = new Config($this->fileSystem, $this->logger, $this->loggerParams); - $this->configPath = 'config.json'; - } - - - public function testDefaults() { - $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); - $this->assertEquals(200, $this->config->getAutoPurgeCount()); - $this->assertEquals(30*60, $this->config->getSimplePieCacheDuration()); - $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); - $this->assertEquals(true, $this->config->getUseCronUpdates()); - $this->assertEquals(8080, $this->config->getProxyPort()); - $this->assertEquals('', $this->config->getProxyHost()); - $this->assertEquals(null, $this->config->getProxyAuth()); - $this->assertEquals('', $this->config->getProxyUser()); - $this->assertEquals('', $this->config->getProxyPassword()); - } - - - public function testRead () { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = true")); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(true, $this->config->getUseCronUpdates()); - } - - - public function testReadIgnoresVeryLowPurgeInterval () { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeMinimumInterval = 59")); - - $this->config->read($this->configPath); - - $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); - } - - - - public function testReadBool () { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = false")); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(false, $this->config->getUseCronUpdates()); - } - - - public function testReadLogsInvalidValue() { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue('autoPurgeCounts = 3')); - $this->logger->expects($this->once()) - ->method('warning') - ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . - 'does not exist. Ignored value.'), - $this->equalTo($this->loggerParams)); - - $this->config->read($this->configPath); - } - - - public function testReadLogsInvalidINI() { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue('')); - $this->logger->expects($this->once()) - ->method('warning') - ->with($this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams)); - - $this->config->read($this->configPath); - } - - - public function testWrite () { - $json = "autoPurgeMinimumInterval = 60\n" . - "autoPurgeCount = 3\n" . - "simplePieCacheDuration = 1800\n" . - "feedFetcherTimeout = 60\n" . - "useCronUpdates = true\n" . - "proxyHost = yo man\n" . - "proxyPort = 12\n" . - "proxyUser = this is a test\n". - "proxyPassword = se"; - $this->config->setAutoPurgeCount(3); - $this->config->setProxyHost("yo man"); - $this->config->setProxyPort(12); - $this->config->setProxyUser("this is a test"); - $this->config->setProxyPassword("se"); + private $fileSystem; + private $config; + private $configPath; + private $loggerParams; + + public function setUp() { + $this->logger = $this->getMockBuilder( + '\OCP\ILogger') + ->disableOriginalConstructor() + ->getMock(); + $this->fileSystem = $this->getMock('FileSystem', [ + 'file_get_contents', + 'file_put_contents', + 'file_exists' + ]); + $this->loggerParams = ['hi']; + $this->config = new Config($this->fileSystem, $this->logger, $this->loggerParams); + $this->configPath = 'config.json'; + } + + + public function testDefaults() { + $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); + $this->assertEquals(200, $this->config->getAutoPurgeCount()); + $this->assertEquals(30*60, $this->config->getSimplePieCacheDuration()); + $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); + $this->assertEquals(true, $this->config->getUseCronUpdates()); + $this->assertEquals(8080, $this->config->getProxyPort()); + $this->assertEquals('', $this->config->getProxyHost()); + $this->assertEquals(null, $this->config->getProxyAuth()); + $this->assertEquals('', $this->config->getProxyUser()); + $this->assertEquals('', $this->config->getProxyPassword()); + } + + + public function testRead () { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = true")); + + $this->config->read($this->configPath); + + $this->assertSame(3, $this->config->getAutoPurgeCount()); + $this->assertSame(true, $this->config->getUseCronUpdates()); + } + + + public function testReadIgnoresVeryLowPurgeInterval () { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue("autoPurgeMinimumInterval = 59")); + + $this->config->read($this->configPath); + + $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); + } + + + + public function testReadBool () { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = false")); + + $this->config->read($this->configPath); + + $this->assertSame(3, $this->config->getAutoPurgeCount()); + $this->assertSame(false, $this->config->getUseCronUpdates()); + } + + + public function testReadLogsInvalidValue() { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue('autoPurgeCounts = 3')); + $this->logger->expects($this->once()) + ->method('warning') + ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . + 'does not exist. Ignored value.'), + $this->equalTo($this->loggerParams)); + + $this->config->read($this->configPath); + } + + + public function testReadLogsInvalidINI() { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue('')); + $this->logger->expects($this->once()) + ->method('warning') + ->with($this->equalTo('Configuration invalid. Ignoring values.'), + $this->equalTo($this->loggerParams)); + + $this->config->read($this->configPath); + } + + + public function testWrite () { + $json = "autoPurgeMinimumInterval = 60\n" . + "autoPurgeCount = 3\n" . + "simplePieCacheDuration = 1800\n" . + "feedFetcherTimeout = 60\n" . + "useCronUpdates = true\n" . + "proxyHost = yo man\n" . + "proxyPort = 12\n" . + "proxyUser = this is a test\n". + "proxyPassword = se"; + $this->config->setAutoPurgeCount(3); + $this->config->setProxyHost("yo man"); + $this->config->setProxyPort(12); + $this->config->setProxyUser("this is a test"); + $this->config->setProxyPassword("se"); - $this->fileSystem->expects($this->once()) - ->method('file_put_contents') - ->with($this->equalTo($this->configPath), - $this->equalTo($json)); + $this->fileSystem->expects($this->once()) + ->method('file_put_contents') + ->with($this->equalTo($this->configPath), + $this->equalTo($json)); - $this->config->write($this->configPath); - } + $this->config->write($this->configPath); + } - public function testNoProxyAuthReturnsNull() { - $this->assertNull($this->config->getProxyAuth()); - } + public function testNoProxyAuthReturnsNull() { + $this->assertNull($this->config->getProxyAuth()); + } - public function testReadingNonExistentConfigWillWriteDefaults() { - $this->fileSystem->expects($this->once()) - ->method('file_exists') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue(false)); + public function testReadingNonExistentConfigWillWriteDefaults() { + $this->fileSystem->expects($this->once()) + ->method('file_exists') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue(false)); - $this->config->setUseCronUpdates(false); + $this->config->setUseCronUpdates(false); - $json = "autoPurgeMinimumInterval = 60\n" . - "autoPurgeCount = 200\n" . - "simplePieCacheDuration = 1800\n" . - "feedFetcherTimeout = 60\n" . - "useCronUpdates = false\n" . - "proxyHost = \n" . - "proxyPort = 8080\n" . - "proxyUser = \n" . - "proxyPassword = "; + $json = "autoPurgeMinimumInterval = 60\n" . + "autoPurgeCount = 200\n" . + "simplePieCacheDuration = 1800\n" . + "feedFetcherTimeout = 60\n" . + "useCronUpdates = false\n" . + "proxyHost = \n" . + "proxyPort = 8080\n" . + "proxyUser = \n" . + "proxyPassword = "; - $this->fileSystem->expects($this->once()) - ->method('file_put_contents') - ->with($this->equalTo($this->configPath), - $this->equalTo($json)); + $this->fileSystem->expects($this->once()) + ->method('file_put_contents') + ->with($this->equalTo($this->configPath), + $this->equalTo($json)); - $this->config->read($this->configPath, true); - } + $this->config->read($this->configPath, true); + } - public function testEncodesUserAndPasswordInHTTPBasicAuth() { - $this->config->setProxyUser("this is a test"); - $this->config->setProxyPassword("se"); + public function testEncodesUserAndPasswordInHTTPBasicAuth() { + $this->config->setProxyUser("this is a test"); + $this->config->setProxyPassword("se"); - $this->assertEquals('this is a test:se', $this->config->getProxyAuth()); - } + $this->assertEquals('this is a test:se', $this->config->getProxyAuth()); + } - public function testNoLowMinimumAutoPurgeInterval() { - $this->config->setAutoPurgeMinimumInterval(59); - $interval = $this->config->getAutoPurgeMinimumInterval(); + public function testNoLowMinimumAutoPurgeInterval() { + $this->config->setAutoPurgeMinimumInterval(59); + $interval = $this->config->getAutoPurgeMinimumInterval(); - $this->assertSame(60, $interval); - } - - - public function testMinimumAutoPurgeInterval() { - $this->config->setAutoPurgeMinimumInterval(61); - $interval = $this->config->getAutoPurgeMinimumInterval(); + $this->assertSame(60, $interval); + } + + + public function testMinimumAutoPurgeInterval() { + $this->config->setAutoPurgeMinimumInterval(61); + $interval = $this->config->getAutoPurgeMinimumInterval(); - $this->assertSame(61, $interval); - } + $this->assertSame(61, $interval); + } - public function testCacheDuration() { - $this->config->setSimplePieCacheDuration(21); - $duration = $this->config->getSimplePieCacheDuration(); + public function testCacheDuration() { + $this->config->setSimplePieCacheDuration(21); + $duration = $this->config->getSimplePieCacheDuration(); - $this->assertSame(21, $duration); - } + $this->assertSame(21, $duration); + } - public function testFeedFetcherTimeout() { - $this->config->setFeedFetcherTimeout(2); - $timout = $this->config->getFeedFetcherTimeout(); + public function testFeedFetcherTimeout() { + $this->config->setFeedFetcherTimeout(2); + $timout = $this->config->getFeedFetcherTimeout(); - $this->assertSame(2, $timout); - } + $this->assertSame(2, $timout); + } } \ No newline at end of file -- cgit v1.2.3