diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2016-07-25 16:43:16 +0300 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2016-07-26 11:25:48 +0300 |
commit | 6af383023e3ff228e60f9eba125a9125beab8ac4 (patch) | |
tree | c63a7a2cf537738a3d2e1be619b37922f86954de /tests | |
parent | b83feb415fbe363d727f70b1dda3b35d7a281973 (diff) |
add unit testsmonitoring-api2
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 33 | ||||
-rw-r--r-- | tests/lib/Controller/ApiControllerTest.php | 124 | ||||
-rw-r--r-- | tests/phpunit.xml | 26 | ||||
-rw-r--r-- | tests/unit/controller/PageControllerTest.php | 51 |
4 files changed, 162 insertions, 72 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0e0a443..7a1d136 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,23 +1,14 @@ <?php -/** - * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -require_once __DIR__ . '/../../../tests/bootstrap.php'; -require_once __DIR__ . '/../appinfo/autoload.php'; +if (!defined('PHPUNIT_RUN')) { + define('PHPUNIT_RUN', 1); +} + +require_once __DIR__ . '/../../../lib/base.php'; + +if(!class_exists('PHPUnit_Framework_TestCase')) { + require_once('PHPUnit/Autoload.php'); +} +\OC_App::loadApp('serverinfo'); +OC_Hook::clear(); + diff --git a/tests/lib/Controller/ApiControllerTest.php b/tests/lib/Controller/ApiControllerTest.php new file mode 100644 index 0000000..29e4457 --- /dev/null +++ b/tests/lib/Controller/ApiControllerTest.php @@ -0,0 +1,124 @@ +<?php +/** + * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\ServerInfo\Tests\lib\Controller; + + +use OCA\ServerInfo\Controller\ApiController; +use OCA\ServerInfo\DatabaseStatistics; +use OCA\ServerInfo\PhpStatistics; +use OCA\ServerInfo\ShareStatistics; +use OCA\ServerInfo\StorageStatistics; +use OCA\ServerInfo\SystemStatistics; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; +use Test\TestCase; + +class ApiControllerTest extends TestCase { + + /** @var IRequest | \PHPUnit_Framework_MockObject_MockObject */ + private $request; + + /** @var SystemStatistics | \PHPUnit_Framework_MockObject_MockObject */ + private $systemStatistics; + + /** @var StorageStatistics | \PHPUnit_Framework_MockObject_MockObject */ + private $storageStatistics; + + /** @var PhpStatistics | \PHPUnit_Framework_MockObject_MockObject */ + private $phpStatistics; + + /** @var DatabaseStatistics | \PHPUnit_Framework_MockObject_MockObject */ + private $databaseStatistics; + + /** @var ShareStatistics | \PHPUnit_Framework_MockObject_MockObject */ + private $shareStatistics; + + /** @var ApiController */ + private $instance; + + public function setUp() { + parent::setUp(); + + $this->request = $this->getMockBuilder('OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); + + $this->systemStatistics = $this->getMockBuilder('OCA\ServerInfo\SystemStatistics') + ->disableOriginalConstructor() + ->getMock(); + + $this->storageStatistics = $this->getMockBuilder('OCA\ServerInfo\StorageStatistics') + ->disableOriginalConstructor() + ->getMock(); + + $this->phpStatistics = $this->getMockBuilder('OCA\ServerInfo\PhpStatistics') + ->disableOriginalConstructor() + ->getMock(); + + $this->databaseStatistics = $this->getMockBuilder('OCA\ServerInfo\DatabaseStatistics') + ->disableOriginalConstructor() + ->getMock(); + + $this->shareStatistics = $this->getMockBuilder('OCA\ServerInfo\ShareStatistics') + ->disableOriginalConstructor() + ->getMock(); + + $this->instance = new ApiController( + 'ServerInfoTest', + $this->request, + $this->systemStatistics, + $this->storageStatistics, + $this->phpStatistics, + $this->databaseStatistics, + $this->shareStatistics + ); + } + + public function testInfo() { + + $this->systemStatistics->expects($this->once())->method('getSystemStatistics') + ->willReturn('systemStatistics'); + $this->storageStatistics->expects($this->once())->method('getStorageStatistics') + ->willReturn('storageStatistics'); + $this->phpStatistics->expects($this->once())->method('getPhpStatistics') + ->willReturn('phpStatistics'); + $this->databaseStatistics->expects($this->once())->method('getDatabaseStatistics') + ->willReturn('databaseStatistics'); + $this->shareStatistics->expects($this->once())->method('getShareStatistics') + ->willReturn('shareStatistics'); + + $result = $this->instance->info(); + $this->assertTrue($result instanceof DataResponse); + $data = $result->getData(); + $this->assertTrue(isset($data['data']['nextcloud'])); + $this->assertTrue(isset($data['data']['server'])); + + $this->assertSame('systemStatistics', $data['data']['nextcloud']['system']); + $this->assertSame('storageStatistics', $data['data']['nextcloud']['storage']); + $this->assertSame('shareStatistics', $data['data']['nextcloud']['shares']); + $this->assertSame('unknown', $data['data']['server']['webserver']); + $this->assertSame('databaseStatistics', $data['data']['server']['database']); + $this->assertSame('phpStatistics', $data['data']['server']['php']); + } + +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..b61d393 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8" ?> +<phpunit bootstrap="bootstrap.php" + verbose="true" + timeoutForSmallTests="900" + timeoutForMediumTests="900" + timeoutForLargeTests="900" + > + <testsuite name='Nextcloud - ServerInfo Tests'> + <directory suffix='Test.php'>.</directory> + </testsuite> + <!-- filters for code coverage --> + <filter> + <whitelist> + <directory suffix=".php">../../serverinfo/lib</directory> + <exclude> + <directory suffix=".php">../../serverinfo/l10n</directory> + <directory suffix=".php">../../serverinfo/lists</directory> + <directory suffix=".php">../../serverinfo/tests</directory> + </exclude> + </whitelist> + </filter> + <logging> + <!-- and this is where your report will be written --> + <log type="coverage-clover" target="./clover.xml"/> + </logging> +</phpunit> diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php deleted file mode 100644 index a20bcc2..0000000 --- a/tests/unit/controller/PageControllerTest.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\ServerInfo\Controller; - -use PHPUnit_Framework_TestCase; - -use OCP\AppFramework\Http\TemplateResponse; - - -class PageControllerTest extends PHPUnit_Framework_TestCase { - - private $controller; - private $userId = 'john'; - - public function setUp() { - $request = $this->getMockBuilder('OCP\IRequest')->getMock(); - - $this->controller = new PageController( - 'serverinfo', $request, $this->userId - ); - } - - - public function testIndex() { - $result = $this->controller->index(); - - $this->assertEquals(['user' => 'john'], $result->getParams()); - $this->assertEquals('main', $result->getTemplateName()); - $this->assertTrue($result instanceof TemplateResponse); - } - -} |