1 | <?php |
||
9 | class TestHelperCntl |
||
10 | { |
||
11 | private static $aimeos; |
||
12 | private static $context; |
||
13 | |||
14 | |||
15 | public static function bootstrap() |
||
16 | { |
||
17 | self::getAimeos(); |
||
18 | \Aimeos\MShop::cache( false ); |
||
19 | } |
||
20 | |||
21 | |||
22 | public static function getContext( $site = 'unittest' ) |
||
23 | { |
||
24 | if( !isset( self::$context[$site] ) ) { |
||
25 | self::$context[$site] = self::createContext( $site ); |
||
26 | } |
||
27 | |||
28 | return clone self::$context[$site]; |
||
29 | } |
||
30 | |||
31 | |||
32 | public static function getAimeos() |
||
33 | { |
||
34 | if( !isset( self::$aimeos ) ) |
||
35 | { |
||
36 | require_once 'Bootstrap.php'; |
||
37 | spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
||
38 | |||
39 | $extdir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); |
||
40 | self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true ); |
||
41 | } |
||
42 | |||
43 | return self::$aimeos; |
||
44 | } |
||
45 | |||
46 | |||
47 | /** |
||
48 | * @param string $site |
||
49 | */ |
||
50 | private static function createContext( $site ) |
||
51 | { |
||
52 | $ctx = new \Aimeos\MShop\Context\Item\Standard(); |
||
53 | $aimeos = self::getAimeos(); |
||
54 | |||
55 | |||
56 | $paths = $aimeos->getConfigPaths( 'mysql' ); |
||
57 | $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
||
58 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
||
59 | |||
60 | $conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
||
61 | $conf = new \Aimeos\MW\Config\Decorator\Memory( $conf ); |
||
62 | $conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file ); |
||
63 | $ctx->setConfig( $conf ); |
||
64 | |||
65 | |||
66 | $dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
||
67 | $ctx->setDatabaseManager( $dbm ); |
||
68 | |||
69 | |||
70 | $logger = new \Aimeos\MW\Logger\File( 'unittest.log', \Aimeos\MW\Logger\Base::DEBUG ); |
||
71 | $ctx->setLogger( $logger ); |
||
72 | |||
73 | |||
74 | $session = new \Aimeos\MW\Session\None(); |
||
75 | $ctx->setSession( $session ); |
||
76 | |||
77 | |||
78 | $i18n = new \Aimeos\MW\Translation\None( 'de' ); |
||
79 | $ctx->setI18n( array( 'de' => $i18n ) ); |
||
80 | |||
81 | |||
82 | $localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx ); |
||
83 | $locale = $localeManager->bootstrap( $site, '', '', false ); |
||
84 | $ctx->setLocale( $locale ); |
||
85 | |||
86 | |||
87 | $view = self::createView( $conf ); |
||
88 | $ctx->setView( $view ); |
||
89 | |||
90 | |||
91 | $ctx->setEditor( 'core:controller/common' ); |
||
92 | |||
93 | return $ctx; |
||
94 | } |
||
95 | |||
96 | |||
97 | protected static function createView( \Aimeos\MW\Config\Iface $config ) |
||
119 | } |
||
120 | } |
||
121 |