1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace CodeIgniterGetText\Tests; |
3
|
|
|
|
4
|
|
|
require_once('include/gettext_test_functions.php'); |
5
|
|
|
require_once('include/gettext_test_constants.php'); |
6
|
|
|
|
7
|
|
|
class LibraryTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
private function _regex($expression, $successful = TRUE) |
11
|
|
|
{ |
12
|
|
|
$log = ($successful ? 'info' : 'debug'); |
13
|
|
|
$regex = '/(' . $log . '|).*(' . $expression . ')/'; |
14
|
|
|
|
15
|
|
|
return ($regex); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testCatalogCodeset() |
19
|
|
|
{ |
20
|
|
|
$this->expectOutputRegex($this->_regex('bind text domain code set')); |
21
|
|
|
$this->_library(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testLocaleDir() |
25
|
|
|
{ |
26
|
|
|
$this->expectOutputRegex($this->_regex('bind text domain directory')); |
27
|
|
|
$this->_library(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testTextDomain() |
31
|
|
|
{ |
32
|
|
|
$this->expectOutputRegex($this->_regex('set text domain')); |
33
|
|
|
$this->_library(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testLocale() |
37
|
|
|
{ |
38
|
|
|
$this->expectOutputRegex($this->_regex('set locale')); |
39
|
|
|
$this->_library(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testEnvironmentLanguage() |
43
|
|
|
{ |
44
|
|
|
$this->expectOutputRegex($this->_regex('set environment language')); |
45
|
|
|
$this->_library(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testFileExists() |
49
|
|
|
{ |
50
|
|
|
$this->expectOutputRegex($this->_regex('check MO file exists')); |
51
|
|
|
$this->_library(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function _library() |
55
|
|
|
{ |
56
|
|
|
$config = array(); |
57
|
|
|
/* |
|
|
|
|
58
|
|
|
$config = array( |
59
|
|
|
'gettext_locale_dir' => $CI->config->item('gettext_locale_dir'), |
60
|
|
|
'gettext_text_domain' => $CI->config->item('gettext_text_domain'), |
61
|
|
|
'gettext_catalog_codeset' => $CI->config->item('gettext_catalog_codeset'), |
62
|
|
|
'gettext_locale' => $CI->config->item('gettext_locale') |
63
|
|
|
); |
64
|
|
|
*/ |
65
|
|
|
|
66
|
|
|
// Load default config array |
67
|
|
|
require(realpath(dirname(__FILE__) . '/../') . '/src/config/gettext.php'); |
68
|
|
|
|
69
|
|
|
\Gettext::init($config); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.