diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-23 15:53:43 -0700 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-23 15:53:43 -0700 |
commit | 5fc0535f1b6d94140eed2234e4cb6e38219a74d1 (patch) | |
tree | d4249b6d88f80425721ab469754ddfb3277f3940 /tests | |
parent | 7ad38535e51812e08042e46bd550aa9cc5781955 (diff) | |
parent | 6d39e0ad6f8cc59566f83c5c9c6a227b2f569f94 (diff) | |
download | nextcloud-server-5fc0535f1b6d94140eed2234e4cb6e38219a74d1.tar.gz nextcloud-server-5fc0535f1b6d94140eed2234e4cb6e38219a74d1.zip |
Merge pull request #4090 from owncloud/cleanup-some-template-functions
Cleanup some template functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/template/resourcelocator.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/lib/template/resourcelocator.php b/tests/lib/template/resourcelocator.php new file mode 100644 index 00000000000..d80d222e2c9 --- /dev/null +++ b/tests/lib/template/resourcelocator.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_ResourceLocator extends PHPUnit_Framework_TestCase { + public function getResourceLocator( $theme, $form_factor, $core_map, $party_map, $appsroots ) { + return $this->getMockForAbstractClass('OC\Template\ResourceLocator', + array( $theme, $form_factor, $core_map, $party_map, $appsroots ), + '', true, true, true, array()); + } + + public function testConstructor() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $this->assertAttributeEquals('theme', 'theme', $locator); + $this->assertAttributeEquals('form_factor', 'form_factor', $locator); + $this->assertAttributeEquals('core', 'serverroot', $locator); + $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator); + $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator); + $this->assertAttributeEquals('map', 'webroot', $locator); + $this->assertAttributeEquals(array(), 'resources', $locator); + } + + public function testFind() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $locator->expects($this->once()) + ->method('doFind') + ->with('foo'); + $locator->expects($this->once()) + ->method('doFindTheme') + ->with('foo'); + $locator->find(array('foo')); + + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $locator->expects($this->once()) + ->method('doFind') + ->with('foo') + ->will($this->throwException(new Exception('test'))); + try { + $locator->find(array('foo')); + } catch (\Exception $e) { + $this->assertEquals('test formfactor:form_factor serverroot:core', $e->getMessage()); + } + } + + public function testAppendIfExist() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $method = new ReflectionMethod($locator, 'appendIfExist'); + $method->setAccessible(true); + + $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot'); + $resource1 = array(__DIR__, 'webroot', basename(__FILE__)); + $this->assertEquals(array($resource1), $locator->getResources()); + + $method->invoke($locator, __DIR__, basename(__FILE__)); + $resource2 = array(__DIR__, 'map', basename(__FILE__)); + $this->assertEquals(array($resource1, $resource2), $locator->getResources()); + + $method->invoke($locator, __DIR__, 'does-not-exist'); + $this->assertEquals(array($resource1, $resource2), $locator->getResources()); + } +} |