summaryrefslogtreecommitdiffstats
path: root/tests/mocks/core/common.php
blob: 2e8265b15d6069dc2f5b4be1db0d98df8c6966e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php

// Set up the global CI functions in their most minimal core representation

if ( ! function_exists('get_instance'))
{
	function &get_instance()
	{
		$test = CI_TestCase::instance();
		$test = $test->ci_instance();
		return $test;
	}
}

// --------------------------------------------------------------------

if ( ! function_exists('get_config'))
{
	function &get_config()
	{
		$test = CI_TestCase::instance();
		$config = $test->ci_get_config();
		return $config;
	}
}

if ( ! function_exists('config_item'))
{
	function config_item($item)
	{
		$config =& get_config();

		if ( ! isset($config[$item]))
		{
			return NULL;
		}

		return $config[$item];
	}
}

if ( ! function_exists('get_mimes'))
{
	/**
	 * Returns the MIME types array from config/mimes.php
	 *
	 * @return	array
	 */
	function &get_mimes()
	{
		static $_mimes = array();

		if (empty($_mimes))
		{
			$path = realpath(PROJECT_BASE.'application/config/mimes.php');
			if (is_file($path))
			{
				$_mimes = include($path);
			}
		}

		return $_mimes;
	}
}

// --------------------------------------------------------------------

/*
if ( ! function_exists('load_class'))
{
	function load_class($class, $directory = 'libraries', $prefix = 'CI_')
	{
		if ($directory !== 'core' OR $prefix !== 'CI_')
		{
			throw new Exception('Not Implemented: Non-core load_class()');
		}

		$test = CI_TestCase::instance();

		$obj =& $test->ci_core_class($class);

		if (is_string($obj))
		{
			throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
		}

		return $obj;
	}
}
*/

// Clean up error messages
// --------------------------------------------------------------------

if ( ! function_exists('show_error'))
{
	function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
	{
		throw new RuntimeException('CI Error: '.$message);
	}
}

if ( ! function_exists('show_404'))
{
	function show_404($page = '', $log_error = TRUE)
	{
		throw new RuntimeException('CI Error: 404');
	}
}

if ( ! function_exists('_exception_handler'))
{
	function _exception_handler($severity, $message, $filepath, $line)
	{
		throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
	}
}

// We assume a few things about our environment ...
// --------------------------------------------------------------------
if ( ! function_exists('is_loaded'))
{
	function &is_loaded()
	{
		$loaded = array();
		return $loaded;
	}
}

if ( ! function_exists('log_message'))
{
	function log_message($level, $message)
	{
		return TRUE;
	}
}

if ( ! function_exists('set_status_header'))
{
	function set_status_header($code = 200, $text = '')
	{
		return TRUE;
	}
}

if ( ! function_exists('is_cli'))
{
	// In order to test HTTP functionality, we need to lie about this
	function is_cli()
	{
		return FALSE;
	}
}