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