Completed
Push — master ( d16df8...f0e5c7 )
by Aimeos
10:41
created

TestHelperJqadm   C

Complexity

Total Complexity 9

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 23

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 23
dl 0
loc 131
rs 5.5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 6 1
A getContext() 0 8 2
B getView() 0 30 2
A getTemplatePaths() 0 4 1
A getAimeos() 0 13 2
A createContext() 0 50 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015
6
 */
7
class TestHelperJqadm
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
	private static $aimeos;
10
	private static $context = array();
11
12
13
	public static function bootstrap()
14
	{
15
		self::getAimeos();
16
		\Aimeos\MShop\Factory::setCache( false );
17
		\Aimeos\Controller\Frontend\Factory::setCache( false );
18
	}
19
20
21
	public static function getContext( $site = 'unittest' )
22
	{
23
		if( !isset( self::$context[$site] ) ) {
24
			self::$context[$site] = self::createContext( $site );
25
		}
26
27
		return clone self::$context[$site];
28
	}
29
30
31
	public static function getView( $site = 'unittest', \Aimeos\MW\Config\Iface $config = null )
32
	{
33
		if( $config === null ) {
34
			$config = self::getContext( $site )->getConfig();
35
		}
36
37
		$view = new \Aimeos\MW\View\Standard( self::getTemplatePaths() );
38
39
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
40
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
41
		$view->addHelper( 'translate', $helper );
42
43
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
44
		$view->addHelper( 'url', $helper );
45
46
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
47
		$view->addHelper( 'number', $helper );
48
49
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
50
		$view->addHelper( 'date', $helper );
51
52
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'admin', 'client/html', 'controller/jsonadm' ) );
53
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
54
		$view->addHelper( 'config', $helper );
55
56
		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' );
57
		$view->addHelper( 'csrf', $helper );
58
59
		return $view;
60
	}
61
62
63
	public static function getTemplatePaths()
64
	{
65
		return self::getAimeos()->getCustomPaths( 'admin/jqadm/templates' );
66
	}
67
68
69
	private static function getAimeos()
70
	{
71
		if( !isset( self::$aimeos ) )
72
		{
73
			require_once 'Bootstrap.php';
74
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
75
76
			$extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
77
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false );
78
		}
79
80
		return self::$aimeos;
81
	}
82
83
84
	/**
85
	 * @param string $site
86
	 */
87
	private static function createContext( $site )
88
	{
89
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
90
		$aimeos = self::getAimeos();
91
92
93
		$paths = $aimeos->getConfigPaths( 'mysql' );
94
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
95
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
96
		$local = array( 'resource' => array( 'fs' => array( 'adapter' => 'Standard', 'basedir' => __DIR__ . '/tmp' ) ) );
97
98
		$conf = new \Aimeos\MW\Config\PHPArray( $local, $paths );
99
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
100
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
101
		$ctx->setConfig( $conf );
102
103
104
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
105
		$ctx->setDatabaseManager( $dbm );
106
107
108
		$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $conf );
109
		$ctx->setFilesystemManager( $fs );
110
111
112
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
113
		$ctx->setLogger( $logger );
114
115
116
		$cache = new \Aimeos\MW\Cache\None();
117
		$ctx->setCache( $cache );
118
119
120
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
121
		$ctx->setI18n( array( 'de' => $i18n ) );
122
123
124
		$session = new \Aimeos\MW\Session\None();
125
		$ctx->setSession( $session );
126
127
128
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx );
129
		$locale = $localeManager->bootstrap( $site, '', '', false );
130
		$ctx->setLocale( $locale );
131
132
133
		$ctx->setEditor( 'core:admin/jqadm' );
134
135
		return $ctx;
136
	}
137
}
138