Passed
Branch master (4f99e3)
by Aimeos
04:48
created

TestHelperHtml::getAimeos()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
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-2018
7
 */
8
class TestHelperHtml
9
{
10
	private static $aimeos;
11
	private static $context = [];
12
13
14
	public static function bootstrap()
15
	{
16
		self::getAimeos();
17
		\Aimeos\MShop::cache( false );
18
		\Aimeos\Controller\Frontend::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 getView( $site = 'unittest', \Aimeos\MW\Config\Iface $config = null )
33
	{
34
		if( $config === null ) {
35
			$config = self::getContext( $site )->getConfig();
36
		}
37
38
		$view = new \Aimeos\MW\View\Standard( self::getHtmlTemplatePaths() );
39
40
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
41
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
42
		$view->addHelper( 'translate', $helper );
43
44
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
45
		$view->addHelper( 'url', $helper );
46
47
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
48
		$view->addHelper( 'number', $helper );
49
50
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
51
		$view->addHelper( 'date', $helper );
52
53
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, ['client', 'resource/fs/baseurl'] );
54
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
55
		$view->addHelper( 'config', $helper );
56
57
		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' );
58
		$view->addHelper( 'csrf', $helper );
59
60
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, new \Zend\Diactoros\ServerRequest() );
0 ignored issues
show
Bug introduced by
The type Zend\Diactoros\ServerRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
		$view->addHelper( 'request', $helper );
62
63
		$helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, new \Zend\Diactoros\Response() );
0 ignored issues
show
Bug introduced by
The type Zend\Diactoros\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
		$view->addHelper( 'response', $helper );
65
66
		return $view;
67
	}
68
69
70
	public static function getHtmlTemplatePaths()
71
	{
72
		return self::getAimeos()->getCustomPaths( 'client/html/templates' );
73
	}
74
75
76
	private static function getAimeos()
77
	{
78
		if( !isset( self::$aimeos ) )
79
		{
80
			require_once 'Bootstrap.php';
81
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
82
83
			$extdir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) );
84
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true );
85
		}
86
87
		return self::$aimeos;
88
	}
89
90
91
	/**
92
	 * @param string $site
93
	 */
94
	private static function createContext( $site )
95
	{
96
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
97
		$aimeos = self::getAimeos();
98
99
100
		$paths = $aimeos->getConfigPaths();
101
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
102
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
103
		$local = array( 'resource' => array( 'fs' => array( 'adapter' => 'Standard', 'basedir' => __DIR__ . '/tmp' ) ) );
104
105
		$conf = new \Aimeos\MW\Config\PHPArray( $local, $paths );
106
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
107
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
108
		$ctx->setConfig( $conf );
109
110
111
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
112
		$ctx->setLogger( $logger );
113
114
115
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
116
		$ctx->setDatabaseManager( $dbm );
117
118
119
		$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $conf );
120
		$ctx->setFilesystemManager( $fs );
121
122
123
		$mq = new \Aimeos\MW\MQueue\Manager\Standard( $conf );
124
		$ctx->setMessageQueueManager( $mq );
125
126
127
		$cache = new \Aimeos\MW\Cache\None();
128
		$ctx->setCache( $cache );
129
130
131
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
132
		$ctx->setI18n( array( 'de' => $i18n ) );
133
134
135
		$session = new \Aimeos\MW\Session\None();
136
		$ctx->setSession( $session );
137
138
139
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
140
		$locale = $localeManager->bootstrap( $site, '', '', false );
141
		$ctx->setLocale( $locale );
142
143
144
		$ctx->setEditor( 'core:client/html' );
145
146
		return $ctx;
147
	}
148
}
149