1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-10-24 03:16:07 +02:00

Initial commit for public repo

This commit is contained in:
Andrew Davis
2018-09-02 10:57:36 -05:00
commit cb5d7c2386
79 changed files with 14644 additions and 0 deletions

8
test/BaseTestCase.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace Test;
class BaseTestCase extends \PHPUnit\Framework\TestCase
{
}

57
test/BuildTest.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace Test;
use Apprentice\Build;
class BuildTest extends BaseTestCase
{
public function setUp()
{
load_config(__DIR__ . '/static/config.php');
mkdir('/tmp/apprentice_output');
}
public function tearDown()
{
$files = glob('/tmp/apprentice_output/*');
foreach ($files as $file) {
unlink($file);
}
rmdir('/tmp/apprentice_output');
}
public function test_build_single_page()
{
$build = new Build();
$build->runSingleBuild('test');
$html = file_get_contents('/tmp/apprentice_output/test.html');
$expectedHtml = "<div>Test Title</div>\n" .
"<div>Test Subtitle</div>\n" .
"<div>Test Description</div>\n";
$this->assertFalse(empty($html));
$this->assertEquals($expectedHtml, $html);
}
public function test_build_all()
{
$build = new Build();
$build->buildAll();
$expectedHtml = "<div>Test Title</div>\n" .
"<div>Test Subtitle</div>\n" .
"<div>Test Description</div>\n";
$expectedHtml2 = "<div>index</div>\n";
$html = file_get_contents('/tmp/apprentice_output/test.html');
$html2 = file_get_contents('/tmp/apprentice_output/index.html');
$this->assertEquals($expectedHtml, $html);
$this->assertEquals($expectedHtml2, $html2);
}
}

59
test/FunctionsTest.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
namespace Test;
class FunctionsTest extends BaseTestCase
{
public function tearDown()
{
$GLOBALS['PARTIAL_TEST'] = null;
}
public function test_load_config()
{
load_config(__DIR__ . '/static/config.php');
$this->assertEquals(__DIR__ . '/static/../icons', config('icon_dir'));
}
public function test_page_path()
{
$page = page_path('home');
$this->assertEquals('/home.html', $page);
}
public function test_escape()
{
$output = escape("'\"&");
$this->assertEquals("&#039;&quot;&amp;", $output);
}
public function test_icon()
{
load_config(__DIR__ . '/static/config.php');
$icon = icon('test');
$this->assertFalse(empty($icon));
$this->assertEquals("<test></test>\n", $icon);
}
public function test_code_table()
{
$php = file_get_contents(__DIR__ . '/static/code_table.php');
$expectedOutput = file_get_contents(__DIR__ . '/static/code_table.html');
$html = code_table($php);
$this->assertFalse(empty($html));
$this->assertEquals($expectedOutput, $html . "\n");
}
public function test_partial()
{
partial('partial', ['test' => 'test var']);
$this->assertEquals('test var', $GLOBALS['PARTIAL_TEST']);
}
}

1
test/icons/test.svg Normal file
View File

@@ -0,0 +1 @@
<test></test>

View File

@@ -0,0 +1,4 @@
<?php
// test comment
$test = 'test';

View File

@@ -0,0 +1,4 @@
<div class="grid-code"><div class="doc"></div><div class="code"><pre><code class="language-php">&lt;?php
</code></pre></div><div class="doc">this is a test</div><div class="code"><pre><code class="language-php">$test = 'some test code';
</code></pre></div></div>

View File

@@ -0,0 +1,4 @@
<?php
// this is a test
$test = 'some test code';

18
test/static/config.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
use Apprentice\Page;
return [
'icon_dir' => __DIR__ . '/../icons',
'code_dir' => __DIR__ . '/code',
'templates_dir' => __DIR__ . '/templates',
'output_dir' => '/tmp/apprentice_output',
'pages' => [
Page::create('index', 'index.phtml'),
Page::create('test', null, 'test.php', [
'title' => 'Test Title',
'subtitle' => 'Test Subtitle',
'description' => 'Test Description',
]),
],
];

View File

@@ -0,0 +1,3 @@
<?php
$GLOBALS['PARTIAL_TEST'] = $test;

View File

@@ -0,0 +1,3 @@
<div><?= escape($title) ?></div>
<div><?= escape($subtitle) ?></div>
<div><?= escape($description) ?></div>

View File

@@ -0,0 +1 @@
<div>index</div>