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 Jul 18, 2017
1 parent 2724ba0 commit 09d2589
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
4 changes: 4 additions & 0 deletions tests/app/config/baseLinksTestFour.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
webloader:
htmlTags:
-
tag: Nette\Utils\Html()::el('script', [type: text/javascript, src: http://example.com/js/foo.js])
2 changes: 0 additions & 2 deletions tests/app/config/baseLinksTestThree.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ webloader:
htmlTags:
-
tag: Nette\Utils\Html()::el('link', [rel: icon, type: image/png, href: /img/foo.png])
namespace: [default]

5 changes: 5 additions & 0 deletions tests/app/config/exceptionsTestEleven.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
webloader:
htmlTags:
# ========== HTML tags ==========
-
foo: Nette\Utils\Html()::el()
9 changes: 9 additions & 0 deletions tests/app/presenters/BaseLinksPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public function actionThree(): void
}


/**
* @return void
*/
public function actionFour(): void
{
$this->setView('tagLoader');
}


/**
* @return AlesWita\WebLoader\Loader\Css
*/
Expand Down
41 changes: 39 additions & 2 deletions tests/tests/BaseLinksTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,45 @@ final class BaseLinksTest extends Tester\TestCase
Tester\Assert::count(0, $cssFiles);
Tester\Assert::count(0, $jsFiles);
Tester\Assert::count(1, $htmlTags);
Tester\Assert::true(file_exists($cssFiles[0]['file']));
Tester\Assert::same(md5_file($cssFiles[0]['file']), md5_file($cssFiles[0]['originalFile']));
}


/**
* @return void
*/
public function testFour(): void {
$configurator = new Nette\Configurator();
$configurator->setTempDirectory(TEMP_DIR);
$configurator->addConfig(__DIR__ . '/../app/config/config.neon');
$configurator->addConfig(__DIR__ . '/../app/config/baseLinksTestFour.neon');

$container = $configurator->createContainer();
$presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory');

$presenter = $presenterFactory->createPresenter('BaseLinks');
$presenter->autoCanonicalize = FALSE;
$request = new Nette\Application\Request('BaseLinks', 'GET', ['action' => 'four']);
$response = $presenter->run($request);

Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse);
Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate);

$source = (string) $response->getSource();
$dom = Tester\DomQuery::fromHtml($source);
$data = $dom->find('script');

Tester\Assert::count(1, $data);
Tester\Assert::same('http://example.com/js/foo.js', (string) $data[0]['src']);
Tester\Assert::same('text/javascript', (string) $data[0]['type']);


$cssFiles = $presenter->webLoader->getCssFiles();
$jsFiles = $presenter->webLoader->getJsFiles();
$htmlTags = $presenter->webLoader->getHtmlTags();

Tester\Assert::count(0, $cssFiles);
Tester\Assert::count(0, $jsFiles);
Tester\Assert::count(1, $htmlTags);
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/tests/ExceptionsTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ final class ExceptionsTest extends Tester\TestCase

$configurator->createContainer();
}


/**
* @throws AlesWita\WebLoader\WebLoaderException Missing parameter "tag" in HTML tag configuration!
* @return void
*/
public function testEleven(): void {
$configurator = new Nette\Configurator();
$configurator->setTempDirectory(TEMP_DIR);
$configurator->addConfig(__DIR__ . '/../app/config/config.neon');
$configurator->addConfig(__DIR__ . '/../app/config/exceptionsTestEleven.neon');

$configurator->createContainer();
}
}


Expand Down

0 comments on commit 09d2589

Please sign in to comment.