-
Notifications
You must be signed in to change notification settings - Fork 0
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
Aleš
committed
Jun 5, 2017
1 parent
69d2ffb
commit 69c30a0
Showing
8 changed files
with
278 additions
and
14 deletions.
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
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,57 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the AlesWita\Components\WebLoader | ||
* Copyright (c) 2017 Ales Wita (aleswita+github@gmail.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AlesWita\Components\WebLoader\Tests\App\Presenters; | ||
|
||
use AlesWita; | ||
use Nette; | ||
|
||
|
||
final class BaseLinksPresenter extends Nette\Application\UI\Presenter | ||
{ | ||
/** @var AlesWita\Components\WebLoader\Factory @inject */ | ||
public $webLoader; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function actionOne(): void { | ||
$this->setView("cssLoader"); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function actionTwo(): void { | ||
$this->setView("jsLoader"); | ||
} | ||
|
||
/** | ||
* @return AlesWita\Components\WebLoader\Loader\Css | ||
*/ | ||
protected function createComponentCss(): AlesWita\Components\WebLoader\Loader\Css { | ||
return $this->webLoader->getCssLoader(); | ||
} | ||
|
||
/** | ||
* @return AlesWita\Components\WebLoader\Loader\Js | ||
*/ | ||
protected function createComponentJs(): AlesWita\Components\WebLoader\Loader\Js { | ||
return $this->webLoader->getJsLoader(); | ||
} | ||
|
||
/** | ||
* @param Nette\Application\IResponse | ||
* @return void | ||
*/ | ||
protected function shutdown($response): void { | ||
parent::shutdown($response); | ||
$this->webLoader->getCache()->clean([Nette\Caching\Cache::TAGS => [AlesWita\Components\WebLoader\Factory::CACHE_TAG]]); | ||
} | ||
} |
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
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,17 @@ | ||
webloader: | ||
expiration: 1 WEEK | ||
cache: | ||
namespace: foo | ||
files: | ||
- | ||
originalFile: %appDir%/../files/css.css | ||
tag: css | ||
- | ||
originalFile: %appDir%/../files/js.js | ||
tag: js | ||
|
||
folders: | ||
- | ||
originalFolder: %appDir%/../files/folder | ||
tag: other | ||
folder: other |
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,20 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the AlesWita\Components\WebLoader | ||
* Copyright (c) 2017 Ales Wita (aleswita+github@gmail.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AlesWita\Components\WebLoader\Tests\App\Presenters; | ||
|
||
use AlesWita; | ||
use Nette; | ||
|
||
|
||
final class GettersPresenter extends Nette\Application\UI\Presenter | ||
{ | ||
/** @var AlesWita\Components\WebLoader\Factory @inject */ | ||
public $webLoader; | ||
} |
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 @@ | ||
foo |
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
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,95 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the AlesWita\Components\WebLoader | ||
* Copyright (c) 2017 Ales Wita (aleswita+github@gmail.com) | ||
* | ||
* @phpVersion 7.1.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AlesWita\Components\WebLoader\Tests\Tests; | ||
|
||
use AlesWita; | ||
use Nette; | ||
use Tester; | ||
|
||
require_once __DIR__ . "/../bootstrap.php"; | ||
require_once __DIR__ . "/../app/presenters/BaseLinksPresenter.php"; | ||
require_once __DIR__ . "/../app/presenters/GettersPresenter.php"; | ||
require_once __DIR__ . "/../app/router/Router.php"; | ||
|
||
|
||
final class GettersTest extends Tester\TestCase | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function testOne(): void { | ||
$configurator = new Nette\Configurator(); | ||
$configurator->setTempDirectory(TEMP_DIR); | ||
$configurator->addConfig(__DIR__ . "/../app/config/config.neon"); | ||
$configurator->addConfig(__DIR__ . "/../app/config/gettersTestOne.neon"); | ||
|
||
$container = $configurator->createContainer(); | ||
$presenterFactory = $container->getByType("Nette\\Application\\IPresenterFactory"); | ||
|
||
$presenter = $presenterFactory->createPresenter("Getters"); | ||
|
||
Tester\Assert::same("1 WEEK", $presenter->webLoader->getExpiration()); | ||
Tester\Assert::contains("aleswita\\webloader\\tests\\tests", $presenter->webLoader->getWwwDir()); | ||
Tester\Assert::false($presenter->webLoader->getDebugMode()); | ||
Tester\Assert::true($presenter->webLoader->getProductionMode()); | ||
Tester\Assert::same(13, strlen($presenter->webLoader->getUniqueId())); | ||
Tester\Assert::true($presenter->webLoader->getCache() instanceof Nette\Caching\Cache); | ||
Tester\Assert::same("foo", $presenter->webLoader->getCacheNamespace()); | ||
Tester\Assert::true($presenter->webLoader->getHttpRequest() instanceof Nette\Http\IRequest); | ||
|
||
|
||
$cssFiles = $presenter->webLoader->getCssFiles(); | ||
|
||
Tester\Assert::true(array_key_exists("originalFile", $cssFiles[0])); | ||
Tester\Assert::same("css", $cssFiles[0]["tag"]); | ||
Tester\Assert::same("default", $cssFiles[0]["namespace"][0]); | ||
Tester\Assert::same("css.css", $cssFiles[0]["baseName"]); | ||
Tester\Assert::same("css", $cssFiles[0]["folder"]); | ||
Tester\Assert::true(array_key_exists("hash", $cssFiles[0])); | ||
Tester\Assert::true(array_key_exists("file", $cssFiles[0])); | ||
|
||
|
||
$jsFiles = $presenter->webLoader->getJsFiles(); | ||
|
||
Tester\Assert::true(array_key_exists("originalFile", $jsFiles[0])); | ||
Tester\Assert::same("js", $jsFiles[0]["tag"]); | ||
Tester\Assert::same("default", $jsFiles[0]["namespace"][0]); | ||
Tester\Assert::same("js.js", $jsFiles[0]["baseName"]); | ||
Tester\Assert::same("js", $jsFiles[0]["folder"]); | ||
Tester\Assert::true(array_key_exists("hash", $jsFiles[0])); | ||
Tester\Assert::true(array_key_exists("file", $jsFiles[0])); | ||
|
||
|
||
$otherFiles = $presenter->webLoader->getOtherFiles(); | ||
|
||
Tester\Assert::true(array_key_exists("originalFile", $otherFiles[0])); | ||
Tester\Assert::same("other", $otherFiles[0]["tag"]); | ||
Tester\Assert::same("default", $otherFiles[0]["namespace"][0]); | ||
Tester\Assert::same("foo.txt", $otherFiles[0]["baseName"]); | ||
Tester\Assert::same("other", $otherFiles[0]["folder"]); | ||
Tester\Assert::true(array_key_exists("hash", $otherFiles[0])); | ||
Tester\Assert::true(array_key_exists("file", $otherFiles[0])); | ||
|
||
|
||
Tester\Assert::true($presenter->webLoader->getCssLoader() instanceof AlesWita\Components\WebLoader\Loader\Css); | ||
Tester\Assert::true($presenter->webLoader->getJsLoader() instanceof AlesWita\Components\WebLoader\Loader\Js); | ||
|
||
|
||
var_dump($presenter->webLoader->getBasePath()); | ||
|
||
Tester\Assert::true("foooooooo"); | ||
} | ||
} | ||
|
||
|
||
$test = new GettersTest; | ||
$test->run(); |