Skip to content

Commit 3cdbebc

Browse files
committed
Added extra tests for theme resolver
1 parent 061ee16 commit 3cdbebc

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

src/Ladybug/Theme/ThemeResolver.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ public function getTheme($key, $format)
8686
}
8787

8888
$parent = $theme->getParent();
89-
if (is_null($parent)) {
90-
return false;
91-
}
9289

93-
$theme = $this->themes['theme_'.strtolower($parent)];
90+
$theme = is_null($parent) ? null : $this->themes['theme_'.strtolower($parent)];
9491

9592
}
9693

94+
return false;
9795
}
9896

9997
protected function supportsFormat(ThemeInterface $theme, $format)
@@ -112,7 +110,7 @@ protected function getDefaultTheme()
112110
return $this->themes[$this->default];
113111
}
114112

115-
return null;
113+
return false;
116114
}
117115

118116
/**

tests/Ladybug/Tests/Theme/ThemeResolverTest.php

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Ladybug\Theme\ThemeResolver;
66
use Ladybug\Theme\ThemeInterface;
77
use Ladybug\Format\HtmlFormat;
8+
use Ladybug\Format\ConsoleFormat;
9+
use Ladybug\Format\XmlFormat;
810
use \Mockery as m;
911

1012
class ThemeResolverTest extends \PHPUnit_Framework_TestCase
@@ -13,14 +15,22 @@ class ThemeResolverTest extends \PHPUnit_Framework_TestCase
1315
/** @var ThemeResolver */
1416
protected $resolver;
1517

16-
protected $theme;
18+
protected $baseTheme;
19+
protected $htmlTheme;
1720

1821
public function setUp()
1922
{
2023
$this->resolver = new ThemeResolver();
2124

22-
$this->theme = m::mock('Ladybug\Theme\ThemeInterface');
23-
$this->theme->shouldReceive('getFormats')->andReturn(array(HtmlFormat::FORMAT_NAME));
25+
$this->baseTheme = m::mock('Ladybug\Theme\ThemeInterface');
26+
$this->baseTheme->shouldReceive('getFormats')->andReturn(array(
27+
HtmlFormat::FORMAT_NAME,
28+
ConsoleFormat::FORMAT_NAME
29+
));
30+
$this->baseTheme->shouldReceive('getParent')->andReturn(null);
31+
32+
$this->htmlTheme = m::mock('Ladybug\Theme\HtmlThemeInterface');
33+
$this->htmlTheme->shouldReceive('getFormats')->andReturn(array(HtmlFormat::FORMAT_NAME));
2434
}
2535

2636
public function tearDown()
@@ -30,26 +40,53 @@ public function tearDown()
3040

3141
public function testAddTheme()
3242
{
33-
$result = $this->resolver->addTheme($this->theme, 'theme_test');
43+
$result = $this->resolver->addTheme($this->htmlTheme, 'theme_test');
3444

3545
$this->assertTrue($result);
3646
$this->assertCount(1, $this->resolver);
3747
}
3848

3949
public function testGetRegisteredTheme()
4050
{
41-
$this->resolver->addTheme($this->theme, 'theme_test');
51+
$this->resolver->addTheme($this->htmlTheme, 'theme_test');
4252

4353
$this->assertInstanceOf('Ladybug\Theme\ThemeInterface', $this->resolver->getTheme('test', 'html'));
4454
}
4555

4656
public function testGetDefaultThemeWhenDoesNotExist()
4757
{
48-
$this->resolver->addTheme($this->theme, 'theme_test');
49-
$this->resolver->addTheme($this->theme, 'theme_test_default', true);
58+
$this->resolver->addTheme($this->htmlTheme, 'theme_test');
59+
$this->resolver->addTheme($this->htmlTheme, 'theme_test_default', true);
5060

5161
$this->assertInstanceOf('Ladybug\Theme\ThemeInterface', $this->resolver->getTheme('notfound', HtmlFormat::FORMAT_NAME));
5262
}
5363

64+
public function testGetFalseWhenDoesNotExistAndNoDefaultTheme()
65+
{
66+
$this->resolver->addTheme($this->htmlTheme, 'theme_test');
67+
68+
$this->assertFalse($this->resolver->getTheme('notfound', HtmlFormat::FORMAT_NAME));
69+
}
70+
71+
public function testGetParentThemeWhenSelectedNotAcceptFormat()
72+
{
73+
$this->htmlTheme->shouldReceive('getParent')->andReturn('base');
74+
75+
$this->resolver->addTheme($this->baseTheme, 'theme_base');
76+
$this->resolver->addTheme($this->htmlTheme, 'theme_test');
77+
78+
$this->assertInstanceOf('Ladybug\Theme\ThemeInterface', $this->resolver->getTheme('test', ConsoleFormat::FORMAT_NAME));
79+
}
80+
81+
public function testGetFalseWhenSelectedNotAcceptFormat()
82+
{
83+
$this->htmlTheme->shouldReceive('getParent')->andReturn('base');
84+
85+
$this->resolver->addTheme($this->baseTheme, 'theme_base');
86+
$this->resolver->addTheme($this->htmlTheme, 'theme_test');
87+
88+
$this->assertFalse($this->resolver->getTheme('test', XmlFormat::FORMAT_NAME));
89+
}
90+
5491

5592
}

0 commit comments

Comments
 (0)