1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-05-14 13:34:05 +02:00
Nextcloud-News/tests/Unit/Service/StatusServiceTest.php
Sean Molenaar 60ab4941cc Move to nextcloud config and update phpunit
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
2020-09-25 19:18:04 +02:00

194 lines
5.8 KiB
PHP

<?php
/**
* Nextcloud - 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 2012 Alessandro Cosentino
* @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Tests\Unit\Service;
use OCA\News\Service\StatusService;
use OCP\IConfig;
use OCP\IDBConnection;
use PHPUnit\Framework\TestCase;
class StatusServiceTest extends TestCase
{
/**
* @var \PHPUnit\Framework\MockObject\MockObject|IConfig
*/
private $settings;
/**
* @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection
*/
private $connection;
/**
* @var StatusService
*/
private $service;
public function setUp(): void
{
$this->settings = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
$this->connection = $this->getMockBuilder(IDBConnection::class)
->disableOriginalConstructor()
->getMock();
$this->service = new StatusService($this->settings, $this->connection, 'news');
}
/**
* @covers \OCA\News\Service\StatusService::getStatus
*/
public function testGetStatus()
{
$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($expected, $response);
}
/**
* @covers \OCA\News\Service\StatusService::getStatus
*/
public function testGetStatusNoCorrectCronAjax()
{
$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->assertEquals($expected, $response);
}
/**
* @covers \OCA\News\Service\StatusService::getStatus
*/
public function testGetStatusNoCorrectCronTurnedOff()
{
$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->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);
}
}