1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2025 |
7
|
|
|
*/ |
8
|
|
|
class TestHelper |
9
|
|
|
{ |
10
|
|
|
private static $aimeos; |
11
|
|
|
private static $context = []; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
public static function bootstrap() |
15
|
|
|
{ |
16
|
|
|
$aimeos = self::getAimeos(); |
17
|
|
|
|
18
|
|
|
$includepaths = $aimeos->getIncludePaths(); |
19
|
|
|
$includepaths[] = get_include_path(); |
20
|
|
|
set_include_path( implode( PATH_SEPARATOR, $includepaths ) ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
public static function getAimeos() |
25
|
|
|
{ |
26
|
|
|
if( !isset( self::$aimeos ) ) |
27
|
|
|
{ |
28
|
|
|
require_once 'Bootstrap.php'; |
29
|
|
|
spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
30
|
|
|
|
31
|
|
|
self::$aimeos = new \Aimeos\Bootstrap(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return self::$aimeos; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public static function context( $site = 'unittest' ) |
39
|
|
|
{ |
40
|
|
|
if( !isset( self::$context[$site] ) ) { |
41
|
|
|
self::$context[$site] = self::createContext( $site ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return clone self::$context[$site]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
private static function createContext( $site ) |
49
|
|
|
{ |
50
|
|
|
$ctx = new \Aimeos\MShop\Context(); |
51
|
|
|
$aimeos = self::getAimeos(); |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
$paths = $aimeos->getConfigPaths(); |
55
|
|
|
$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
56
|
|
|
|
57
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( array(), $paths ); |
58
|
|
|
$ctx->setConfig( $conf ); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$dbm = new \Aimeos\Base\DB\Manager\Standard( $conf->get( 'resource', [] ), 'DBAL' ); |
62
|
|
|
$ctx->setDatabaseManager( $dbm ); |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
$logger = new \Aimeos\Base\Logger\File( $site . '.log', \Aimeos\Base\Logger\Iface::DEBUG ); |
66
|
|
|
$ctx->setLogger( $logger ); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
$cache = new \Aimeos\Base\Cache\None(); |
70
|
|
|
$ctx->setCache( $cache ); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
$passwd = new \Aimeos\Base\Password\Standard(); |
74
|
|
|
$ctx->setPassword( $passwd ); |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
$mail = new \Aimeos\Base\Mail\Manager\None(); |
78
|
|
|
$ctx->setMail( $mail ); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$i18n = new \Aimeos\Base\Translation\None( 'en' ); |
82
|
|
|
$ctx->setI18n( array( 'en' => $i18n ) ); |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
$session = new \Aimeos\Base\Session\None(); |
86
|
|
|
$ctx->setSession( $session ); |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
$localeManager = \Aimeos\MShop::create( $ctx, 'locale' ); |
90
|
|
|
$locale = $localeManager->bootstrap( $site, '', '', false ); |
|
|
|
|
91
|
|
|
$ctx->setLocale( $locale ); |
92
|
|
|
|
93
|
|
|
$view = self::view( $site, $conf ); |
94
|
|
|
$ctx->setView( $view ); |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
return $ctx->setEditor( 'ai-cms-grapesjs' ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public static function view( $site = 'unittest', ?\Aimeos\Base\Config\Iface $config = null ) |
102
|
|
|
{ |
103
|
|
|
$aimeos = self::getAimeos(); |
104
|
|
|
|
105
|
|
|
if( $config === null ) { |
106
|
|
|
$config = self::context( $site )->config(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$templates = array_merge_recursive( |
110
|
|
|
$aimeos->getTemplatePaths( 'admin/jqadm/templates' ), |
111
|
|
|
$aimeos->getTemplatePaths( 'client/html/templates' ), |
112
|
|
|
$aimeos->getTemplatePaths( 'client/jsonapi/templates' ) |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$view = new \Aimeos\Base\View\Standard( $templates ); |
116
|
|
|
|
117
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, ['site' => 'unittest'] ); |
118
|
|
|
$view->addHelper( 'param', $helper ); |
119
|
|
|
|
120
|
|
|
$helper = new \Aimeos\Base\View\Helper\Access\All( $view ); |
121
|
|
|
$view->addHelper( 'access', $helper ); |
122
|
|
|
|
123
|
|
|
$trans = new \Aimeos\Base\Translation\None( 'de_DE' ); |
124
|
|
|
$helper = new \Aimeos\Base\View\Helper\Translate\Standard( $view, $trans ); |
125
|
|
|
$view->addHelper( 'translate', $helper ); |
126
|
|
|
|
127
|
|
|
$helper = new \Aimeos\Base\View\Helper\Url\Standard( $view, 'http://baseurl' ); |
128
|
|
|
$view->addHelper( 'url', $helper ); |
129
|
|
|
|
130
|
|
|
$helper = new \Aimeos\Base\View\Helper\Number\Standard( $view, '.', '' ); |
131
|
|
|
$view->addHelper( 'number', $helper ); |
132
|
|
|
|
133
|
|
|
$helper = new \Aimeos\Base\View\Helper\Date\Standard( $view, 'Y-m-d' ); |
134
|
|
|
$view->addHelper( 'date', $helper ); |
135
|
|
|
|
136
|
|
|
$config = new \Aimeos\Base\Config\Decorator\Protect( $config, ['version', 'admin', 'client', 'resource/fs/baseurl', 'resource/fs-media/baseurl', 'resource/fs-theme/baseurl'] ); |
137
|
|
|
$helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $config ); |
138
|
|
|
$view->addHelper( 'config', $helper ); |
139
|
|
|
|
140
|
|
|
$helper = new \Aimeos\Base\View\Helper\Session\Standard( $view, new \Aimeos\Base\Session\None() ); |
141
|
|
|
$view->addHelper( 'session', $helper ); |
142
|
|
|
|
143
|
|
|
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
144
|
|
|
$helper = new \Aimeos\Base\View\Helper\Request\Standard( $view, $psr17Factory->createServerRequest( 'GET', 'https://aimeos.org' ) ); |
145
|
|
|
$view->addHelper( 'request', $helper ); |
146
|
|
|
|
147
|
|
|
$helper = new \Aimeos\Base\View\Helper\Response\Standard( $view, $psr17Factory->createResponse() ); |
148
|
|
|
$view->addHelper( 'response', $helper ); |
149
|
|
|
|
150
|
|
|
$helper = new \Aimeos\Base\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' ); |
151
|
|
|
$view->addHelper( 'csrf', $helper ); |
152
|
|
|
|
153
|
|
|
$view->pageSitePath = []; |
154
|
|
|
|
155
|
|
|
return $view; |
156
|
|
|
} |
157
|
|
|
} |