-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb77a47
commit 4827261
Showing
11 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
vendor | ||
composer.lock | ||
.idea | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Kollarovic\Admin\Test; | ||
|
||
use Tester\Assert; | ||
use Tester\DomQuery; | ||
|
||
require_once __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class AdminControlTest extends TestCase | ||
{ | ||
|
||
public function testRender() | ||
{ | ||
$presenter = $this->createPresenter(); | ||
$control = $presenter['adminControl']; | ||
ob_start(); | ||
$control->render(); | ||
$html = ob_get_clean(); | ||
|
||
$dom = DomQuery::fromHtml($html); | ||
Assert::true($dom->has('html')); | ||
Assert::true($dom->has('footer')); | ||
Assert::contains('Mario Kollarovic', $html); | ||
} | ||
|
||
} | ||
|
||
|
||
\run(new AdminControlTest()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Kollarovic\Admin\Test; | ||
|
||
use Tester\Assert; | ||
use Tester\DomQuery; | ||
|
||
require_once __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class LoginControlTest extends TestCase | ||
{ | ||
|
||
public function testRender() | ||
{ | ||
$presenter = $this->createPresenter(); | ||
$control = $presenter['loginControl']; | ||
ob_start(); | ||
$control->render(); | ||
$html = ob_get_clean(); | ||
|
||
$dom = DomQuery::fromHtml($html); | ||
Assert::true($dom->has('html')); | ||
Assert::true($dom->has('form')); | ||
} | ||
|
||
} | ||
|
||
|
||
\run(new LoginControlTest()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Kollarovic\Admin\Test; | ||
|
||
use Kollarovic\Admin\IAdminControlFactory; | ||
use Kollarovic\Admin\ILoginControlFactory; | ||
use Nette\Application\UI\Presenter; | ||
use Nette\Application\UI\InvalidLinkException; | ||
use Nette\Security\Identity; | ||
|
||
|
||
class MockPresenter extends Presenter | ||
{ | ||
|
||
private $currentDestination = 'Setting:web'; | ||
|
||
private $linkToUrl = [ | ||
'Homepage:default' => '/', | ||
'//Homepage:default' => 'http://example.com/', | ||
'Page:default' => '/page/default', | ||
'Page:list' => '/page/list', | ||
'this' => '/setting/web', | ||
'page' => '/setting/page', | ||
'Setting:default' => '/setting/default', | ||
'Setting:base' => '/setting/base', | ||
'Setting:advanced' => '/setting/advanced', | ||
'Setting:web' => '/setting/web', | ||
'Setting:mail' => '/setting/mail', | ||
]; | ||
|
||
/** @var IAdminControlFactory @inject */ | ||
public $adminControlFactory; | ||
|
||
/** @var ILoginControlFactory @inject */ | ||
public $loginControlFactory; | ||
|
||
|
||
public function link($destination, $args = array()) | ||
{ | ||
if (!array_key_exists($destination, $this->linkToUrl)) { | ||
throw new InvalidLinkException("'$destination'"); | ||
} | ||
|
||
return $this->linkToUrl[$destination]; | ||
} | ||
|
||
|
||
public function isLinkCurrent($destination = NULL, $args = array()) | ||
{ | ||
return ($destination == $this->currentDestination); | ||
} | ||
|
||
|
||
protected function createComponentAdminControl() | ||
{ | ||
$this->user->login(new Identity(1)); | ||
$this->saveGlobalState(); | ||
$adminControl = $this->adminControlFactory->create(); | ||
$adminControl->setUserName('Mario Kollarovic')->setUserImage('images/user.png'); | ||
$adminControl->setProfileUrl('/'); | ||
$adminControl->setSkin('red'); | ||
$adminControl->onLoggedOut[] = function() { | ||
$this->redirect('Sign:in'); | ||
}; | ||
return $adminControl; | ||
} | ||
|
||
|
||
protected function createComponentLoginControl() | ||
{ | ||
$loginControl = $this->loginControlFactory->create(); | ||
return $loginControl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Kollarovic\Admin\Test; | ||
|
||
use Nette\Localization\ITranslator; | ||
|
||
|
||
class MockTranslator implements ITranslator | ||
{ | ||
|
||
function translate($message, $count = null) | ||
{ | ||
return $message; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<? | ||
|
||
namespace Kollarovic\Admin\Test; | ||
|
||
use Nette\Configurator; | ||
|
||
|
||
abstract class TestCase extends \Tester\TestCase | ||
{ | ||
|
||
protected function createContainer() | ||
{ | ||
$configurator = new Configurator(); | ||
$configurator->setDebugMode(false); | ||
$configurator->setTempDirectory(TEMP_DIR); | ||
$configurator->addConfig(__DIR__ . '/../config.neon'); | ||
return $configurator->createContainer(); | ||
} | ||
|
||
|
||
protected function createPresenter() | ||
{ | ||
$container = $this->createContainer(); | ||
$presenter = new MockPresenter(); | ||
$container->callInjects($presenter); | ||
return $presenter; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
|
||
if (!$autoload = @include __DIR__ . '/../vendor/autoload.php') { | ||
echo 'Install Nette Tester using `composer update --dev`'; | ||
exit(1); | ||
} | ||
|
||
$autoload->addPsr4('Kollarovic\Admin\Test\\', __DIR__ . '/Admin'); | ||
|
||
|
||
Tester\Environment::setup(); | ||
|
||
define('TEMP_DIR', __DIR__ . '/temp'); | ||
|
||
function run(Tester\TestCase $testCase) { | ||
$testCase->run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
extensions: | ||
navigation: Kollarovic\Navigation\DI\Extension | ||
admin: Kollarovic\Admin\DI\Extension | ||
|
||
navigation: | ||
admin: | ||
label: Homepage | ||
link: Homepage:default | ||
items: | ||
page: | ||
label: Page | ||
link: Page:default | ||
icon: fa-file-text-o | ||
value: 50 | ||
setting: | ||
label: Setting | ||
link: Setting:default | ||
items: | ||
base: | ||
label: Base | ||
link: Setting:base | ||
advanced: | ||
label: Advanced | ||
link: Setting:advanced | ||
items: | ||
web: | ||
label: Web | ||
link: Setting:web | ||
mail: | ||
label: Mail | ||
link: Setting:mail | ||
|
||
services: | ||
translator: Kollarovic\Admin\Test\MockTranslator | ||
nette.latteFactory: | ||
setup: | ||
- addFilter('translate', [@translator, 'translate']) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.* |