diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-09-20 22:03:05 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-25 19:18:04 +0200 |
commit | 60ab4941cc7e6ede095e9e4aee3c2bf9a5c3bff6 (patch) | |
tree | baf0b07dd1c545efeb59437af46a99f4d9f69425 /tests/Unit/Controller/PageControllerTest.php | |
parent | 2c8b4fa019749113658b9ed8cae211b679e4cbc0 (diff) |
Move to nextcloud config and update phpunit
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit/Controller/PageControllerTest.php')
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 241 |
1 files changed, 82 insertions, 159 deletions
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index ce7a3e73d..69fed0d77 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -13,7 +13,7 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; +use OC\L10N\L10N; use OCA\News\Controller\PageController; use \OCA\News\Db\FeedType; use OCA\News\Explore\RecommendedSites; @@ -28,26 +28,51 @@ use PHPUnit\Framework\TestCase; class PageControllerTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $settings; - private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var PageController + */ private $controller; - private $user; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator + */ private $urlGenerator; - private $appConfig; + + /** + * @var array + */ private $configData; - private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|RecommendedSites + */ private $recommended; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|StatusService + */ private $status; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { - $this->appName = 'news'; - $this->user = 'becka'; $this->configData = [ 'name' => 'AppTest', 'id' => 'apptest', @@ -70,12 +95,6 @@ class PageControllerTest extends TestCase $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); - $this->appConfig = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); - $this->config = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); $this->recommended = $this->getMockBuilder(RecommendedSites::class) ->disableOriginalConstructor() ->getMock(); @@ -83,10 +102,14 @@ class PageControllerTest extends TestCase ->disableOriginalConstructor() ->getMock(); $this->controller = new PageController( - $this->appName, $this->request, - $this->settings, $this->urlGenerator, $this->config, - $this->l10n, $this->recommended, $this->status, - $this->user + 'news', + $this->request, + $this->settings, + $this->urlGenerator, + $this->l10n, + $this->recommended, + $this->status, + 'becka' ); } @@ -95,15 +118,7 @@ class PageControllerTest extends TestCase { $this->status->expects($this->once()) ->method('getStatus') - ->will( - $this->returnValue( - [ - 'warnings' => [ - 'improperlyConfiguredCron' => false - ] - ] - ) - ); + ->will($this->returnValue(['warnings' => ['improperlyConfiguredCron' => false]])); $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); @@ -130,8 +145,10 @@ class PageControllerTest extends TestCase $this->assertEquals(true, $response->getParams()['warnings']['improperlyConfiguredCron']); } - - public function testSettings() + /** + * @covers \OCA\News\Controller\PageController::settings + */ + public function testSettings() { $result = [ 'settings' => [ @@ -148,55 +165,23 @@ class PageControllerTest extends TestCase $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue(' ')); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') - ->with( - $this->equalTo('news.page.explore'), - $this->equalTo(['lang' => 'en']) - ) + ->with('news.page.explore', ['lang' => 'en']) ->will($this->returnValue('test')); @@ -205,7 +190,7 @@ class PageControllerTest extends TestCase } - public function testSettingsExploreUrlSet() + public function testSettingsExploreUrlSet() { $result = [ 'settings' => [ @@ -222,48 +207,19 @@ class PageControllerTest extends TestCase $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue('abc')); $this->urlGenerator->expects($this->never()) ->method('getAbsoluteURL'); @@ -273,83 +229,50 @@ class PageControllerTest extends TestCase $this->assertEquals($result, $response); } - public function testUpdateSettings() + /** + * @covers \OCA\News\Controller\PageController::updateSettings + */ + public function testUpdateSettings() { $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'showAll', '1'); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'compact', '1'); $this->settings->expects($this->at(2)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll'), - $this->equalTo('0') - ); + ->with('becka', 'news', 'preventReadOnScroll', '0'); $this->settings->expects($this->at(3)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'oldestFirst', '1'); $this->settings->expects($this->at(4)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand'), - $this->equalTo('1') - ); - $this->controller->updateSettings(true, true, false, true, true); + ->with('becka', 'news', 'compactExpand', '1'); + $this->controller->updateSettings(true, true, false, true, true); } - public function testExplore() { $in = 'test'; $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId'), - $this->equalTo(0) - ); + ->with('becka', 'news', 'lastViewedFeedId', 0); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType'), - $this->equalTo(FeedType::EXPLORE) - ); + ->with('becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE); $this->recommended->expects($this->once()) ->method('forLanguage') - ->with($this->equalTo('en')) + ->with('en') ->will($this->returnValue($in)); - $out = $this->controller->explore('en'); $this->assertEquals($in, $out); + } } |