<commit_before><?php

use erdiko\core\Response;
require_once dirname(__DIR__).'/ErdikoTestCase.php';


class ResponseTest extends ErdikoTestCase
{
    var $ResponseObj=null;
    var $webRoot=null;

    function setUp() {
       
        $this->ResponseObj = new Response;

        $this->webRoot = dirname(dirname(__DIR__));
        //echo $this->webRoot;
    }


    function tearDown()
    {
        unset($this->ResponseObj);
    }

    function testSetDataValueAndGetDataValue()
    {
        $key = 'Test_Key';
        $data = 'Test_Data';
        $this->ResponseObj->setDataValue($key, $data);
        $return = $this->ResponseObj->getDataValue($key);
        $this->assertTrue($return == $data);
    }

    function testSetTheme()
    {
        $theme = 'theme';
        $this->ResponseObj->setTheme($theme);
        $return = $this->ResponseObj->getTheme();
        $this->assertTrue($return == $theme);
    }

    function testSetThemeTemplate()
    {
        $themeTemplate = 'themeTemplate';
        $this->ResponseObj->setThemeTemplate($themeTemplate);
        $return = $this->ResponseObj->getThemeTemplate();
        $this->assertTrue($return == $themeTemplate);
    }
    
    function testSetContent()
    {
        $content = 'Here are some content';
        $this->ResponseObj->setContent($content);
        $return = $this->ResponseObj->getContent();
        $this->assertTrue($return == $content);
    }
    
    function testAppendContent()
    {
        $content = 'Here are some content';
        $this->ResponseObj->setContent($content);
        $return = $this->ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $appContent = '...more content...';
        $this->ResponseObj->appendContent($appContent);
        $return = $this->ResponseObj->getContent();
        $this->assertTrue($return == $content.$appContent);
    }

    function testRender()
    {
        $ResponseObj = new Response;

        $theme = new erdiko\core\Theme('bootstrap', null, 'default');
        $ResponseObj->setTheme($theme);
        $return = $ResponseObj->getTheme();
        $this->assertTrue($return == $theme);

        //Add some content
        $content = 'Here are some content';
        $ResponseObj->setContent($content);
        $return = $ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $return = $ResponseObj->render();
        
        
        /** 
         *  Compare header, content, and footer
         *
         */
        $themeFolder = $ResponseObj->getTheme()->getThemeFolder();
        
        //Header
        $header = file_get_contents($themeFolder.'/templates/page/header.php');
        $pos = strrpos($header, 'navbar-brand');
        $header = substr($header, 0, $pos);
        $find = strrpos($return, $header);
        $this->assertTrue($find != false);

        //Footer
        $footer = file_get_contents($themeFolder.'/templates/page/footer.php');
        $pos = strrpos($footer, 'nav nav-justified');
        $footer = substr($footer, 0, $pos);
        $find = strrpos($return, $footer);
        $this->assertTrue($find != false);

        //Content
        $find = strrpos($return, $content);
        $this->assertTrue($find != false);


        unset($ResponseObj);

        /** 
         *  Test the second condition
         *
         */
        $ResponseObj = new Response;
        

        $ResponseObj->setThemeName('bootstrap');
        $return = $ResponseObj->getTheme();
        
        //Add some content
        $content = 'Here are some content';
        $ResponseObj->setContent($content);
        $return = $ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $return = $ResponseObj->render();
        
        /** 
         *  Compare header, content, and footer
         *
         */
        $themeFolder = $ResponseObj->getTheme()->getThemeFolder();
        
        //Header
        $header = file_get_contents($themeFolder.'/templates/page/header.php');
        $pos = strrpos($header, 'navbar-brand');
        $header = substr($header, 0, $pos);
        $find = strrpos($return, $header);
        $this->assertTrue($find != false);

        //Footer
        $footer = file_get_contents($themeFolder.'/templates/page/footer.php');
        $pos = strrpos($footer, 'nav nav-justified');
        $footer = substr($footer, 0, $pos);
        $find = strrpos($return, $footer);
        $this->assertTrue($find != false);

        //Content
        $find = strrpos($return, $content);
        $this->assertTrue($find != false);

        unset($ResponseObj);

        /** 
         *  Test the third condition
         *
         */
        $ResponseObj = new Response;

        $content = 'Here are some content';
        $ResponseObj->setContent($content);
        $return = $ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $return = $ResponseObj->render();
        
        //Content
        echo $return;
        $find = strrpos($return, $content);
        $this->assertTrue($find == 0);

        unset($ResponseObj);
    }

    function testSend()
    {
        
    }

  }
?>

<commit_msg>Cleaned up Response class.<commit_after><?php

use erdiko\core\Response;
require_once dirname(__DIR__).'/ErdikoTestCase.php';


class ResponseTest extends ErdikoTestCase
{
    var $ResponseObj=null;

    function setUp() {
        $this->ResponseObj = new Response;
    }

    function tearDown()
    {
        unset($this->ResponseObj);
    }

