summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-02-17 15:17:40 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-02-17 15:17:40 +0100
commit816a8beb0b77164aa60a7fe23b4b3d0881985be3 (patch)
treedca5921f4b39b7c2c911487901dd2638a492b059 /tests
parent77365fe363729efa1d2c9c668d7dc2d35c8c6a71 (diff)
add status api route5.2.4
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/controller/PageControllerTest.php65
-rw-r--r--tests/unit/controller/UtilityApiControllerTest.php19
-rw-r--r--tests/unit/service/StatusServiceTest.php89
3 files changed, 130 insertions, 43 deletions
diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php
index fd548df62..47c85fdd9 100644
--- a/tests/unit/controller/PageControllerTest.php
+++ b/tests/unit/controller/PageControllerTest.php
@@ -29,6 +29,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
private $configData;
private $config;
private $recommended;
+ private $status;
/**
* Gets run before each test
@@ -74,64 +75,44 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
'\OCA\News\Explore\RecommendedSites')
->disableOriginalConstructor()
->getMock();
+ $this->status = $this->getMockBuilder(
+ '\OCA\News\Service\StatusService')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->controller = new PageController($this->appName, $this->request,
$this->settings, $this->urlGenerator, $this->appConfig,
- $this->config, $this->l10n, $this->recommended, $this->user);
+ $this->config, $this->l10n, $this->recommended, $this->status,
+ $this->user);
}
public function testIndex(){
- $this->config->expects($this->once())
- ->method('getUseCronUpdates')
- ->will($this->returnValue(true));
-
- $this->settings->expects($this->once())
- ->method('getAppValue')
- ->with(
- $this->equalTo('core'),
- $this->equalTo('backgroundjobs_mode')
- )
- ->will($this->returnValue('webcron'));
+ $this->status->expects($this->once())
+ ->method('getStatus')
+ ->will($this->returnValue([
+ 'warnings' => [
+ 'improperlyConfiguredCron' => false
+ ]
+ ]));
$response = $this->controller->index();
$this->assertEquals('index', $response->getTemplateName());
- $this->assertSame('', $response->getParams()['cronWarning']);
+ $this->assertSame(false, $response->getParams()['cronWarning']);
}
public function testIndexNoCorrectCronAjax(){
- $this->config->expects($this->once())
- ->method('getUseCronUpdates')
- ->will($this->returnValue(true));
-
- $this->settings->expects($this->once())
- ->method('getAppValue')
- ->with(
- $this->equalTo('core'),
- $this->equalTo('backgroundjobs_mode')
- )
- ->will($this->returnValue('ajax'));
-
- $response = $this->controller->index();
- $this->assertEquals('ajaxCron', $response->getParams()['cronWarning']);
- }
-
-
- public function testIndexNoCorrectCronTurnedOff(){
- $this->config->expects($this->once())
- ->method('getUseCronUpdates')
- ->will($this->returnValue(false));
+ $this->status->expects($this->once())
+ ->method('getStatus')
+ ->will($this->returnValue([
+ 'warnings' => [
+ 'improperlyConfiguredCron' => true
+ ]
+ ]));
- $this->settings->expects($this->once())
- ->method('getAppValue')
- ->with(
- $this->equalTo('core'),
- $this->equalTo('backgroundjobs_mode')
- )
- ->will($this->returnValue('ajax'));
$response = $this->controller->index();
- $this->assertSame('', $response->getParams()['cronWarning']);
+ $this->assertEquals(true, $response->getParams()['cronWarning']);
}
diff --git a/tests/unit/controller/UtilityApiControllerTest.php b/tests/unit/controller/UtilityApiControllerTest.php
index f4219fddf..292b8d16a 100644
--- a/tests/unit/controller/UtilityApiControllerTest.php
+++ b/tests/unit/controller/UtilityApiControllerTest.php
@@ -21,6 +21,7 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase {
private $newsAPI;
private $updater;
private $appName;
+ private $status;
protected function setUp() {
$this->appName = 'news';
@@ -36,8 +37,13 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase {
'\OCA\News\Utility\Updater')
->disableOriginalConstructor()
->getMock();
+ $this->status = $this->getMockBuilder(
+ '\OCA\News\Service\StatusService')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->newsAPI = new UtilityApiController(
- $this->appName, $this->request, $this->updater, $this->settings
+ $this->appName, $this->request, $this->updater, $this->settings,
+ $this->status
);
}
@@ -70,4 +76,15 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase {
}
+ public function testStatus(){
+ $in = 'hi';
+ $this->status->expects($this->once())
+ ->method('getStatus')
+ ->will($this->returnValue($in));
+ $result = $this->newsAPI->status();
+
+ $this->assertEquals($in, $result);
+ }
+
+
}
diff --git a/tests/unit/service/StatusServiceTest.php b/tests/unit/service/StatusServiceTest.php
new file mode 100644
index 000000000..40e2ecce9
--- /dev/null
+++ b/tests/unit/service/StatusServiceTest.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+namespace OCA\News\Service;
+
+use \OCA\News\Db\FeedType;
+
+
+class StatusServiceTest extends \PHPUnit_Framework_TestCase {
+
+ private $settings;
+ private $config;
+ private $service;
+ private $appName;
+
+ public function setUp(){
+ $this->appName = 'news';
+ $this->settings = $this->getMockBuilder(
+ '\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->config = $this->getMockBuilder(
+ '\OCA\News\Config\Config')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->service = new StatusService($this->settings, $this->config,
+ $this->appName);
+ }
+
+ private function beforeStatus($cronMode='webcron', $cronEnabled=true,
+ $version='1.0') {
+ $this->settings->expects($this->at(0))
+ ->method('getAppValue')
+ ->with($this->equalTo($this->appName),
+ $this->equalTo('installed_version'))
+ ->will($this->returnValue($version));
+
+ $this->settings->expects($this->at(1))
+ ->method('getAppValue')
+ ->with(
+ $this->equalTo('core'),
+ $this->equalTo('backgroundjobs_mode')
+ )
+ ->will($this->returnValue($cronMode));
+
+ $this->config->expects($this->once())
+ ->method('getUseCronUpdates')
+ ->will($this->returnValue($cronEnabled));
+
+ }
+
+
+ public function testGetStatus(){
+ $this->beforeStatus();
+
+ $response = $this->service->getStatus();
+ $this->assertEquals('1.0', $response['version']);
+ $this->assertFalse($response['warnings']['improperlyConfiguredCron']);
+ }
+
+
+ public function testGetStatusNoCorrectCronAjax(){
+ $this->beforeStatus('ajax');
+
+ $response = $this->service->getStatus();
+ $this->assertTrue($response['warnings']['improperlyConfiguredCron']);
+ }
+
+
+
+ public function testGetStatusNoCorrectCronTurnedOff(){
+ $this->beforeStatus('ajax', false);
+
+ $response = $this->service->getStatus();
+ $this->assertFalse($response['warnings']['improperlyConfiguredCron']);
+ }
+
+
+} \ No newline at end of file