Passed
Branch master (d032f7)
by Aimeos
05:30
created

TestHelperJqadm::getView()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 47
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 30
nc 2
nop 2
dl 0
loc 47
rs 9.44
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2018
6
 */
7
class TestHelperJqadm
8
{
9
	private static $aimeos;
10
	private static $context = [];
11
12
13
	public static function bootstrap()
14
	{
15
		self::getAimeos();
16
		\Aimeos\MShop::cache( false );
17
	}
18
19
20
	public static function getContext( $site = 'unittest' )
21
	{
22
		if( !isset( self::$context[$site] ) ) {
23
			self::$context[$site] = self::createContext( $site );
24
		}
25
26
		return clone self::$context[$site];
27
	}
28
29
30
	public static function getView( $site = 'unittest', \Aimeos\MW\Config\Iface $config = null )
31
	{
32
		if( $config === null ) {
33
			$config = self::getContext( $site )->getConfig();
34
		}
35
36
		$view = new \Aimeos\MW\View\Standard( self::getTemplatePaths() );
37
38
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['site' => 'unittest'] );
39
		$view->addHelper( 'param', $helper );
40
41
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
42
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
43
		$view->addHelper( 'translate', $helper );
44
45
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
46
		$view->addHelper( 'url', $helper );
47
48
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
49
		$view->addHelper( 'number', $helper );
50
51
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
52
		$view->addHelper( 'date', $helper );
53
54
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, ['admin', 'resource/fs/baseurl'] );
55
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
56
		$view->addHelper( 'config', $helper );
57
58
		$helper = new \Aimeos\MW\View\Helper\Session\Standard( $view, new \Aimeos\MW\Session\None() );
59
		$view->addHelper( 'session', $helper );
60
61
		$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...
62
		$view->addHelper( 'request', $helper );
63
64
		$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...
65
		$view->addHelper( 'response', $helper );
66
67
		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' );
68
		$view->addHelper( 'csrf', $helper );
69
70
		$fcn = function() { return array( 'admin' ); };
71
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, $fcn );
72
		$view->addHelper( 'access', $helper );
73
74
		$view->pageSitePath = [];
75
76
		return $view;
77
	}
78
79
80
	public static function getTemplatePaths()
81
	{
82
		return self::getAimeos()->getCustomPaths( 'admin/jqadm/templates' );
83
	}
84
85
86
	public static function getAimeos()
87
	{
88
		if( !isset( self::$aimeos ) )
89
		{
90
			require_once 'Bootstrap.php';
91
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
92
93
			$extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
94
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false );
95
		}
96
97
		return self::$aimeos;
98
	}
99
100
101
	/**
102
	 * @param string $site
103
	 */
104
	private static function createContext( $site )
105
	{
106
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
107
		$aimeos = self::getAimeos();
108
109
110
		$paths = $aimeos->getConfigPaths( 'mysql' );
111
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
112
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
113
		$local = array( 'resource' => array( 'fs' => array( 'adapter' => 'Standard', 'basedir' => __DIR__ . '/tmp' ) ) );
114
115
		$conf = new \Aimeos\MW\Config\PHPArray( $local, $paths );
116
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
117
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
118
		$ctx->setConfig( $conf );
119
120
121
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
122
		$ctx->setDatabaseManager( $dbm );
123
124
125
		$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $conf );
126
		$ctx->setFilesystemManager( $fs );
127
128
129
		$mq = new \Aimeos\MW\MQueue\Manager\Standard( $conf );
130
		$ctx->setMessageQueueManager( $mq );
131
132
133
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
134
		$ctx->setLogger( $logger );
135
136
137
		$cache = new \Aimeos\MW\Cache\None();
138
		$ctx->setCache( $cache );
139
140
141
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
142
		$ctx->setI18n( array( 'de' => $i18n ) );
143
144
145
		$session = new \Aimeos\MW\Session\None();
146
		$ctx->setSession( $session );
147
148
149
		$localeManager = \Aimeos\MShop::create( $ctx, 'locale' );
150
		$locale = $localeManager->bootstrap( $site, '', '', false );
1 ignored issue
show
Bug introduced by
The method bootstrap() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Locale\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Order\Manager\Base\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

150
		/** @scrutinizer ignore-call */ 
151
  $locale = $localeManager->bootstrap( $site, '', '', false );
Loading history...
151
		$ctx->setLocale( $locale );
152
153
154
		$ctx->setEditor( 'ai-admin-jqadm:admin/jqadm' );
155
156
		return $ctx;
157
	}
158
}
159