Skip to content

Commit

Permalink
feature/Method blockExists was added, unit-tests were refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdodonov committed Nov 25, 2020
1 parent 8f302d8 commit 636da24
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 9 deletions.
16 changes: 16 additions & 0 deletions Mezon/HtmlTemplate/HtmlTemplate.php
Expand Up @@ -304,6 +304,22 @@ public function compile(): string
return $this->template;
}

/**
* Does block exist
*
* @param string $blockName block name
* @return bool does block exist?
*/
public function blockExists(string $blockName):bool{
if ($this->fileExists('Res/Blocks/' . $blockName . '.tpl')) {
return true;
} elseif ($this->fileExists('Blocks/' . $blockName . '.tpl')) {
return true;
} else {
return false;
}
}

/**
* Method returns block's content
*
Expand Down
32 changes: 23 additions & 9 deletions Mezon/HtmlTemplate/Tests/HtmlTemplateUnitTest.php
Expand Up @@ -144,7 +144,7 @@ public function testGetUnexistingBlock()
public function testGetExistingVar(): void
{
// setup
$template = new HtmlTemplate(__DIR__);
$template = new HtmlTemplate(HtmlTemplateUnitTest::PATH_TO_TEST_DATA);
$template->setPageVar('existing-var', 'existing value');

// test body and assertions
Expand All @@ -157,7 +157,7 @@ public function testGetExistingVar(): void
public function testGetUnExistingVar(): void
{
// setup
$template = new HtmlTemplate(__DIR__);
$template = new HtmlTemplate(HtmlTemplateUnitTest::PATH_TO_TEST_DATA);

// assertions
$this->expectException(\Exception::class);
Expand All @@ -172,7 +172,7 @@ public function testGetUnExistingVar(): void
public function testSetPageVars(): void
{
// setup
$template = new HtmlTemplate(__DIR__);
$template = new HtmlTemplate(HtmlTemplateUnitTest::PATH_TO_TEST_DATA);

// test body
$template->setPageVars([
Expand All @@ -193,10 +193,10 @@ public function testSetPageVars(): void
public function testSetPageVarFromFile(): void
{
// setup
$template = new HtmlTemplate(__DIR__);
$template = new HtmlTemplate(HtmlTemplateUnitTest::PATH_TO_TEST_DATA);

// test body
$template->setPageVarFromFile('title', __DIR__ . '/Res/var.txt');
$template->setPageVarFromFile('title', HtmlTemplateUnitTest::PATH_TO_TEST_DATA . '/Res/var.txt');

// assertions
$this->assertEquals('some var from file', $template->getPageVar('title'));
Expand All @@ -208,18 +208,18 @@ public function testSetPageVarFromFile(): void
public function testPathsManipulations(): void
{
// setup
$template = new HtmlTemplate(__DIR__);
$template = new HtmlTemplate(HtmlTemplateUnitTest::PATH_TO_TEST_DATA);

// assertions
$this->assertContains(__DIR__, $template->getPaths());
$this->assertContains(HtmlTemplateUnitTest::PATH_TO_TEST_DATA, $template->getPaths());

// test body
$template->addPaths([
'some-path'
]);

// assertions
$this->assertContains(__DIR__, $template->getPaths());
$this->assertContains(HtmlTemplateUnitTest::PATH_TO_TEST_DATA, $template->getPaths());
$this->assertContains('some-path', $template->getPaths());

// test body
Expand All @@ -228,7 +228,21 @@ public function testPathsManipulations(): void
]);

// asssertions
$this->assertNotContains(__DIR__, $template->getPaths());
$this->assertNotContains(HtmlTemplateUnitTest::PATH_TO_TEST_DATA, $template->getPaths());
$this->assertContains('some-path', $template->getPaths());
}

/**
* Testing method
*/
public function testBlockExists(): void
{
// setup
$template = new HtmlTemplate(HtmlTemplateUnitTest::PATH_TO_TEST_DATA);

// test body and assertions
$this->assertTrue($template->blockExists('block1'));
$this->assertTrue($template->blockExists('block2'));
$this->assertFalse($template->blockExists('block3'));
}
}
Empty file.
Empty file.
File renamed without changes.

0 comments on commit 636da24

Please sign in to comment.