Skip to content

Commit 728a2b4

Browse files
committed
Initial commit of tests.
Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
1 parent 9c3e968 commit 728a2b4

4 files changed

Lines changed: 260 additions & 0 deletions

File tree

tests/ExtensionDispatcherTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use Feather\Models\Extension;
5+
6+
class ExtensionDispatcherTest extends TestCase {
7+
8+
9+
public function testDispatcherRegisterExtension()
10+
{
11+
$dispatcher = $this->getDispatcher();
12+
$extension = new Extension(array(
13+
'location' => 'extension/location',
14+
'identifier' => 'foo',
15+
'auto' => false
16+
));
17+
$dispatcher->register($extension);
18+
$this->assertInstanceOf('Feather\Models\Extension', $dispatcher['extension.foo']);
19+
$this->assertEquals('foo', $dispatcher['extension.foo']->identifier);
20+
$this->assertEquals('extension/location', $dispatcher['extension.foo']->location);
21+
$this->assertTrue($dispatcher->isRegistered('foo'));
22+
}
23+
24+
25+
public function testDispatcherRegistersExtensionsFromArray()
26+
{
27+
$dispatcher = $this->getDispatcher();
28+
$extension = new Extension(array(
29+
'location' => 'extension/location',
30+
'identifier' => 'foo',
31+
'auto' => false
32+
));
33+
$dispatcher->registerExtensions(array($extension));
34+
$this->assertInstanceOf('Feather\Models\Extension', $dispatcher['extension.foo']);
35+
$this->assertEquals('foo', $dispatcher['extension.foo']->identifier);
36+
$this->assertEquals('extension/location', $dispatcher['extension.foo']->location);
37+
}
38+
39+
40+
public function testDispatcherAutoStartExtension()
41+
{
42+
$app = new Illuminate\Container;
43+
$app['events'] = new Illuminate\Events\Dispatcher;
44+
$files = m::mock('Illuminate\Filesystem');
45+
$files->shouldReceive('exists')->once()->andReturn(true);
46+
$dispatcher = m::mock('Feather\Extensions\Dispatcher[findExtensions,loadExtension]');
47+
$dispatcher->__construct($files, 'path/to');
48+
$dispatcher->setApplication($app);
49+
$extension = new Extension(array(
50+
'location' => 'extension/location',
51+
'identifier' => 'foo',
52+
'auto' => true
53+
));
54+
$file = m::mock('stdClass');
55+
$file->shouldReceive('getBasename')->once()->andReturn('FooExtension');
56+
$file->shouldReceive('getExtension')->once()->andReturn('php');
57+
$instantiatedExtension = m::mock('Feather\Extensions\Extension');
58+
$instantiatedExtension->shouldReceive('start')->once();
59+
$dispatcher->shouldReceive('findExtensions')->once()->with('path/to/extension/location')->andReturn(array($file));
60+
$dispatcher->shouldReceive('loadExtension')->with('Feather\Extensions\extension\location\FooExtension')->andReturn($instantiatedExtension);
61+
$dispatcher->register($extension);
62+
$this->assertContains('foo', $dispatcher->getStarted());
63+
$this->assertTrue($dispatcher->isStarted('foo'));
64+
}
65+
66+
67+
protected function getDispatcher()
68+
{
69+
$app = new Illuminate\Container;
70+
$app['events'] = new Illuminate\Events\Dispatcher;
71+
$files = m::mock('Illuminate\Filesystem');
72+
$files->shouldReceive('exists')->once()->andReturn(true);
73+
$dispatcher = m::mock(new Feather\Extensions\Dispatcher($files, 'path/to'));
74+
$dispatcher->setApplication($app);
75+
return $dispatcher;
76+
}
77+
78+
79+
}
80+

