<commit_before><?php
session_start();

class MinimalTest extends PHPUnit_Framework_TestCase {

	public function test_core() {
		require_once('lib/core.inc.php');
		print 'core : ';
		
		// Is secured server connection ?
		unset($_SERVER['HTTPS']);
		$this->assertEquals(server_is_secure(), false);

		$_SERVER['HTTPS'] = 'off';
		$this->assertEquals(server_is_secure(), false);

		$_SERVER['HTTPS'] = 'OFF';
		$this->assertEquals(server_is_secure(), false);

		$_SERVER['HTTPS'] = 'on';
		$this->assertEquals(server_is_secure(), true);

		$_SERVER['HTTPS'] = 'not_empty_or_off';
		$this->assertEquals(server_is_secure(), true);

		$_SERVER['SERVER_PORT'] = 443;
		$this->assertEquals(server_is_secure(), true);

		// Are guid uniques ?
		$this->assertNotEquals(guid(), guid());

		// Are hash uniques to a particular object ?
		$this->assertEquals(object_hash(null), object_hash(''));
		$this->assertNotEquals(object_hash(null), object_hash(array()));

		$this->assertEquals(object_hash('a'), object_hash('a'));
		$this->assertNotEquals(object_hash('a'), object_hash('b'));

		$this->assertEquals(object_hash(array('a')), object_hash(array('a')));
		$this->assertNotEquals(object_hash(array()), object_hash(array('a')));
		$this->assertNotEquals(object_hash(array('a')), object_hash(array('b')));
		$this->assertNotEquals(object_hash(array('a')), object_hash(array('b')));

		$obj = new stdclass;
		$this->assertEquals(object_hash($obj), object_hash($obj));
		$this->assertNotEquals(object_hash($obj), object_hash(new stdclass));

		print 'done' . "\r\n";
	}

	public function test_var() {
		
		plugin_require('var');

		print 'var : ';

		$this->assertNull(var_get('path'));

		// Check string path accessors
		$this->assertTrue(var_set('path', true));
		$this->assertTrue(var_get('path'));
		
		$this->assertTrue(var_set('path/path2', true));
		$this->assertTrue(var_get('path/path2'));

		$data = array('path' => array('path2' => null));
		$this->assertTrue(var_set('path/path2', true, $data));
		$this->assertTrue(var_get('path/path2', null, $data));

		// Check array key path accessors
		$this->assertTrue(var_set(array('arrayPath'), true));
		$this->assertTrue(var_get('arrayPath'));

		$this->assertTrue(var_set(array('arrayPath', 'arrayPath2'), true));
		$this->assertTrue(var_get('arrayPath/arrayPath2'));

		$data = array('arrayPath' => array('arrayPath2' => null));
		$this->assertTrue(var_set(array('arrayPath', 'arrayPath2'), true, $data));
		$this->assertTrue(var_get(array('arrayPath', 'arrayPath2'), null, $data));

		// Check session accessors
		$this->assertTrue(session_var_set(array('arrayPath'), true));
		$this->assertTrue(session_var_get('arrayPath'));

		$this->assertTrue(session_var_set(array('arrayPath', 'arrayPath2'), true));
		$this->assertTrue(session_var_get('arrayPath/arrayPath2'));

		// Append to arrays
		var_append('arrayPath', 'arrayPath3');
		$this->assertContains('arrayPath3', var_get('arrayPath'));
		
		// Append only to arrays
		$this->assertFalse(var_append(array('arrayPath', 'arrayPath2'), 'arrayPath4'));
		
		var_set('arrayPath/arrayPath2', array());
		var_append(array('arrayPath', 'arrayPath2'), 'arrayPath4');

		$this->assertContains('arrayPath4', var_get('arrayPath/arrayPath2'));

		$data = array();
		var_append(array('arrayPath', 'arrayPath2'), 'arrayPath4', $data);
		$this->assertContains('arrayPath4', var_get('arrayPath/arrayPath2', null, $data));

		// Array unset
		var_unset('arrayPath/arrayPath2');
		$this->assertArrayNotHasKey('arrayPath2', var_get('arrayPath'));
		$this->assertArrayHasKey('arrayPath', vars());
		
		print 'done' . "\r\n";		
	}


