<commit_before><?php
/*
 * Copyright 2010 <NAME> <<EMAIL> at gmail dot com>
 *
 * This file is part of CoOrg.
 *
 * CoOrg is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

  * CoOrg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.

  * You should have received a copy of the GNU Affero General Public License
  * along with CoOrg.  If not, see <http://www.gnu.org/licenses/>.
*/

class ControllerTest extends PHPUnit_Framework_TestCase {
	public function setUp() {
		CoOrg::setSite('http://www.test.info/');
		CoOrg::spoofReferer('http://www.test.info/some/part/of/the/site');
		$config = new Config('config/tests.config.php');
		CoOrg::init($config, 'coorg/tests/mocks/app', 'coorg/tests/mocks/plugins');
		CoOrgSmarty::$vars = array();
	}
	
	public function tearDown() {
		CoOrg::clear();
	}

	public function testVariablesSet()
	{
		CoOrg::config()->set('path', '/the/path/');
		CoOrg::process('en/alpha/show/someID/someParameter');
		$this->assertEquals('someID', AlphaController::$objectRetrieve);
		$this->assertEquals(array('coorgRequest' => 'alpha/show/someID/someParameter',
		                          'coorgUrl' => '/the/path/en/alpha/show/someID/someParameter',
		                          'value' => 'value', /* value, name and string come from the alphacontroller*/
		                          'name' => 'name', 
		                          'string' => 'string',
		                          'object' => 'someID',
		                          'param' => 'someParameter'),
		                    CoOrgSmarty::$vars);
	}
	
	public function testCoOrgURLOnHome()
	{
		CoOrg::config()->set('path', '/the/path/');
		CoOrg::process('en/');
		$this->assertEquals(array('coorgRequest' => '',
		                          'coorgUrl' => '/the/path/en',
		                          'language' => 'en'),
		                    CoOrgSmarty::$vars);
	}
	
	public function testBaseHTMLRendered()
	{
		CoOrg::process('alpha/show/someID/someParameter');
		$this->assertEquals(file_get_contents('coorg/tests/alphashowoutput.html'),
		                    CoOrgSmarty::$renderedOutput);
	}
	
	public function testTemplateNotFound()
	{
		CoOrg::process('alpha/bogus');
		$this->assertEquals(Header::$errorCode, '500 Internal Server Error');
		$this->assertEquals('alpha/bogus', CoOrgSmarty::$vars['request']);
		$this->assertEquals('http://www.test.info/some/part/of/the/site', CoOrgSmarty::$vars['referer']);
		$this->assertEquals('Template bogus.html.tpl not found', CoOrgSmarty::$vars['exception']->getMessage());
		<commit_msg>Fix 2 CoOrg tests<commit_after><?php
/*
 * Copyright 2010 <NAME> <<EMAIL>>
 *
 * This file is part of CoOrg.
 *
 * CoOrg is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

  * CoOrg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.

  * You should have received a copy of the GNU Affero General Public License
  * along with CoOrg.  If not, see <http://www.gnu.org/licenses/>.
*/

class ControllerTest extends PHPUnit_Framework_TestCase {
	public function setUp() {
		CoOrg::setSite('http://www.test.info/');
		CoOrg::spoofReferer('http://www.test.info/some/part/of/the/site');
		$config = new Config('config/tests.config.php');
		CoOrg::init($config, 'coorg/tests/mocks/app', 'coorg/tests/mocks/plugins');
		CoOrgSmarty::$vars = array();
	}
	
	public function tearDown() {
		CoOrg::clear();
	}

	public function testVariablesSet()
	{
		CoOrg::config()->set('path', '/the/path/');
		CoOrg::process('en/alpha/show/someID/someParameter');
		$this->assertEquals('someID', AlphaController::$objectRetrieve);
		$this->assertEquals(array('coorgRequest' => 'alpha/show/someID/someParameter',
		                          'coorgUrl' => '/the/path/en/alpha/show/someID/someParameter',
		                          'staticPath' => '/the/path/static/',
		                          'value' => 'value', /* value, name and string come from the alphacontroller*/
		                          'name' => 'name', 
		                          'string' => 'string',
		                          'object' => 'someID',
		                          'param' => 'someParameter'),
		                    CoOrgSmarty::$vars);
	}
	
	public function testCoOrgURLOnHome()
	{
		CoOrg::config()->set('path', '/the/path/');
		CoOrg::process('en/');
		$this->assertEquals(array('coorgRequest' => '',
		                          'coorgUrl' => '/the/path/en',
		                          'staticPath' => '/the/path/static/',
		                          'language' => 'en'),
		                    CoOrgSmarty::$vars);
	}
	
	public function testBaseHTMLRendered()
	{
		CoOrg::process('alpha/show/someID/someParameter');
		$this->assertEquals(file_get_contents('coorg/tests/alphashowoutput.html'),
		                    CoOrgSmarty::$renderedOutput);
	}
	
	public function testTemplateNotFound()
	{
		CoOrg::process('alpha/bogus');
		$this->assertEquals(Header::$errorCode, '500 Internal Server Error');
		$this->assertEquals('alpha/bogus', CoOrgSmarty::$vars['request']);
		$this->assertEquals('http://www.test.info/some/part/of/the/site', CoOrgSmarty::$vars['referer']);
		$this->assertEquals('Template bogus.html.tpl not found', CoOrgSmarty::$vars['exception']->getMessage());
		
{'fraction_non_alphanumeric': 0.15026169171028195, 'fraction_numerical': 0.0028701671450278576, 'mean_word_length': 2.92317880794702, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, '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': '3493941', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1741, 'n_words': 407}