tests/ExtensionTest.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use Feather\Models\Extension;
5+
6+
class ExtensionTest extends PHPUnit_Framework_TestCase {
7+
8+
9+
public function testExtensionsAreBootstrapped()
10+
{
11+
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
12+
$extension = new Extension(array(
13+
'location' => 'extension/location',
14+
'identifier' => 'foo',
15+
'auto' => true
16+
));
17+
$dispatcher->register($extension);
18+
19+
$this->assertEquals('success', $app['events']->first('start_test'));
20+
}
21+
22+
23+
public function testExtensionsCanListenForEvents()
24+
{
25+
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
26+
$extension = new Extension(array(
27+
'location' => 'extension/location',
28+
'identifier' => 'foo',
29+
'auto' => true
30+
));
31+
$dispatcher->register($extension);
32+
$extension->loaded['Feather\Extensions\extension\location\FooExtension']->listen('foobar', function()
33+
{
34+
return 'barfoo';
35+
});
36+
$extension->loaded['Feather\Extensions\extension\location\FooExtension']->listen('barfoo', function()
37+
{
38+
return 'foobar';
39+
});
40+
$this->assertEquals('barfoo', $app['events']->first('foobar'));
41+
$this->assertEquals('foobar', $app['events']->first('barfoo'));
42+
}
43+
44+
45+
public function testExtensionsCanOverrideEvents()
46+
{
47+
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
48+
$extension = new Extension(array(
49+
'location' => 'extension/location',
50+
'identifier' => 'foo',
51+
'auto' => true
52+
));
53+
$dispatcher->register($extension);
54+
$extension->loaded['Feather\Extensions\extension\location\FooExtension']->listen('foobar', function()
55+
{
56+
return 'barfoo';
57+
});
58+
$extension->loaded['Feather\Extensions\extension\location\FooExtension']->override('foobar', function()
59+
{
60+
return 'barbar';
61+
});
62+
$this->assertEquals('barbar', $app['events']->first('foobar'));
63+
}
64+
65+
66+
public function testExtensionsCanUseMethods()
67+
{
68+
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
69+
$extension = new Extension(array(
70+
'location' => 'extension/location',
71+
'identifier' => 'foo',
72+
'auto' => true
73+
));
74+
$dispatcher->register($extension);
75+
$extension->loaded['Feather\Extensions\extension\location\FooExtension']->listen('foobar', 'foo');
76+
$this->assertEquals('foomethod', $app['events']->first('foobar'));
77+
}
78+
79+
80+
protected function getApplicationAndDispatcher()
81+
{
82+
$app = new Illuminate\Container;
83+
$app['events'] = new Illuminate\Events\Dispatcher;
84+
$app['files'] = m::mock('Illuminate\Filesystem');
85+
$app['files']->shouldReceive('exists')->once()->andReturn(true);
86+
$dispatcher = m::mock('Feather\Extensions\Dispatcher[findExtensions,loadExtension]');
87+
$dispatcher->__construct($app['files'], 'path/to');
88+
$dispatcher->setApplication($app);
89+
$file = m::mock('stdClass');
90+
$file->shouldReceive('getBasename')->once()->andReturn('FooExtension');
91+
$file->shouldReceive('getExtension')->once()->andReturn('php');
92+
$instantiatedExtension = m::mock('Feather\Extensions\Extension[start]');
93+
$instantiatedExtension->__construct($app);
94+
$instantiatedExtension->shouldReceive('foo')->andReturn('foomethod');
95+
$instantiatedExtension->shouldReceive('start')->once()->andReturnUsing(function() use ($instantiatedExtension)
96+
{
97+
$instantiatedExtension->listen('start_test', function()
98+
{
99+
return 'success';
100+
});
101+
});
102+
$dispatcher->shouldReceive('findExtensions')->once()->with('path/to/extension/location')->andReturn(array($file));
103+
$dispatcher->shouldReceive('loadExtension')->with('Feather\Extensions\extension\location\FooExtension')->andReturn($instantiatedExtension);
104+
return array($app, $dispatcher);
105+
}
106+
107+
108+
}

tests/FeatherCompilerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use Feather\Presenter\Compilers\FeatherCompiler;
5+
6+
class FeatherCompilerTest extends TestCase {
7+
8+
9+
public function testAssignmentsAreCompiled()
10+
{
11+
$compiler = new FeatherCompiler($this->getFiles(), __DIR__);
12+
$this->assertEquals('<?php $foo = \'bar\'; ?>', $compiler->compileString('@assign($foo, \'bar\')'));
13+
$this->assertEquals('<?php $foo = $bar; ?>', $compiler->compileString('@assign($foo, $bar)'));
14+
}
15+
16+
17+
public function testExtensionEventsAreCompiled()
18+
{
19+
$compiler = new FeatherCompiler($this->getFiles(), __DIR__);
20+
$expected = '<?php echo Feather\Extension::fire(\'foo\'); ?>';
21+
$this->assertEquals($expected, $compiler->compileString('@event(\'foo\')'));
22+
}
23+
24+
25+
public function testInlineErrorsAreCompiled()
26+
{
27+
$compiler = new FeatherCompiler($this->getFiles(), __DIR__);
28+
$expected = '<?php echo $errors->has(\'foo\') ? view("feather::errors.inline", array("error" => $errors->first(\'foo\'))) : null; ?>';
29+
$this->assertEquals($expected, $compiler->compileString('@error(\'foo\')'));
30+
}
31+
32+
33+
public function testErrorsAreCompiled()
34+
{
35+
$compiler = new FeatherCompiler($this->getFiles(), __DIR__);
36+
$expected = '<?php echo $errors->all() ? view("feather::errors.page", array("errors" => $errors->all())) : null; ?>';
37+
$this->assertEquals($expected, $compiler->compileString('@errors'));
38+
}
39+
40+
41+
public function getFiles()
42+
{
43+
return m::mock('Illuminate\Filesystem');
44+
}
45+
46+
}

tests/PresenterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use Feather\Presenter\Presenter;
5+
6+
class PresenterTest extends TestCase {
7+
8+
9+
public function testCanPreparePresenter()
10+
{
11+
$app = new Illuminate\Container;
12+
$app['config'] = new Illuminate\Config\Repository(m::mock('Illuminate\Config\LoaderInterface'), 'production');
13+
$app['config']->getLoader()->shouldReceive('load')->once()->with('production', 'feather', null)->once()->andReturn(array('forum' => array('theme' => 'foo')));
14+
$app['files'] = m::mock('Illuminate\Filesystem');
15+
$app['files']->shouldReceive('exists')->once()->andReturn(false);
16+
$app['view'] = m::mock('Illuminate\View\ViewManager');
17+
$app['view']->shouldReceive('addLocation')->once()->with('themes/foo/views');
18+
$app['view']->shouldReceive('addLocation')->once()->with('app/views');
19+
$app['path'] = 'app';
20+
$app['path.themes'] = 'themes';
21+
$presenter = new Presenter($app);
22+
$presenter->prepare();
23+
}
24+
25+
26+
}

0 commit comments

Comments
 (0)