    /**
     * @expectedException
     */
    function testSetDataValueAndGetDataValue()
    {
        /**
         * First test
         * 
         * Set a key and then get the key
         */
        $key = 'Test_Key';
        $data = 'Test_Data';
        $this->ResponseObj->setDataValue($key, $data);
        $return = $this->ResponseObj->getDataValue($key);
        $this->assertTrue($return == $data);

        /**
         * Second test
         * 
         * Try to get a non exist key
         */
        $key = 'Test_Non_Exist_Key';
        //$return = $this->ResponseObj->getDataValue($key);
        //var_dump($return);

        //$this->assertTrue($return == $data);
    }

    function testSetTheme()
    {
        $theme = 'theme';
        $this->ResponseObj->setTheme($theme);
        $return = $this->ResponseObj->getTheme();
        $this->assertTrue($return == $theme);
    }

    function testSetThemeTemplate()
    {
        $themeTemplate = 'themeTemplate';
        $this->ResponseObj->setThemeTemplate($themeTemplate);
        $return = $this->ResponseObj->getThemeTemplate();
        $this->assertTrue($return == $themeTemplate);
    }
    
    function testSetContent()
    {
        $content = 'Test content';
        $this->ResponseObj->setContent($content);
        $return = $this->ResponseObj->getContent();
        $this->assertTrue($return == $content);
    }
    
    function testAppendContent()
    {
        $content = 'Test content';
        $this->ResponseObj->setContent($content);
        $return = $this->ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $appContent = 'Second test content';
        $this->ResponseObj->appendContent($appContent);
        $return = $this->ResponseObj->getContent();
        $this->assertTrue($return == $content.$appContent);
    }

    function testRender()
    {
        /** 
         *
         *  Test the first condition in render()
         *
         */
        $ResponseObj = new Response;

        //Set a theme object
        $theme = new erdiko\core\Theme('bootstrap', null, 'default');
        $ResponseObj->setTheme($theme);
        //Get the theme object and check if they are the same object
        $return = $ResponseObj->getTheme();
        $this->assertTrue($return == $theme);

        //Add content
        $content = 'Test content';
        $ResponseObj->setContent($content);
        //Get content and validate the content
        $return = $ResponseObj->getContent();
        $this->assertTrue($return == $content);

        //Perform the render function
        $return = $ResponseObj->render();
        
        
        /** 
         *  Validate the content
         */
        $themeFolder = $ResponseObj->getTheme()->getThemeFolder();
        
        //Header
        $header = file_get_contents($themeFolder.'/templates/page/header.php');
        $pos = strrpos($header, 'navbar-brand');
        $header = substr($header, 0, $pos);
        $find = strrpos($return, $header);
        $this->assertTrue($find != false);

        //Footer
        $footer = file_get_contents($themeFolder.'/templates/page/footer.php');
        $pos = strrpos($footer, 'nav nav-justified');
        $footer = substr($footer, 0, $pos);
        $find = strrpos($return, $footer);
        $this->assertTrue($find != false);

        //Content
        $find = strrpos($return, $content);
        $this->assertTrue($find != false);

        unset($ResponseObj);

        /** 
         *
         *  Test the second condition in render()
         *
         */
        $ResponseObj = new Response;
        

        $ResponseObj->setThemeName('bootstrap');
        $return = $ResponseObj->getTheme();
        
        //Add some content
        $content = 'Test content';
        $ResponseObj->setContent($content);
        $return = $ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $return = $ResponseObj->render();
        
        /** 
         *  Validate the content
         */
        $themeFolder = $ResponseObj->getTheme()->getThemeFolder();
        
        //Header
        $header = file_get_contents($themeFolder.'/templates/page/header.php');
        $pos = strrpos($header, 'navbar-brand');
        $header = substr($header, 0, $pos);
        $find = strrpos($return, $header);
        $this->assertTrue($find != false);

        //Footer
        $footer = file_get_contents($themeFolder.'/templates/page/footer.php');
        $pos = strrpos($footer, 'nav nav-justified');
        $footer = substr($footer, 0, $pos);
        $find = strrpos($return, $footer);
        $this->assertTrue($find != false);

        //Content
        $find = strrpos($return, $content);
        $this->assertTrue($find != false);

        unset($ResponseObj);

        /** 
         *
         *  Test the third condition in render()
         *
         */
        $ResponseObj = new Response;

        $content = 'Test content';
        $ResponseObj->setContent($content);
        $return = $ResponseObj->getContent();
        $this->assertTrue($return == $content);

        $return = $ResponseObj->render();
        
        //Content
        $find = strrpos($return, $content);
        $this->assertTrue($find == 0);

        unset($ResponseObj);
    }

    function testSend()
    {
        
    }

  }
?>


{'fraction_non_alphanumeric': 0.15537190082644628, 'fraction_numerical': 0.0009182736455463728, 'mean_word_length': 2.0782928208027136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 130, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3687380', 'n_tokens_mistral': 3069, 'n_tokens_neox': 3027, 'n_words': 568}