Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #6 from Aheenam/feature/routing
Browse files Browse the repository at this point in the history
Feature/routing
  • Loading branch information
rathesDot authored Jan 5, 2018
2 parents 82d9413 + 01355dc commit d08e6ea
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"laravel": {
"providers": [
"Aheenam\\Mozhi\\MozhiServiceProvider"
]
],
"aliases": {
"Mozhi": "Aheenam\\Mozhi\\Facades\\Mozhi"
}
}
},
"scripts": {
Expand Down
26 changes: 26 additions & 0 deletions src/Facades/Mozhi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Aheenam\Mozhi\Facades;

use Illuminate\Support\Facades\Facade;

class Mozhi extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'mozhi';
}

/**
* include the routes for mozhi.
*/
public static function routes()
{
require __DIR__.'/../routes/web.php';
}
}
3 changes: 0 additions & 3 deletions src/MozhiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public function boot()

// set the themes views
$this->loadViewsFrom(base_path($this->app['config']['mozhi.theme_path']), 'theme');

// load the routes
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/FrontControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class FrontControllerTest extends TestCase
/** @test */
public function it_renders_correct_view_on_route()
{
\Mozhi::routes();

$response = $this->get('/no-template')
->assertStatus(200);

Expand All @@ -27,6 +29,7 @@ public function it_returns_a_404_if_route_not_found()
/** @test */
public function it_looks_for_a_index_page_if_slug_is_empty()
{
\Mozhi::routes();
$response = $this->get('/')
->assertStatus(200);

Expand Down
11 changes: 11 additions & 0 deletions tests/RouteResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ public function it_returns_null_if_page_does_not_exists()

$this->assertNull($page);
}

/** @test */
public function it_resolves_routes_only_where_it_was_defined()
{
$this->app['router']->group(['prefix' => 'test-prefix'], function () {
\Mozhi::routes();
});

$this->get('/test-prefix')->assertStatus(200);
$this->get('/')->assertStatus(404);
}
}
14 changes: 12 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ protected function getPackageProviders($app)
return [MozhiServiceProvider::class];
}

/**
* add the package facades.
*/
protected function getPackageAliases($app)
{
return [
'Mozhi' => \Aheenam\Mozhi\Facades\Mozhi::class,
];
}

/**
* Define environment setup.
*
Expand All @@ -42,9 +52,9 @@ protected function getEnvironmentSetUp($app)
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'prefix' => '',
]);

$app['config']->set('mozhi.content_disk', 'content');
Expand Down

0 comments on commit d08e6ea

Please sign in to comment.