diff options
Diffstat (limited to 'apps/theming/tests')
-rw-r--r-- | apps/theming/tests/CapabilitiesTest.php | 61 | ||||
-rw-r--r-- | apps/theming/tests/Controller/ThemingControllerTest.php | 7 | ||||
-rw-r--r-- | apps/theming/tests/IconBuilderTest.php | 14 | ||||
-rw-r--r-- | apps/theming/tests/UtilTest.php | 37 |
4 files changed, 73 insertions, 46 deletions
diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php index 1c379797736..55f40cb788a 100644 --- a/apps/theming/tests/CapabilitiesTest.php +++ b/apps/theming/tests/CapabilitiesTest.php @@ -22,17 +22,9 @@ namespace OCA\Theming\Tests; use OCA\Theming\Capabilities; -use OCA\Theming\Controller\ThemingController; -use OCA\Theming\Settings\Admin; -use OCA\Theming\Settings\Section; use OCA\Theming\ThemingDefaults; -use OCA\Theming\Util; -use OCP\AppFramework\App; -use OCP\Capabilities\ICapability; -use OCP\IL10N; +use OCP\IConfig; use OCP\IURLGenerator; -use OCP\Settings\ISection; -use OCP\Settings\ISettings; use Test\TestCase; /** @@ -48,19 +40,19 @@ class CapabilitiesTest extends TestCase { /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ protected $url; + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + protected $config; + /** @var Capabilities */ protected $capabilities; protected function setUp() { parent::setUp(); - $this->theming = $this->getMockBuilder(ThemingDefaults::class) - ->disableOriginalConstructor() - ->getMock(); - $this->url = $this->getMockBuilder(IURLGenerator::class) - ->getMock(); - - $this->capabilities = new Capabilities($this->theming, $this->url); + $this->theming = $this->createMock(ThemingDefaults::class); + $this->url = $this->getMockBuilder(IURLGenerator::class)->getMock(); + $this->config = $this->createMock(IConfig::class); + $this->capabilities = new Capabilities($this->theming, $this->url, $this->config); } public function dataGetCapabilities() { @@ -81,6 +73,14 @@ class CapabilitiesTest extends TestCase { 'logo' => 'http://localhost/logo5', 'background' => 'http://localhost/background6', ]], + ['name1', 'url2', 'slogan3', 'color4', 'logo5', 'backgroundColor', 'http://localhost/', [ + 'name' => 'name1', + 'url' => 'url2', + 'slogan' => 'slogan3', + 'color' => 'color4', + 'logo' => 'http://localhost/logo5', + 'background' => 'color4', + ]], ]; } @@ -96,6 +96,9 @@ class CapabilitiesTest extends TestCase { * @param string[] $expected */ public function testGetCapabilities($name, $url, $slogan, $color, $logo, $background, $baseUrl, array $expected) { + $this->config->expects($this->once()) + ->method('getAppValue') + ->willReturn($background); $this->theming->expects($this->once()) ->method('getName') ->willReturn($name); @@ -105,21 +108,29 @@ class CapabilitiesTest extends TestCase { $this->theming->expects($this->once()) ->method('getSlogan') ->willReturn($slogan); - $this->theming->expects($this->once()) + $this->theming->expects($this->atLeast(1)) ->method('getColorPrimary') ->willReturn($color); $this->theming->expects($this->once()) ->method('getLogo') ->willReturn($logo); - $this->theming->expects($this->once()) - ->method('getBackground') - ->willReturn($background); - $this->url->expects($this->exactly(2)) - ->method('getAbsoluteURL') - ->willReturnCallback(function($url) use($baseUrl) { - return $baseUrl . $url; - }); + if($background !== 'backgroundColor') { + $this->theming->expects($this->once()) + ->method('getBackground') + ->willReturn($background); + $this->url->expects($this->exactly(2)) + ->method('getAbsoluteURL') + ->willReturnCallback(function($url) use($baseUrl) { + return $baseUrl . $url; + }); + } else { + $this->url->expects($this->once()) + ->method('getAbsoluteURL') + ->willReturnCallback(function($url) use($baseUrl) { + return $baseUrl . $url; + }); + } $this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities()); } diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index cbdb86d0358..5fa8dc51939 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -62,8 +62,6 @@ class ThemingControllerTest extends TestCase { private $l10n; /** @var ThemingController */ private $themingController; - /** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */ - private $rootFolder; /** @var ITempManager */ private $tempManager; /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */ @@ -79,14 +77,13 @@ class ThemingControllerTest extends TestCase { $this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->l10n = $this->createMock(L10N::class); - $this->rootFolder = $this->createMock(IRootFolder::class); + $this->appData = $this->createMock(IAppData::class); $this->appManager = $this->createMock(IAppManager::class); - $this->util = new Util($this->config, $this->rootFolder, $this->appManager); + $this->util = new Util($this->config, $this->appManager, $this->appData); $this->timeFactory->expects($this->any()) ->method('getTime') ->willReturn(123); $this->tempManager = \OC::$server->getTempManager(); - $this->appData = $this->createMock(IAppData::class); $this->scssCacher = $this->createMock(SCSSCacher::class); $this->themingController = new ThemingController( diff --git a/apps/theming/tests/IconBuilderTest.php b/apps/theming/tests/IconBuilderTest.php index 423e3e86dbc..9b5b1933201 100644 --- a/apps/theming/tests/IconBuilderTest.php +++ b/apps/theming/tests/IconBuilderTest.php @@ -27,7 +27,9 @@ use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; use OCP\App\IAppManager; use OCP\AppFramework\Http\NotFoundResponse; +use OCP\Files\IAppData; use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; use OCP\IConfig; use Test\TestCase; @@ -35,8 +37,8 @@ class IconBuilderTest extends TestCase { /** @var IConfig */ protected $config; - /** @var IRootFolder */ - protected $rootFolder; + /** @var IAppData */ + protected $appData; /** @var ThemingDefaults */ protected $themingDefaults; /** @var Util */ @@ -50,11 +52,11 @@ class IconBuilderTest extends TestCase { parent::setUp(); $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); - $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); + $this->appData = $this->createMock(IAppData::class); $this->themingDefaults = $this->getMockBuilder('OCA\Theming\ThemingDefaults') ->disableOriginalConstructor()->getMock(); $this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock(); - $this->util = new Util($this->config, $this->rootFolder, $this->appManager); + $this->util = new Util($this->config, $this->appManager, $this->appData); $this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util); } @@ -89,6 +91,10 @@ class IconBuilderTest extends TestCase { $this->themingDefaults->expects($this->once()) ->method('getColorPrimary') ->willReturn($color); + $this->appData->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willThrowException(new NotFoundException()); $expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file); $icon = $this->iconBuilder->renderAppIcon($app, 512); diff --git a/apps/theming/tests/UtilTest.php b/apps/theming/tests/UtilTest.php index 83895208fea..de6690ffe0d 100644 --- a/apps/theming/tests/UtilTest.php +++ b/apps/theming/tests/UtilTest.php @@ -24,6 +24,10 @@ namespace OCA\Theming\Tests; use OCA\Theming\Util; use OCP\App\IAppManager; +use OCP\Files\IAppData; +use OCP\Files\NotFoundException; +use OCP\Files\SimpleFS\ISimpleFile; +use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\Files\IRootFolder; use Test\TestCase; @@ -34,17 +38,17 @@ class UtilTest extends TestCase { protected $util; /** @var IConfig */ protected $config; - /** @var IRootFolder */ - protected $rootFolder; + /** @var IAppData */ + protected $appData; /** @var IAppManager */ protected $appManager; protected function setUp() { parent::setUp(); - $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); - $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); - $this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock(); - $this->util = new Util($this->config, $this->rootFolder, $this->appManager); + $this->config = $this->createMock(IConfig::class); + $this->appData = $this->createMock(IAppData::class); + $this->appManager = $this->createMock(IAppManager::class); + $this->util = new Util($this->config, $this->appManager, $this->appData); } public function testInvertTextColorLight() { @@ -112,6 +116,10 @@ class UtilTest extends TestCase { * @dataProvider dataGetAppIcon */ public function testGetAppIcon($app, $expected) { + $this->appData->expects($this->any()) + ->method('getFolder') + ->with('images') + ->willThrowException(new NotFoundException()); $this->appManager->expects($this->once()) ->method('getAppPath') ->with($app) @@ -129,13 +137,18 @@ class UtilTest extends TestCase { } public function testGetAppIconThemed() { - $this->rootFolder->expects($this->once()) - ->method('nodeExists') - ->with('/themedinstancelogo') - ->willReturn(true); - $expected = '/themedinstancelogo'; + $file = $this->createMock(ISimpleFile::class); + $folder = $this->createMock(ISimpleFolder::class); + $folder->expects($this->once()) + ->method('getFile') + ->with('logo') + ->willReturn($file); + $this->appData->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willReturn($folder); $icon = $this->util->getAppIcon('noapplikethis'); - $this->assertEquals($expected, $icon); + $this->assertEquals($file, $icon); } /** |