<?php

namespace KupShop\AdminBundle\Tests;

class ifModuleTest extends \DatabaseTestCase
{
    public function testIfModule()
    {
        $smarty = createSmarty(true, true);

        $smarty->setForceCompile(true);
        $template = $smarty->fetch($this->getTemplatePath('ifModuleTest.tpl'));

        $this->assertContains('<div id="div11">', $template);
        $this->assertContains('<div id="div11">', $template);
        $this->assertContains('<div id="div41">', $template);
        $this->assertContains('<div id="div51">', $template);
        $this->assertContains('<div id="div51">', $template);
        $this->assertContains('<div id="div61">', $template);
        $this->assertContains('<div id="div81">', $template);

        $this->assertNotContains('<div id="div21">', $template);
        $this->assertNotContains('<div id="div22">', $template);
        $this->assertNotContains('<div id="div31">', $template);

        $this->assertEquals(7, substr_count($template, '<div>'));
        $this->assertEquals(17, substr_count($template, '</div>'));
    }

    protected function getTemplatePath($file)
    {
        if (!file_exists($file)) {
            $classFile = (new \ReflectionClass($this))->getFileName();
            $file = dirname($classFile).'/'.$file;
        }

        return $file;
    }
}
