1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
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 view( $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
|
|
|
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
62
|
|
|
$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $psr17Factory->createServerRequest( 'GET', 'https://aimeos.org' ) ); |
63
|
|
|
$view->addHelper( 'request', $helper ); |
64
|
|
|
|
65
|
|
|
$helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, $psr17Factory->createResponse() ); |
66
|
|
|
$view->addHelper( 'response', $helper ); |
67
|
|
|
|
68
|
|
|
$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' ); |
69
|
|
|
$view->addHelper( 'csrf', $helper ); |
70
|
|
|
|
71
|
|
|
$helper = new \Aimeos\MW\View\Helper\Access\All( $view ); |
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()->getTemplatePaths( '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 ); |
151
|
|
|
$ctx->setLocale( $locale ); |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
$ctx->setEditor( 'ai-admin-jqadm:admin/jqadm' ); |
155
|
|
|
|
156
|
|
|
return $ctx; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|