Blame view

sources/tests/lib/template/resourcelocator.php 2.77 KB
f7d878ff1   kload   [enh] Update to 7...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  <?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 {
  
  	/**
  	 * @param string $theme
  	 * @param string $form_factor
  	 */
  	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());
  	}
  }