Completed
Push — master ( b9f1e5...5ff555 )
by Aimeos
11:02
created

TestHelperCntl::createView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2021
6
 */
7
8
9
class TestHelperCntl
10
{
11
	private static $aimeos;
12
	private static $context;
13
14
15
	public static function bootstrap()
16
	{
17
		self::getAimeos();
18
		\Aimeos\MShop::cache( false );
19
	}
20
21
22
	public static function getContext( $site = 'unittest' )
23
	{
24
		if( !isset( self::$context[$site] ) ) {
25
			self::$context[$site] = self::createContext( $site );
26
		}
27
28
		return clone self::$context[$site];
29
	}
30
31
32
	public static function getAimeos()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
33
	{
34
		if( !isset( self::$aimeos ) )
35
		{
36
			require_once 'Bootstrap.php';
37
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
38
39
			$extdir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) );
40
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true );
41
		}
42
43
		return self::$aimeos;
44
	}
45
46
47
	/**
48
	 * @param string $site
49
	 */
50
	private static function createContext( $site )
51
	{
52
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
53
		$aimeos = self::getAimeos();
54
55
56
		$paths = $aimeos->getConfigPaths( 'mysql' );
57
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
58
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
59
60
		$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
61
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
62
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
63
		$ctx->setConfig( $conf );
64
65
66
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
67
		$ctx->setDatabaseManager( $dbm );
68
69
70
		$logger = new \Aimeos\MW\Logger\File( 'unittest.log', \Aimeos\MW\Logger\Base::DEBUG );
71
		$ctx->setLogger( $logger );
72
73
74
		$session = new \Aimeos\MW\Session\None();
75
		$ctx->setSession( $session );
76
77
78
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
79
		$ctx->setI18n( array( 'de' => $i18n ) );
80
81
82
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
83
		$locale = $localeManager->bootstrap( $site, '', '', false );
84
		$ctx->setLocale( $locale );
85
86
87
		$view = self::createView( $conf );
88
		$ctx->setView( $view );
89
90
91
		$ctx->setEditor( 'core:controller/common' );
92
93
		return $ctx;
94
	}
95
96
97
	protected static function createView( \Aimeos\MW\Config\Iface $config )
98
	{
99
		$view = new \Aimeos\MW\View\Standard( self::getAimeos()->getCustomPaths( 'client/html/templates' ) );
100
101
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
102
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
103
		$view->addHelper( 'translate', $helper );
104
105
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
106
		$view->addHelper( 'url', $helper );
107
108
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
109
		$view->addHelper( 'number', $helper );
110
111
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
112
		$view->addHelper( 'date', $helper );
113
114
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, ['controller/jobs', 'client/html', 'resource/fs/baseurl'] );
115
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
116
		$view->addHelper( 'config', $helper );
117
118
		return $view;
119
	}
120
}
121