diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/CheckSetupControllerTest.php | 85 | ||||
-rw-r--r-- | tests/lib/Http/Client/ClientTest.php | 127 |
2 files changed, 201 insertions, 11 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index f0e19e007f2..c062dff0704 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -21,6 +21,7 @@ namespace Tests\Settings\Controller; +use OC\DB\Connection; use OC\Settings\Controller\CheckSetupController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDisplayResponse; @@ -28,11 +29,13 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OC_Util; +use OCP\Lock\ILockingProvider; use Psr\Http\Message\ResponseInterface; use Symfony\Component\EventDispatcher\EventDispatcher; use Test\TestCase; @@ -64,6 +67,12 @@ class CheckSetupControllerTest extends TestCase { private $checker; /** @var EventDispatcher|\PHPUnit_Framework_MockObject_MockObject */ private $dispatcher; + /** @var Connection|\PHPUnit_Framework_MockObject_MockObject */ + private $db; + /** @var ILockingProvider|\PHPUnit_Framework_MockObject_MockObject */ + private $lockingProvider; + /** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */ + private $dateTimeFormatter; public function setUp() { parent::setUp(); @@ -90,6 +99,10 @@ class CheckSetupControllerTest extends TestCase { $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); + $this->db = $this->getMockBuilder(Connection::class) + ->disableOriginalConstructor()->getMock(); + $this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock(); + $this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock(); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ 'settings', @@ -102,8 +115,11 @@ class CheckSetupControllerTest extends TestCase { $this->checker, $this->logger, $this->dispatcher, + $this->db, + $this->lockingProvider, + $this->dateTimeFormatter, ]) - ->setMethods(['getCurlVersion', 'isPhpOutdated', 'isOpcacheProperlySetup', 'hasFreeTypeSupport', 'hasMissingIndexes', 'isSqliteUsed'])->getMock(); + ->setMethods(['isReadOnlyConfig', 'hasValidTransactionIsolationLevel', 'hasFileinfoInstalled', 'hasWorkingFileLocking', 'getLastCronInfo', 'getSuggestedOverwriteCliURL', 'getOutdatedCaches', 'getCurlVersion', 'isPhpOutdated', 'isOpcacheProperlySetup', 'hasFreeTypeSupport', 'hasMissingIndexes', 'isSqliteUsed'])->getMock(); } public function testIsInternetConnectionWorkingDisabledViaConfig() { @@ -263,21 +279,21 @@ class CheckSetupControllerTest extends TestCase { public function testCheck() { $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('has_internet_connection', true) - ->will($this->returnValue(true)); - $this->config->expects($this->at(1)) + ->method('getAppValue') + ->with('core', 'cronErrors') + ->willReturn(''); + $this->config->expects($this->at(2)) ->method('getSystemValue') ->with('memcache.local', null) ->will($this->returnValue('SomeProvider')); - $this->config->expects($this->at(2)) + $this->config->expects($this->at(3)) ->method('getSystemValue') ->with('has_internet_connection', true) - ->will($this->returnValue(false)); - $this->config->expects($this->at(3)) + ->will($this->returnValue(true)); + $this->config->expects($this->at(4)) ->method('getSystemValue') - ->with('trusted_proxies', []) - ->willReturn(['1.2.3.4']); + ->with('appstoreenabled', true) + ->will($this->returnValue(false)); $this->request->expects($this->once()) ->method('getRemoteAddress') @@ -343,11 +359,55 @@ class CheckSetupControllerTest extends TestCase { ->method('hasMissingIndexes') ->willReturn([]); $this->checkSetupController + ->method('getOutdatedCaches') + ->willReturn([]); + $this->checkSetupController ->method('isSqliteUsed') ->willReturn(false); + $this->checkSetupController + ->expects($this->once()) + ->method('isReadOnlyConfig') + ->willReturn(false); + $this->checkSetupController + ->expects($this->once()) + ->method('hasValidTransactionIsolationLevel') + ->willReturn(true); + $this->checkSetupController + ->expects($this->once()) + ->method('hasFileinfoInstalled') + ->willReturn(true); + $this->checkSetupController + ->expects($this->once()) + ->method('hasWorkingFileLocking') + ->willReturn(true); + $this->checkSetupController + ->expects($this->once()) + ->method('getSuggestedOverwriteCliURL') + ->willReturn(''); + $this->checkSetupController + ->expects($this->once()) + ->method('getLastCronInfo') + ->willReturn([ + 'diffInSeconds' => 123, + 'relativeTime' => '2 hours ago', + 'backgroundJobsUrl' => 'https://example.org', + ]); $expected = new DataResponse( [ + 'isGetenvServerWorking' => true, + 'isReadOnlyConfig' => false, + 'hasValidTransactionIsolationLevel' => true, + 'outdatedCaches' => [], + 'hasFileinfoInstalled' => true, + 'hasWorkingFileLocking' => true, + 'suggestedOverwriteCliURL' => '', + 'cronInfo' => [ + 'diffInSeconds' => 123, + 'relativeTime' => '2 hours ago', + 'backgroundJobsUrl' => 'https://example.org', + ], + 'cronErrors' => '', 'serverHasInternetConnection' => false, 'isMemcacheConfigured' => true, 'memcacheDocs' => 'http://docs.example.org/server/go.php?to=admin-performance', @@ -367,9 +427,9 @@ class CheckSetupControllerTest extends TestCase { 'phpOpcacheDocumentation' => 'http://docs.example.org/server/go.php?to=admin-php-opcache', 'isSettimelimitAvailable' => true, 'hasFreeTypeSupport' => false, - 'hasMissingIndexes' => [], 'isSqliteUsed' => false, 'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion', + 'missingIndexes' => [], ] ); $this->assertEquals($expected, $this->checkSetupController->check()); @@ -388,6 +448,9 @@ class CheckSetupControllerTest extends TestCase { $this->checker, $this->logger, $this->dispatcher, + $this->db, + $this->lockingProvider, + $this->dateTimeFormatter, ]) ->setMethods(null)->getMock(); diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index ec4ca6ec90c..7f12a824d17 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -27,6 +27,8 @@ class ClientTest extends \Test\TestCase { private $client; /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; + /** @var array */ + private $defaultRequestOptions; public function setUp() { parent::setUp(); @@ -85,42 +87,167 @@ class ClientTest extends \Test\TestCase { $this->assertSame('username:password@foo', self::invokePrivate($this->client, 'getProxyUri')); } + private function setUpDefaultRequestOptions() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('proxy', null) + ->willReturn('foo'); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('proxyuserpwd', null) + ->willReturn(null); + $this->certificateManager + ->expects($this->once()) + ->method('getAbsoluteBundlePath') + ->with(null) + ->willReturn('/my/path.crt'); + + $this->defaultRequestOptions = [ + 'verify' => '/my/path.crt', + 'proxy' => 'foo' + ]; + } + public function testGet() { + $this->setUpDefaultRequestOptions(); + $this->guzzleClient->method('request') + ->with('get', 'http://localhost/', $this->defaultRequestOptions) ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->get('http://localhost/', [])->getStatusCode()); } + public function testGetWithOptions() { + $this->setUpDefaultRequestOptions(); + + $options = [ + 'verify' => false, + 'proxy' => 'bar' + ]; + + $this->guzzleClient->method('request') + ->with('get', 'http://localhost/', $options) + ->willReturn(new Response(1337)); + $this->assertEquals(1337, $this->client->get('http://localhost/', $options)->getStatusCode()); + } + public function testPost() { + $this->setUpDefaultRequestOptions(); + $this->guzzleClient->method('request') + ->with('post', 'http://localhost/', $this->defaultRequestOptions) ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->post('http://localhost/', [])->getStatusCode()); } + public function testPostWithOptions() { + $this->setUpDefaultRequestOptions(); + + $options = [ + 'verify' => false, + 'proxy' => 'bar' + ]; + + $this->guzzleClient->method('request') + ->with('post', 'http://localhost/', $options) + ->willReturn(new Response(1337)); + $this->assertEquals(1337, $this->client->post('http://localhost/', $options)->getStatusCode()); + } + public function testPut() { + $this->setUpDefaultRequestOptions(); + $this->guzzleClient->method('request') + ->with('put', 'http://localhost/', $this->defaultRequestOptions) ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->put('http://localhost/', [])->getStatusCode()); } + public function testPutWithOptions() { + $this->setUpDefaultRequestOptions(); + + $options = [ + 'verify' => false, + 'proxy' => 'bar' + ]; + + $this->guzzleClient->method('request') + ->with('put', 'http://localhost/', $options) + ->willReturn(new Response(1337)); + $this->assertEquals(1337, $this->client->put('http://localhost/', $options)->getStatusCode()); + } + public function testDelete() { + $this->setUpDefaultRequestOptions(); + $this->guzzleClient->method('request') + ->with('delete', 'http://localhost/', $this->defaultRequestOptions) ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->delete('http://localhost/', [])->getStatusCode()); } + public function testDeleteWithOptions() { + $this->setUpDefaultRequestOptions(); + + $options = [ + 'verify' => false, + 'proxy' => 'bar' + ]; + + $this->guzzleClient->method('request') + ->with('delete', 'http://localhost/', $options) + ->willReturn(new Response(1337)); + $this->assertEquals(1337, $this->client->delete('http://localhost/', $options)->getStatusCode()); + } + public function testOptions() { + $this->setUpDefaultRequestOptions(); + $this->guzzleClient->method('request') + ->with('options', 'http://localhost/', $this->defaultRequestOptions) ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode()); } + public function testOptionsWithOptions() { + $this->setUpDefaultRequestOptions(); + + $options = [ + 'verify' => false, + 'proxy' => 'bar' + ]; + + $this->guzzleClient->method('request') + ->with('options', 'http://localhost/', $options) + ->willReturn(new Response(1337)); + $this->assertEquals(1337, $this->client->options('http://localhost/', $options)->getStatusCode()); + } + public function testHead() { + $this->setUpDefaultRequestOptions(); + $this->guzzleClient->method('request') + ->with('head', 'http://localhost/', $this->defaultRequestOptions) ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->head('http://localhost/', [])->getStatusCode()); } + public function testHeadWithOptions() { + $this->setUpDefaultRequestOptions(); + + $options = [ + 'verify' => false, + 'proxy' => 'bar' + ]; + + $this->guzzleClient->method('request') + ->with('head', 'http://localhost/', $options) + ->willReturn(new Response(1337)); + $this->assertEquals(1337, $this->client->head('http://localhost/', $options)->getStatusCode()); + } + public function testSetDefaultOptionsWithNotInstalled() { $this->config ->expects($this->at(0)) |