Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

TestHelperJobs   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 21

Importance

Changes 0
Metric Value
dl 0
loc 157
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 21

6 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 5 1
A getContext() 0 8 2
A getAimeos() 0 11 2
A getControllerPaths() 0 4 1
A createContext() 0 53 1
A createView() 0 28 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 */
8
9
10
class TestHelperJobs
11
{
12
	private static $aimeos;
13
	private static $context;
14
15
16
	/**
17
	 * Initializes the environment
18
	 */
19
	public static function bootstrap()
20
	{
21
		self::getAimeos();
22
		\Aimeos\MShop\Factory::setCache( false );
23
	}
24
25
26
	/**
27
	 * Returns the context object
28
	 *
29
	 * @param string $site Site code
30
	 * @return \Aimeos\MShop\Context\Item\Iface Context object
31
	 */
32
	public static function getContext( $site = 'unittest' )
33
	{
34
		if( !isset( self::$context[$site] ) ) {
35
			self::$context[$site] = self::createContext( $site );
36
		}
37
38
		return clone self::$context[$site];
39
	}
40
41
42
	/**
43
	 * Returns the Aimeos bootstrap object
44
	 *
45
	 * @return \Aimeos\Bootstrap Aimeos bootstrap object
46
	 */
47
	public static function getAimeos()
48
	{
49
		if( !isset( self::$aimeos ) )
50
		{
51
			require_once dirname( dirname( dirname( __DIR__ ) ) ) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
52
53
			self::$aimeos = new \Aimeos\Bootstrap( [], false );
54
		}
55
56
		return self::$aimeos;
57
	}
58
59
60
	/**
61
	 * Returns the list of controller paths
62
	 *
63
	 * @return array Controller paths
64
	 */
65
	public static function getControllerPaths()
66
	{
67
		return self::getAimeos()->getCustomPaths( 'controller/jobs' );
68
	}
69
70
71
	/**
72
	 * Creates a new context object
73
	 *
74
	 * @param string $site Site code
75
	 * @return \Aimeos\MShop\Context\Item\Iface Context object
76
	 */
77
	private static function createContext( $site )
78
	{
79
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
80
		$aimeos = self::getAimeos();
81
82
83
		$paths = $aimeos->getConfigPaths();
84
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
85
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
86
87
		$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
88
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
89
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
90
		$ctx->setConfig( $conf );
91
92
93
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
94
		$ctx->setLogger( $logger );
95
96
97
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
98
		$ctx->setDatabaseManager( $dbm );
99
100
101
		$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $conf );
102
		$ctx->setFilesystemManager( $fs );
103
104
105
		$mq = new \Aimeos\MW\MQueue\Manager\Standard( $conf );
106
		$ctx->setMessageQueueManager( $mq );
107
108
109
		$session = new \Aimeos\MW\Session\None();
110
		$ctx->setSession( $session );
111
112
113
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
114
		$ctx->setI18n( array( 'de' => $i18n ) );
115
116
117
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx );
118
		$locale = $localeManager->bootstrap( $site, 'de', '', false );
119
		$ctx->setLocale( $locale );
120
121
122
		$view = self::createView( $conf );
123
		$ctx->setView( $view );
124
125
126
		$ctx->setEditor( 'core:controller/jobs' );
127
128
		return $ctx;
129
	}
130
131
132
	/**
133
	 * Creates a new view object
134
	 *
135
	 * @param \Aimeos\MW\Config\Iface $config Configuration object
136
	 * @return \Aimeos\MW\View\Iface View object
137
	 */
138
	protected static function createView( \Aimeos\MW\Config\Iface $config )
139
	{
140
		$tmplpaths = array_merge_recursive(
141
			self::getAimeos()->getCustomPaths( 'client/html/templates' ),
142
			self::getAimeos()->getCustomPaths( 'controller/jobs/templates' )
143
		);
144
145
		$view = new \Aimeos\MW\View\Standard( $tmplpaths );
146
147
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
148
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
149
		$view->addHelper( 'translate', $helper );
150
151
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
152
		$view->addHelper( 'url', $helper );
153
154
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
155
		$view->addHelper( 'number', $helper );
156
157
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
158
		$view->addHelper( 'date', $helper );
159
160
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'controller/jobs', 'client/html' ) );
161
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
162
		$view->addHelper( 'config', $helper );
163
164
		return $view;
165
	}
166
}
167