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