1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-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(); |
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 context( $site = 'unittest' ) |
26
|
|
|
{ |
27
|
|
|
if( !isset( self::$context[$site] ) ) { |
28
|
|
|
self::$context[$site] = self::createContext( $site ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return clone self::$context[$site]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public static function getAimeos() |
36
|
|
|
{ |
37
|
|
|
if( !isset( self::$aimeos ) ) |
38
|
|
|
{ |
39
|
|
|
require_once 'Bootstrap.php'; |
40
|
|
|
spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
41
|
|
|
|
42
|
|
|
self::$aimeos = new \Aimeos\Bootstrap(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return self::$aimeos; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
private static function createContext( $site ) |
50
|
|
|
{ |
51
|
|
|
$ctx = new \Aimeos\MShop\Context(); |
52
|
|
|
$aimeos = self::getAimeos(); |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
$paths = $aimeos->getConfigPaths(); |
56
|
|
|
$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
57
|
|
|
$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
58
|
|
|
|
59
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( [], $paths ); |
60
|
|
|
$conf = new \Aimeos\Base\Config\Decorator\Memory( $conf ); |
61
|
|
|
$conf = new \Aimeos\Base\Config\Decorator\Documentor( $conf, $file ); |
62
|
|
|
$ctx->setConfig( $conf ); |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
$dbm = new \Aimeos\Base\DB\Manager\Standard( $conf->get( 'resource', [] ), 'PDO' ); |
66
|
|
|
$ctx->setDatabaseManager( $dbm ); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
$logger = new \Aimeos\Base\Logger\File( $site . '.log', \Aimeos\Base\Logger\Iface::DEBUG ); |
70
|
|
|
$ctx->setLogger( $logger ); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
$i18n = new \Aimeos\Base\Translation\None( 'de' ); |
74
|
|
|
$ctx->setI18n( array( 'de' => $i18n ) ); |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
$session = new \Aimeos\Base\Session\None(); |
78
|
|
|
$ctx->setSession( $session ); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$localeManager = \Aimeos\MShop::create( $ctx, 'locale' ); |
82
|
|
|
$localeItem = $localeManager->bootstrap( $site, '', '', false ); |
|
|
|
|
83
|
|
|
$ctx->setLocale( $localeItem ); |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
return $ctx->setEditor( 'ai-symfony' ); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|