Skip to content

Commit

Permalink
Starting some tests (tests/Console/Utils/ParamsValidatorTest.phpt), ref
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed Nov 22, 2017
1 parent 5357c6a commit 163293e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
10 changes: 4 additions & 6 deletions assets/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ document.getElementsByTagName("iframe")[0].addEventListener("load", function() {
}
});

/**
* Simple router
*/
var onHashChangeRouter = function() {
if (window.location.hash) {
var hash = window.location.hash.replace(/#/, '');
Expand All @@ -83,9 +86,4 @@ var onHashChangeRouter = function() {
}
};

/**
* Simple router
*/
window.onhashchange = function() {
onHashChangeRouter();
};
window.addEventListener('hashchange', onHashChangeRouter);
2 changes: 1 addition & 1 deletion demoOutput/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html> <html> <head> <title>Awesome cookbook JSON-RPC API doc</title> <style>html,body{margin:0;padding:0;height:100%;width:100%}h1,h2,h3,h4,h5,h6,p{margin:0}body{background-color:#2980b9;background-color:#34495e;font-size:12px;font-family:Arial,Helvetica,sans-serif;color:#2c3e50;overflow:auto;box-sizing:border-box;width:100vw;max-width:100vw;height:100vh;max-height:100vh;display:grid;grid-template-columns:auto 300px 900px auto;grid-template-rows:80px auto 80px;grid-template-areas:"header header header header" "empty-left nav main empty-right" "footer footer footer footer";grid-column-gap:2em}header{grid-area:header}nav{grid-area:nav;align-self:start}.empty-left{grid-area:empty-left}.empty-right{grid-area:empty-right}main{grid-area:main}footer{grid-area:footer}button.section-method,a.section-site{font-size:12px;display:block;width:100%;border:0;margin:0;line-height:30px;vertical-align:middle;padding:0 1em;background-color:#fff;color:#505050;box-sizing:border-box;text-align:left;border-radius:0;cursor:pointer}button.section-method:hover,a.section-site:hover,button.section-method:active,a.section-site:active,button.section-method:focus,a.section-site:focus,button.section-method:target,a.section-site:target{background-color:#eee;cursor:pointer;outline:none}.section-site:first-of-type{font-weight:700}.section-method:first-of-type,.section-site:first-of-type{border-top-right-radius:2px;border-top-left-radius:2px}.section-method:last-of-type,.section-site:last-of-type{border-bottom-right-radius:2px;border-bottom-left-radius:2px}.section-method:first-of-type{margin-top:1em}iframe{width:100%;height:0;border:0;padding:0;margin:0}</style> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/> </head> <body> <header>Awesome cookbook JSON-RPC API doc</header> <div class="empty-left"></div> <nav> <p><a data-section-href="home.html" class="section-site" data-target="home">Home</a> <a data-section-href="about.html" class="section-site" data-target="about-project">About project</a> <button data-section-href="methods/user.login.html" class="section-method" data-target="user-login">user.login</button> <button data-section-href="methods/user.logout.html" class="section-method" data-target="user-logout">user.logout</button></p></nav> <div class="empty-right"></div> <main> <iframe src="" scrolling="no"></iframe> </main> <footer></footer> <script type="text/javascript">document.addEventListener("DOMContentLoaded",function(event){var buttons=document.querySelectorAll('[data-section-href]');for(var i=0;i<buttons.length;i++){buttons[i].addEventListener("click",function(event){event.stopPropagation();event.preventDefault();window.location.hash=this.getAttribute("data-target")})} if(buttons.length){if(window.location.hash){onHashChangeRouter()}else{var sectionLink=buttons[0].getAttribute("data-section-href");document.getElementsByTagName('iframe')[0].setAttribute("src",sectionLink)}}});document.getElementsByTagName("iframe")[0].addEventListener("load",function(){this.style.height=this.contentWindow.document.body.scrollHeight+'px'});document.getElementsByTagName("iframe")[0].addEventListener("load",function(){var jsonAreas=this.contentWindow.document.getElementsByClassName('language-json');for(var i=0;i<jsonAreas.length;i++){var content=jsonAreas[i].innerHTML;content=content.replace(/"([^"]+)":/g,"<span class=language-json-key>&quot;$1&quot;:</span>");content=content.replace(/"([^"]+)"([^:])/g,"<span class=language-json-string>&quot;$1&quot;</span>$2");content=content.replace(/([ ,:{\n])(\d+)/g,"$1<span class=language-json-number>$2</span>");jsonAreas[i].innerHTML=content}});var onHashChangeRouter=function(){if(window.location.hash){var hash=window.location.hash.replace(/#/,'');var sectionLink=document.querySelectorAll('[data-target="'+hash+'"]');if(sectionLink.length){var sectionSrc=sectionLink[0].getAttribute("data-section-href");document.getElementsByTagName('iframe')[0].setAttribute("src",sectionSrc)}}};window.onhashchange=function(){onHashChangeRouter()}</script> </body> </html>
<!DOCTYPE html> <html> <head> <title>Awesome cookbook JSON-RPC API doc</title> <style>html,body{margin:0;padding:0;height:100%;width:100%}h1,h2,h3,h4,h5,h6,p{margin:0}body{background-color:#2980b9;background-color:#34495e;font-size:12px;font-family:Arial,Helvetica,sans-serif;color:#2c3e50;overflow:auto;box-sizing:border-box;width:100vw;max-width:100vw;height:100vh;max-height:100vh;display:grid;grid-template-columns:auto 300px 900px auto;grid-template-rows:80px auto 80px;grid-template-areas:"header header header header" "empty-left nav main empty-right" "footer footer footer footer";grid-column-gap:2em}header{grid-area:header}nav{grid-area:nav;align-self:start}.empty-left{grid-area:empty-left}.empty-right{grid-area:empty-right}main{grid-area:main}footer{grid-area:footer}button.section-method,a.section-site{font-size:12px;display:block;width:100%;border:0;margin:0;line-height:30px;vertical-align:middle;padding:0 1em;background-color:#fff;color:#505050;box-sizing:border-box;text-align:left;border-radius:0;cursor:pointer}button.section-method:hover,a.section-site:hover,button.section-method:active,a.section-site:active,button.section-method:focus,a.section-site:focus,button.section-method:target,a.section-site:target{background-color:#eee;cursor:pointer;outline:none}.section-site:first-of-type{font-weight:700}.section-method:first-of-type,.section-site:first-of-type{border-top-right-radius:2px;border-top-left-radius:2px}.section-method:last-of-type,.section-site:last-of-type{border-bottom-right-radius:2px;border-bottom-left-radius:2px}.section-method:first-of-type{margin-top:1em}iframe{width:100%;height:0;border:0;padding:0;margin:0}</style> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/> </head> <body> <header>Awesome cookbook JSON-RPC API doc</header> <div class="empty-left"></div> <nav> <p><a data-section-href="home.html" class="section-site" data-target="home">Home</a> <a data-section-href="about.html" class="section-site" data-target="about-project">About project</a> <button data-section-href="methods/user.login.html" class="section-method" data-target="user-login">user.login</button> <button data-section-href="methods/user.logout.html" class="section-method" data-target="user-logout">user.logout</button></p></nav> <div class="empty-right"></div> <main> <iframe src="" scrolling="no"></iframe> </main> <footer></footer> <script type="text/javascript">document.addEventListener("DOMContentLoaded",function(event){var buttons=document.querySelectorAll('[data-section-href]');for(var i=0;i<buttons.length;i++){buttons[i].addEventListener("click",function(event){event.stopPropagation();event.preventDefault();window.location.hash=this.getAttribute("data-target")})} if(buttons.length){if(window.location.hash){onHashChangeRouter()}else{var sectionLink=buttons[0].getAttribute("data-section-href");document.getElementsByTagName('iframe')[0].setAttribute("src",sectionLink)}}});document.getElementsByTagName("iframe")[0].addEventListener("load",function(){this.style.height=this.contentWindow.document.body.scrollHeight+'px'});document.getElementsByTagName("iframe")[0].addEventListener("load",function(){var jsonAreas=this.contentWindow.document.getElementsByClassName('language-json');for(var i=0;i<jsonAreas.length;i++){var content=jsonAreas[i].innerHTML;content=content.replace(/"([^"]+)":/g,"<span class=language-json-key>&quot;$1&quot;:</span>");content=content.replace(/"([^"]+)"([^:])/g,"<span class=language-json-string>&quot;$1&quot;</span>$2");content=content.replace(/([ ,:{\n])(\d+)/g,"$1<span class=language-json-number>$2</span>");jsonAreas[i].innerHTML=content}});var onHashChangeRouter=function(){if(window.location.hash){var hash=window.location.hash.replace(/#/,'');var sectionLink=document.querySelectorAll('[data-target="'+hash+'"]');if(sectionLink.length){var sectionSrc=sectionLink[0].getAttribute("data-section-href");document.getElementsByTagName('iframe')[0].setAttribute("src",sectionSrc)}}};window.addEventListener('hashchange',onHashChangeRouter)</script> </body> </html>
3 changes: 2 additions & 1 deletion src/anabelle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env php
<?php

require __DIR__ . '/../../../autoload.php';
//require __DIR__ . '/../../../autoload.php';
require __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\Console\Application;
use Ublaboo\Anabelle\Console\GenerateDocuCommand;
Expand Down
64 changes: 64 additions & 0 deletions tests/Console/Utils/ParamsValidatorTest.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Ublaboo\Anabelle\Tests\Console\Utils;

require_once __DIR__ . '/../../bootstrap.php';

use Tester\Assert;
use Tester\TestCase;
use Ublaboo\Anabelle\Console\Utils\Exception\ParamsValidatorException;
use Ublaboo\Anabelle\Console\Utils\ParamsValidator;
use Ublaboo\Anabelle\Http\AuthCredentials;

class ParamsValidatorTest extends TestCase
{

public function testDirectories(): void
{
$auth = new AuthCredentials(null, null);
$paramsValidator = new ParamsValidator('');

Assert::exception(function() use ($paramsValidator, $auth): void {
$paramsValidator->validateInputParams(
'nonExistingDir',
'',
$auth,
false
);
}, ParamsValidatorException::class, 'Input documentation directory does not exist');

Assert::exception(function() use ($paramsValidator, $auth): void {
$paramsValidator->validateInputParams(
__FILE__,
'',
$auth,
false
);
}, ParamsValidatorException::class, 'Given path is not a directory');

Assert::exception(function() use ($paramsValidator, $auth): void {
$paramsValidator->validateInputParams(
__DIR__,
'',
$auth,
false
);
}, ParamsValidatorException::class, 'Missing file ' . __DIR__ . '/index.md');

$m = "Output directory path already exists."
. " Delete it or use option [-o] as for \"overwrite\" output directory";

Assert::exception(function() use ($paramsValidator, $auth, $m): void {
$paramsValidator->validateInputParams(
TEST_DOCU_DIR,
TEST_DOCU_DIR,
$auth,
false
);
}, ParamsValidatorException::class, $m);
}
}

(new ParamsValidatorTest())->run();
15 changes: 15 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Api\Tests;

use Tester\Environment;

require __DIR__ . '/../vendor/autoload.php';

define('TEST_DOCU_DIR', __DIR__ . '/testDir');

Environment::setup();

date_default_timezone_set('Europe/Prague');
Empty file added tests/testDir/index.md
Empty file.

0 comments on commit 163293e

Please sign in to comment.