From 8f39fe28990ac028dbf4109ba3387597406d36ff Mon Sep 17 00:00:00 2001 From: Joseph Mancuso Date: Mon, 10 Jul 2017 22:50:41 -0400 Subject: [PATCH] initial commit --- composer.json | 14 ++++ renderTest.php | 200 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 composer.json create mode 100644 renderTest.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8933e63 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "miraframework/tests", + "description": "A Service Provider to add Testing to the Mira Framework", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Joseph Mancuso", + "email": "jmancuso.mil@gmail.com" + } + ], + "minimum-stability": "stable", + "require": {} +} diff --git a/renderTest.php b/renderTest.php new file mode 100644 index 0000000..b0bee03 --- /dev/null +++ b/renderTest.php @@ -0,0 +1,200 @@ +assertEquals($template, true); + $template = Mira\Render::getTemplate('mira', 'base'); + $this->assertEquals($template, true); + } + + public function testPatternMatcher() + { + $this->assertEquals(Mira\Render::matcher('if'), '/(\s*)@if(\s*\(.*\))/'); + } + + public function testHeaderFooterWithTemplateAndSubdomain() + { + $_SERVER['HTTP_HOST'] = "mira.domainName.com"; + $config[] = $config['header'] = "mira.base"; + $this->assertEquals(Mira\Render::getHeader($config), true); + + $_SERVER['HTTP_HOST'] = "mira.domainName.com"; + $config[] = $config['footer'] = "mira.footer"; + $this->assertEquals(Mira\Render::getFooter($config), true); + } + + public function testHeaderFooterWithTemplateWithoutSubdomain() + { + $config[] = $config['header'] = "mira.base"; + $this->assertEquals(Mira\Render::getHeader($config), true); + $config[] = $config['footer'] = "mira.footer"; + $this->assertEquals(Mira\Render::getFooter($config), true); + } + + public function testHeaderFooterWithTemplateWithoutHeaderAndFooter() + { + $config['header'] = ""; + $this->assertEquals(Mira\Render::getHeader($config), false); + $config['footer'] = ""; + $this->assertEquals(Mira\Render::getFooter($config), false); + } + + public function testTemplateExtends() + { + $this->assertEquals(Mira\Render::templateExtends('mira.home'), true); + } + + public function testRegister() + { + $output = "output of a file"; + $this->assertEquals(Mira\Render::register('/output/', '', $output), ' of a file'); + } + + public function testGetSubdomain() + { + $_SERVER['HTTP_HOST'] = "domain.domainName.com"; + $this->assertEquals(Mira\Render::getSubdomain(), 'domain'); + } + + public function testMultiTenancy() + { + $_SERVER['HTTP_HOST'] = "domain.domainName.com"; + $this->assertEquals(Mira\Render::multiTenancy(), true); + } + + /** + * @runInSeparateProcess + */ + public function testRedirect() + { + $this->assertEquals(Mira\Render::redirect('/'), true); + } + + public function testGetConfigWithSplitParamters() + { + $this->assertEquals(Mira\Render::getConfig('mira.home'), []); + } + + public function testGetConfigWithoutSplitParamters() + { + $this->assertEquals(Mira\Render::getConfig('mira'), []); + } + + public function testGetConfigWithAppThatDoesntExist() + { + $this->assertTrue(is_array(Mira\Render::getConfig('noneexistantapp'))); + } + + public function testCompileMustache() + { + $output = "{{ 'testing' }}"; + $this->assertEquals(Mira\Render::compileMustache($output), ""); + } + + public function testCompileIfStatements() + { + $output = "@if (1) @endif"; + $this->assertEquals(Mira\Render::compileIfStatements($output), " "); + } + + public function testCompileComments() + { + $output = "@comment hey @endcomment"; + $this->assertEquals(Mira\Render::compileComments($output), " hey"); + } + + public function testCompileUnless() + { + $output = "@unless (1) @endunless"; + $this->assertEquals(Mira\Render::compileUnless($output), ""); + } + + public function testCompileUse() + { + $output = "@use Mira\Testing"; + $this->assertEquals(Mira\Render::compileUse($output), ""); + } + + public function testGetTemplateTags() + { + $output = "@use Mira\Testing"; + $this->assertEquals(Mira\Render::getTemplateTags($output), ""); + } + + public function testGetTemplateEngine() + { + $template = "mira.home"; + $template = explode(".", $template); + $this->assertEquals(Mira\Render::templateEngine($template, []), ""); + } + + public function testGetTemplateEngineWithMultiTenancy() + { + $_SERVER['HTTP_HOST'] = "mira.domainName.com"; + $template = "mira.home"; + $template = explode(".", $template); + $this->assertEquals(Mira\Render::templateEngine($template, []), ""); + } + + public function testGetTemplateEngineWrongTemplate() + { + $_SERVER['HTTP_HOST'] = "mira.domainName.com"; + $template = "mira.wrongTemplate"; + $template = explode(".", $template); + $this->assertEquals(Mira\Render::templateEngine($template, []), ""); + } + + public function testRenderViewWithMultiTenancy(){ + $_SERVER['HTTP_HOST'] = "mira.domainName.com"; + $template = "mira.home"; + $this->assertEquals(Mira\Render::view($template, []), true); + } + + public function testRenderViewWithoutMultiTenancy(){ + $template = "mira.home"; + $this->assertEquals(Mira\Render::view($template, []), true); + } + + public function testRenderViewWithIncorrectTemplate(){ + $template = "mira.wrongtemplate"; + $this->assertEquals(Mira\Render::view($template, []), true); + } + + public function testRenderViewWithIncorrectApp() + { + $template = "wrongApp.wrongtemplate"; + $this->assertEquals(Mira\Render::view($template, []), true); + } + + public function testRenderViewWithNoApp() + { + $template = ""; + $this->assertEquals(Mira\Render::view($template, []), false); + } + + + + + + + + + + + + +}