	public function test_hook() {
		require_once('lib/hook.inc.php');
		
		print 'hook : ';

		$this->assertNull(hook_do('my_first_hook'));

		hook_register('my_first_hook', function () {
			return true;
		});

		$this->assertTrue(hook_do('my_first_hook'));

		hook_unregister('my_first_hook');

		$this->assertNull(hook_do('my_first_hook'));

		hook_register('my_second_hook', function () {
			return 'a';
		}, 2);

		hook_register('my_second_hook', function () {
			return 'b';
		});

		hook_register('my_second_hook', function () {
			return 'c';
		}, -2);

		$this->assertEquals(hook_do('my_second_hook'), 'cba');

		print 'done' . "\r\n";<commit_msg>update tests using on/trigger new methods<commit_after><?php
session_start();

class MinimalTest extends PHPUnit_Framework_TestCase {

	public function test_core() {
		require_once('lib/core.inc.php');
		print 'core : ';
		
		// Is secured server connection ?
		unset($_SERVER['HTTPS']);
		$this->assertEquals(server_is_secure(), false);

		$_SERVER['HTTPS'] = 'off';
		$this->assertEquals(server_is_secure(), false);

		$_SERVER['HTTPS'] = 'OFF';
		$this->assertEquals(server_is_secure(), false);

		$_SERVER['HTTPS'] = 'on';
		$this->assertEquals(server_is_secure(), true);

		$_SERVER['HTTPS'] = 'not_empty_or_off';
		$this->assertEquals(server_is_secure(), true);

		$_SERVER['SERVER_PORT'] = 443;
		$this->assertEquals(server_is_secure(), true);

		// Are guid uniques ?
		$this->assertNotEquals(guid(), guid());

		// Are hash uniques to a particular object ?
		$this->assertEquals(object_hash(null), object_hash(''));
		$this->assertNotEquals(object_hash(null), object_hash(array()));

		$this->assertEquals(object_hash('a'), object_hash('a'));
		$this->assertNotEquals(object_hash('a'), object_hash('b'));

		$this->assertEquals(object_hash(array('a')), object_hash(array('a')));
		$this->assertNotEquals(object_hash(array()), object_hash(array('a')));
		$this->assertNotEquals(object_hash(array('a')), object_hash(array('b')));
		$this->assertNotEquals(object_hash(array('a')), object_hash(array('b')));

		$obj = new stdclass;
		$this->assertEquals(object_hash($obj), object_hash($obj));
		$this->assertNotEquals(object_hash($obj), object_hash(new stdclass));

		print 'done' . "\r\n";
	}

	public function test_var() {
		
		plugin_require('var');

		print 'var : ';

		$this->assertNull(var_get('path'));

		// Check string path accessors
		$this->assertTrue(var_set('path', true));
		$this->assertTrue(var_get('path'));
		
		$this->assertTrue(var_set('path/path2', true));
		$this->assertTrue(var_get('path/path2'));

		$data = array('path' => array('path2' => null));
		$this->assertTrue(var_set('path/path2', true, $data));
		$this->assertTrue(var_get('path/path2', null, $data));

		// Check array key path accessors
		$this->assertTrue(var_set(array('arrayPath'), true));
		$this->assertTrue(var_get('arrayPath'));

		$this->assertTrue(var_set(array('arrayPath', 'arrayPath2'), true));
		$this->assertTrue(var_get('arrayPath/arrayPath2'));

		$data = array('arrayPath' => array('arrayPath2' => null));
		$this->assertTrue(var_set(array('arrayPath', 'arrayPath2'), true, $data));
		$this->assertTrue(var_get(array('arrayPath', 'arrayPath2'), null, $data));

		// Check session accessors
		$this->assertTrue(session_var_set(array('arrayPath'), true));
		$this->assertTrue(session_var_get('arrayPath'));

		$this->assertTrue(session_var_set(array('arrayPath', 'arrayPath2'), true));
		$this->assertTrue(session_var_get('arrayPath/arrayPath2'));

		// Append to arrays
		var_append('arrayPath', 'arrayPath3');
		$this->assertContains('arrayPath3', var_get('arrayPath'));
		
		// Append only to arrays
		$this->assertFalse(var_append(array('arrayPath', 'arrayPath2'), 'arrayPath4'));
		
		var_set('arrayPath/arrayPath2', array());
		var_append(array('arrayPath', 'arrayPath2'), 'arrayPath4');

		$this->assertContains('arrayPath4', var_get('arrayPath/arrayPath2'));

		$data = array();
		var_append(array('arrayPath', 'arrayPath2'), 'arrayPath4', $data);
		$this->assertContains('arrayPath4', var_get('arrayPath/arrayPath2', null, $data));

		// Array unset
		var_unset('arrayPath/arrayPath2');
		$this->assertArrayNotHasKey('arrayPath2', var_get('arrayPath'));
		$this->assertArrayHasKey('arrayPath', vars());
		
		print 'done' . "\r\n";		
	}


	public function test_event() {
		require_once('lib/event.inc.php');
		
		print 'event : ';

		$this->assertNull(trigger('my_first_event'));

		on('my_first_event', function () {
			return true;
		});

		$this->assertTrue(trigger('my_first_event'));

		off('my_first_event');

		$this->assertNull(trigger('my_first_event'));

		on('my_second_event', function () {
			return 'a';
		}, 2);

		on('my_second_event', function () {
			return 'b';
		});

		on('my_second_event', function () {
			return 'c';
		}, -2);

		$this->assertEquals(trigger('my_second_event'), 'cba');

		print 'done' . "\r\n";
{'fraction_non_alphanumeric': 0.20265195963388877, 'fraction_numerical': 0.007509974184463741, 'mean_word_length': 6.026380873866446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, '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': '6145773', 'n_tokens_mistral': 3140, 'n_tokens_neox': 2866, 'n_words': 430}