* @author Bernhard Posselt * @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); } }