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

TestHelperCustom::getView()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 9.312
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2018
6
 */
7
class TestHelperCustom
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
		$param = ['site' => 'unittest'];
39
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
40
		$view->addHelper( 'param', $helper );
41
42
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
43
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
44
		$view->addHelper( 'translate', $helper );
45
46
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
47
		$view->addHelper( 'url', $helper );
48
49
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
50
		$view->addHelper( 'number', $helper );
51
52
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
53
		$view->addHelper( 'date', $helper );
54
55
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'admin', 'client/html', 'controller/jsonadm' ) );
56
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
57
		$view->addHelper( 'config', $helper );
58
59
		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' );
60
		$view->addHelper( 'csrf', $helper );
61
62
		$fcn = function() { return array( 'admin' ); };
63
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, $fcn );
64
		$view->addHelper( 'access', $helper );
65
66
		return $view;
67
	}
68
69
70
	public static function getTemplatePaths()
71
	{
72
		return self::getAimeos()->getCustomPaths( 'admin/jqadm/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( __FILE__ ) ) ) );
84
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false );
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
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
112
		$ctx->setDatabaseManager( $dbm );
113
114
115
		$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $conf );
116
		$ctx->setFilesystemManager( $fs );
117
118
119
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
120
		$ctx->setLogger( $logger );
121
122
123
		$cache = new \Aimeos\MW\Cache\None();
124
		$ctx->setCache( $cache );
125
126
127
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
128
		$ctx->setI18n( array( 'de' => $i18n ) );
129
130
131
		$session = new \Aimeos\MW\Session\None();
132
		$ctx->setSession( $session );
133
134
135
		$localeManager = \Aimeos\MShop::create( $ctx, 'locale' );
136
		$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

136
		/** @scrutinizer ignore-call */ 
137
  $locale = $localeManager->bootstrap( $site, '', '', false );
Loading history...
137
		$ctx->setLocale( $locale );
138
139
140
		$ctx->setEditor( 'ai-admin-jqadm:lib/custom' );
141
142
		return $ctx;
143
	}
144
}
145