summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Service/StatusServiceTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Service/StatusServiceTest.php')
-rw-r--r--tests/Unit/Service/StatusServiceTest.php197
1 files changed, 143 insertions, 54 deletions
diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php
index 8c42997a0..ee2e19614 100644
--- a/tests/Unit/Service/StatusServiceTest.php
+++ b/tests/Unit/Service/StatusServiceTest.php
@@ -13,8 +13,6 @@
namespace OCA\News\Tests\Unit\Service;
-use OCA\News\Config\Config;
-use \OCA\News\Db\FeedType;
use OCA\News\Service\StatusService;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -23,83 +21,174 @@ use PHPUnit\Framework\TestCase;
class StatusServiceTest extends TestCase
{
-
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IConfig
+ */
private $settings;
- private $config;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection
+ */
+ private $connection;
+
+ /**
+ * @var StatusService
+ */
private $service;
- private $appName;
- public function setUp()
+ public function setUp(): void
{
- $this->appName = 'news';
$this->settings = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
- $this->config = $this->getMockBuilder(Config::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->db = $this->getMockBuilder(IDBConnection::class)
+ $this->connection = $this->getMockBuilder(IDBConnection::class)
->disableOriginalConstructor()
->getMock();
- $this->service = new StatusService(
- $this->settings, $this->db,
- $this->config, $this->appName
- );
- }
-
- private function beforeStatus($cronMode='cron', $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));
-
+ $this->service = new StatusService($this->settings, $this->connection, 'news');
}
-
+ /**
+ * @covers \OCA\News\Service\StatusService::getStatus
+ */
public function testGetStatus()
{
- $this->beforeStatus();
-
+ $this->settings->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->withConsecutive(
+ ['news', 'installed_version'],
+ ['news', 'useCronUpdates']
+ )
+ ->will($this->returnValueMap([
+ ['news', 'installed_version', '', '1.0'],
+ ['news', 'useCronUpdates', true, true],
+ ]));
+
+ $this->settings->expects($this->exactly(1))
+ ->method('getSystemValue')
+ ->with('backgroundjobs_mode')
+ ->will($this->returnValue('cron'));
+
+ $this->connection->expects($this->exactly(1))
+ ->method('supports4ByteText')
+ ->will($this->returnValue(true));
+
+ $expected = [
+ 'version' => '1.0',
+ 'warnings' => [
+ 'improperlyConfiguredCron' => false,
+ 'incorrectDbCharset' => false,
+ ],
+ ];
$response = $this->service->getStatus();
- $this->assertEquals('1.0', $response['version']);
- $this->assertFalse($response['warnings']['improperlyConfiguredCron']);
+ $this->assertEquals($expected, $response);
}
-
+ /**
+ * @covers \OCA\News\Service\StatusService::getStatus
+ */
public function testGetStatusNoCorrectCronAjax()
{
- $this->beforeStatus('ajax');
-
+ $this->settings->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->withConsecutive(
+ ['news', 'installed_version'],
+ ['news', 'useCronUpdates']
+ )
+ ->will($this->returnValueMap([
+ ['news', 'installed_version', '', '1.0'],
+ ['news', 'useCronUpdates', true, true],
+ ]));
+
+ $this->settings->expects($this->exactly(1))
+ ->method('getSystemValue')
+ ->with('backgroundjobs_mode')
+ ->will($this->returnValue('ajax'));
+
+ $this->connection->expects($this->exactly(1))
+ ->method('supports4ByteText')
+ ->will($this->returnValue(true));
+
+ $expected = [
+ 'version' => '1.0',
+ 'warnings' => [
+ 'improperlyConfiguredCron' => true,
+ 'incorrectDbCharset' => false,
+ ],
+ ];
$response = $this->service->getStatus();
- $this->assertTrue($response['warnings']['improperlyConfiguredCron']);
+ $this->assertEquals($expected, $response);
}
-
-
+ /**
+ * @covers \OCA\News\Service\StatusService::getStatus
+ */
public function testGetStatusNoCorrectCronTurnedOff()
{
- $this->beforeStatus('ajax', false);
-
+ $this->settings->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->withConsecutive(
+ ['news', 'installed_version'],
+ ['news', 'useCronUpdates']
+ )
+ ->will($this->returnValueMap([
+ ['news', 'installed_version', '', '1.0'],
+ ['news', 'useCronUpdates', true, false],
+ ]));
+
+ $this->settings->expects($this->exactly(1))
+ ->method('getSystemValue')
+ ->with('backgroundjobs_mode')
+ ->will($this->returnValue('ajax'));
+
+ $this->connection->expects($this->exactly(1))
+ ->method('supports4ByteText')
+ ->will($this->returnValue(true));
+
+ $expected = [
+ 'version' => '1.0',
+ 'warnings' => [
+ 'improperlyConfiguredCron' => false,
+ 'incorrectDbCharset' => false,
+ ],
+ ];
$response = $this->service->getStatus();
- $this->assertFalse($response['warnings']['improperlyConfiguredCron']);
+ $this->assertEquals($expected, $response);
}
+ /**
+ * @covers \OCA\News\Service\StatusService::getStatus
+ */
+ public function testGetStatusReportsNon4ByteText()
+ {
+ $this->settings->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->withConsecutive(
+ ['news', 'installed_version'],
+ ['news', 'useCronUpdates']
+ )
+ ->will($this->returnValueMap([
+ ['news', 'installed_version', '', '1.0'],
+ ['news', 'useCronUpdates', true, false],
+ ]));
+
+ $this->settings->expects($this->exactly(1))
+ ->method('getSystemValue')
+ ->with('backgroundjobs_mode')
+ ->will($this->returnValue('ajax'));
+
+ $this->connection->expects($this->exactly(1))
+ ->method('supports4ByteText')
+ ->will($this->returnValue(false));
+
+ $expected = [
+ 'version' => '1.0',
+ 'warnings' => [
+ 'improperlyConfiguredCron' => false,
+ 'incorrectDbCharset' => true,
+ ],
+ ];
+ $response = $this->service->getStatus();
+ $this->assertEquals($expected, $response);
+ }
} \ No newline at end of file