1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2022 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TestHelper |
10
|
|
|
{ |
11
|
|
|
private static $aimeos; |
12
|
|
|
private static $context = []; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
public static function bootstrap() |
16
|
|
|
{ |
17
|
|
|
$aimeos = self::getAimeos(); |
|
|
|
|
18
|
|
|
\Aimeos\MShop::cache( false ); |
19
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
public static function context( $site = 'unittest' ) |
24
|
|
|
{ |
25
|
|
|
if( !isset( self::$context[$site] ) ) { |
26
|
|
|
self::$context[$site] = self::createContext( $site ); |
27
|
|
|
self::$context[$site]->setView( self::view( self::$context[$site]->config() ) ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return clone self::$context[$site]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public static function view( \Aimeos\Base\Config\Iface $config ) |
35
|
|
|
{ |
36
|
|
|
$view = new \Aimeos\MW\View\Standard( self::getTemplatePaths() ); |
37
|
|
|
|
38
|
|
|
$trans = new \Aimeos\Base\Translation\None( 'en' ); |
39
|
|
|
$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans ); |
40
|
|
|
$view->addHelper( 'translate', $helper ); |
41
|
|
|
|
42
|
|
|
$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'baseurl' ); |
43
|
|
|
$view->addHelper( 'url', $helper ); |
44
|
|
|
|
45
|
|
|
$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' ); |
46
|
|
|
$view->addHelper( 'number', $helper ); |
47
|
|
|
|
48
|
|
|
$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' ); |
49
|
|
|
$view->addHelper( 'date', $helper ); |
50
|
|
|
|
51
|
|
|
$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config ); |
52
|
|
|
$view->addHelper( 'config', $helper ); |
53
|
|
|
|
54
|
|
|
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
55
|
|
|
$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $psr17Factory->createServerRequest( 'GET', 'https://aimeos.org' ) ); |
56
|
|
|
$view->addHelper( 'request', $helper ); |
57
|
|
|
|
58
|
|
|
$helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, $psr17Factory->createResponse() ); |
59
|
|
|
$view->addHelper( 'response', $helper ); |
60
|
|
|
|
61
|
|
|
return $view; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public static function getTemplatePaths() |
66
|
|
|
{ |
67
|
|
|
return self::getAimeos()->getTemplatePaths( 'client/jsonapi/templates' ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
private static function getAimeos() |
72
|
|
|
{ |
73
|
|
|
if( !isset( self::$aimeos ) ) |
74
|
|
|
{ |
75
|
|
|
require_once 'Bootstrap.php'; |
76
|
|
|
spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
77
|
|
|
|
78
|
|
|
$extdir = dirname( dirname( dirname( dirname( __DIR__ ) ) ) ); |
79
|
|
|
self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return self::$aimeos; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
private static function createContext( $site ) |
87
|
|
|
{ |
88
|
|
|
$ctx = new \Aimeos\MShop\Context\Item\Standard(); |
89
|
|
|
$aimeos = self::getAimeos(); |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
$paths = $aimeos->getConfigPaths(); |
93
|
|
|
$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
94
|
|
|
$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
95
|
|
|
|
96
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( [], $paths ); |
97
|
|
|
$conf = new \Aimeos\Base\Config\Decorator\Memory( $conf ); |
98
|
|
|
$conf = new \Aimeos\Base\Config\Decorator\Documentor( $conf, $file ); |
99
|
|
|
$ctx->setConfig( $conf ); |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
$dbm = new \Aimeos\MW\DB\Manager\DBAL( $conf ); |
103
|
|
|
$ctx->setDatabaseManager( $dbm ); |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
$mq = new \Aimeos\MW\MQueue\Manager\Standard( $conf ); |
107
|
|
|
$ctx->setMessageQueueManager( $mq ); |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
$logger = new \Aimeos\Base\Logger\File( $site . '.log', \Aimeos\Base\Logger\Iface::DEBUG ); |
111
|
|
|
$ctx->setLogger( $logger ); |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
$cache = new \Aimeos\MW\Cache\None(); |
115
|
|
|
$ctx->setCache( $cache ); |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
$i18n = new \Aimeos\Base\Translation\None( 'en' ); |
119
|
|
|
$ctx->setI18n( array( 'en' => $i18n ) ); |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
$session = new \Aimeos\Base\Session\None(); |
123
|
|
|
$ctx->setSession( $session ); |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx ); |
127
|
|
|
$locale = $localeManager->bootstrap( $site, '', '', false ); |
128
|
|
|
$ctx->setLocale( $locale ); |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
$ctx->setEditor( 'ai-client-jsonapi:client/jsonapi' ); |
132
|
|
|
|
133
|
|
|
return $ctx; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|