Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleš committed Jun 5, 2017
1 parent 69d2ffb commit 69c30a0
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 14 deletions.
98 changes: 84 additions & 14 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ public function setWwwDir(string $wwwDir): self {
}

/**
* @param string
* @param bool
* @return self
*/
public function setDebugMode(string $debugMode): self {
public function setDebugMode(bool $debugMode): self {
$this->debugMode = $debugMode;
return $this;
}

/**
* @param string
* @param bool
* @return self
*/
public function setProductionMode(string $productionMode): self {
public function setProductionMode(bool $productionMode): self {
$this->productionMode = $productionMode;
return $this;
}
Expand Down Expand Up @@ -175,6 +175,86 @@ public function addOtherFile(array $fileSettings): self {

/** ******************** */

/**
* @return string|NULL
*/
public function getExpiration(): ?string {
return $this->expiration;
}

/**
* @return string
*/
public function getWwwDir(): string {
return $this->wwwDir;
}

/**
* @return bool
*/
public function getDebugMode(): bool {
return $this->debugMode;
}

/**
* @return bool
*/
public function getProductionMode(): bool {
return $this->productionMode;
}

/**
* @return string
*/
public function getUniqueId(): string {
return $this->uniqueId;
}

/**
* @return Nette\Caching\Cache
*/
public function getCache(): Nette\Caching\Cache {
if ($this->cache === NULL) {
$this->cache = new Caching\Cache($this->cacheStorage, $this->cacheNamespace);
}
return $this->cache;
}

/**
* @return string
*/
public function getCacheNamespace(): string {
return $this->cacheNamespace;
}

/**
* @return Nette\Http\IRequest
*/
public function getHttpRequest(): Nette\Http\IRequest {
return $this->httpRequest;
}

/**
* @return array
*/
public function getCssFiles(): array {
return $this->cssFiles;
}

/**
* @return array
*/
public function getJsFiles(): array {
return $this->jsFiles;
}

/**
* @return array
*/
public function getOtherFiles(): array {
return $this->otherFiles;
}

/**
* @param string
* @return AlesWita\Components\WebLoader\Css
Expand Down Expand Up @@ -203,16 +283,6 @@ public function getJsLoader(string $namespace = self::DEFAULT_NAMESPACE): AlesWi
return $jsLoader;
}

/**
* @return Nette\Caching\Cache
*/
public function getCache(): Nette\Caching\Cache {
if ($this->cache === NULL) {
$this->cache = new Caching\Cache($this->cacheStorage, $this->cacheNamespace);
}
return $this->cache;
}

/**
* @return string
*/
Expand Down
57 changes: 57 additions & 0 deletions tests/app/BaseLinksPresenter.php
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]]);
}
}
3 changes: 3 additions & 0 deletions tests/app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ services:
baseLinks.presenter:
class: AlesWita\Components\WebLoader\Tests\App\Presenters\BaseLinksPresenter

getters.presenter:
class: AlesWita\Components\WebLoader\Tests\App\Presenters\GettersPresenter

routing.router: AlesWita\Components\WebLoader\Tests\App\Router\Router::createRouter
17 changes: 17 additions & 0 deletions tests/app/config/gettersTestOne.neon
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
20 changes: 20 additions & 0 deletions tests/app/presenters/GettersPresenter.php
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;
}
1 change: 1 addition & 0 deletions tests/files/folder/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
1 change: 1 addition & 0 deletions tests/tests/BaseLinksTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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";


Expand Down
95 changes: 95 additions & 0 deletions tests/tests/GettersTest.phpt
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();

0 comments on commit 69c30a0

Please sign in to comment.