1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Aimeos (aimeos.org), 2017-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 | $aimeos = self::getAimeos(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
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] )->setToken( md5( microtime( true ) ) ); |
||
31 | } |
||
32 | |||
33 | |||
34 | public static function view( \Aimeos\Base\Config\Iface $config ) |
||
35 | { |
||
36 | $view = new \Aimeos\Base\View\Standard( self::getTemplatePaths() ); |
||
37 | |||
38 | $trans = new \Aimeos\Base\Translation\None( 'en' ); |
||
39 | $helper = new \Aimeos\Base\View\Helper\Translate\Standard( $view, $trans ); |
||
40 | $view->addHelper( 'translate', $helper ); |
||
41 | |||
42 | $helper = new \Aimeos\Base\View\Helper\Url\Standard( $view, 'baseurl' ); |
||
43 | $view->addHelper( 'url', $helper ); |
||
44 | |||
45 | $helper = new \Aimeos\Base\View\Helper\Number\Standard( $view, '.', '' ); |
||
46 | $view->addHelper( 'number', $helper ); |
||
47 | |||
48 | $helper = new \Aimeos\Base\View\Helper\Date\Standard( $view, 'Y-m-d' ); |
||
49 | $view->addHelper( 'date', $helper ); |
||
50 | |||
51 | $helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $config ); |
||
52 | $view->addHelper( 'config', $helper ); |
||
53 | |||
54 | $psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
||
55 | $helper = new \Aimeos\Base\View\Helper\Request\Standard( $view, $psr17Factory->createServerRequest( 'GET', 'https://aimeos.org' ) ); |
||
56 | $view->addHelper( 'request', $helper ); |
||
57 | |||
58 | $helper = new \Aimeos\Base\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(); |
||
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( ['client' => ['jsonapi' => ['debug' => true]]], $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\Base\DB\Manager\Standard( $conf->get( 'resource', [] ), 'DBAL' ); |
||
103 | $ctx->setDatabaseManager( $dbm ); |
||
104 | |||
105 | |||
106 | $mq = new \Aimeos\Base\MQueue\Manager\Standard( $conf->get( 'resource', [] ) ); |
||
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\Base\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 | $passwd = new \Aimeos\Base\Password\Standard(); |
||
123 | $ctx->setPassword( $passwd ); |
||
124 | |||
125 | |||
126 | $session = new \Aimeos\Base\Session\None(); |
||
127 | $ctx->setSession( $session ); |
||
128 | |||
129 | |||
130 | $localeManager = \Aimeos\MShop::create( $ctx, 'locale' ); |
||
131 | $locale = $localeManager->bootstrap( $site, '', '', false ); |
||
132 | $ctx->setLocale( $locale ); |
||
133 | |||
134 | |||
135 | $ctx->setEditor( 'ai-client-jsonapi' ); |
||
136 | |||
137 | return $ctx; |
||
138 | } |
||
139 | } |
||
140 |