From b6df50eada48421ea415b0964981c473567d0ff9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 22 Sep 2016 00:03:42 +0200 Subject: Add unit tests --- tests/Controller/WizardControllerTest.php | 127 ++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tests/Controller/WizardControllerTest.php (limited to 'tests/Controller') diff --git a/tests/Controller/WizardControllerTest.php b/tests/Controller/WizardControllerTest.php new file mode 100644 index 00000000..264dad4a --- /dev/null +++ b/tests/Controller/WizardControllerTest.php @@ -0,0 +1,127 @@ + + * + * @author Joas Schilling + * + * @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 . + * + */ + +namespace OCA\FirstRunWizard\Tests\Controller; + + +use OCA\FirstRunWizard\AppInfo\Application; +use OCA\FirstRunWizard\Controller\WizardController; +use OCA\FirstRunWizard\Notification\BackgroundJob; +use OCA\FirstRunWizard\Notification\Notifier; +use OCP\AppFramework\App; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\BackgroundJob\IJob; +use OCP\IConfig; +use OCP\IRequest; +use OCP\Notification\INotifier; +use Test\TestCase; + +/** + * Class WizardControllerTest + * + * @package OCA\FirstRunWizard\Tests\Controller + * @group DB + */ +class WizardControllerTest extends TestCase { + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + protected $config; + + protected function setUp() { + parent::setUp(); + $this->config = $this->createMock(IConfig::class); + } + + /** + * @param string $user + * @return WizardController + */ + protected function getController($user = 'test') { + return new WizardController( + 'firstrunwizard', + $this->createMock(IRequest::class), + $this->config, + $user + ); + } + + public function dataDisable() { + return [ + ['test1'], + ['test2'], + ]; + } + + /** + * @dataProvider dataDisable + * @param string $user + */ + public function testDisable($user) { + $controller = $this->getController($user); + + $this->config->expects($this->once()) + ->method('setUserValue') + ->with($user, 'firstrunwizard', 'show', 0); + + $response = $controller->disable(); + + $this->assertInstanceOf(DataResponse::class, $response); + $this->assertSame(Http::STATUS_OK, $response->getStatus()); + } + + public function dataShow() { + return [ + ['desktop1', 'android1', 'ios1'], + ['desktop2', 'android2', 'ios2'], + ]; + } + + /** + * @dataProvider dataShow + * @param string $desktopUrl + * @param string $androidUrl + * @param string $iosUrl + */ + public function testShow($desktopUrl, $androidUrl, $iosUrl) { + $controller = $this->getController(); + + $this->config->expects($this->exactly(3)) + ->method('getSystemValue') + ->willReturnMap([ + ['customclient_desktop', 'https://nextcloud.com/install', $desktopUrl], + ['customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client', $androidUrl], + ['customclient_ios', 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', $iosUrl], + ]); + + $response = $controller->show(); + + $this->assertInstanceOf(Http\TemplateResponse::class, $response); + $this->assertSame(Http::STATUS_OK, $response->getStatus()); + $this->assertSame([ + 'desktop' => $desktopUrl, + 'android' => $androidUrl, + 'ios' => $iosUrl, + ], $response->getParams()); + } +} -- cgit v1.2.3