1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class TestHelper |
9
|
|
|
{ |
10
|
|
|
private static $aimeos; |
11
|
|
|
private static $context = []; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
public static function bootstrap() |
15
|
|
|
{ |
16
|
|
|
$mshop = self::getAimeos(); |
17
|
|
|
|
18
|
|
|
$includepaths = $mshop->getIncludePaths(); |
19
|
|
|
$includepaths[] = get_include_path(); |
20
|
|
|
set_include_path( implode( PATH_SEPARATOR, $includepaths ) ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
public static function getContext( $site = 'unittest' ) |
25
|
|
|
{ |
26
|
|
|
if( !isset( self::$context[$site] ) ) { |
27
|
|
|
self::$context[$site] = self::createContext( $site ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return clone self::$context[$site]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
private static function getAimeos() |
35
|
|
|
{ |
36
|
|
|
if( !isset( self::$aimeos ) ) |
37
|
|
|
{ |
38
|
|
|
require_once 'Bootstrap.php'; |
39
|
|
|
spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
40
|
|
|
|
41
|
|
|
$extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
42
|
|
|
self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return self::$aimeos; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Creates a new context item. |
51
|
|
|
* |
52
|
|
|
* @param string $site Unique site code |
53
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object |
54
|
|
|
*/ |
55
|
|
|
private static function createContext( $site ) |
56
|
|
|
{ |
57
|
|
|
$ctx = new \Aimeos\MShop\Context\Item\Standard(); |
58
|
|
|
$mshop = self::getAimeos(); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$paths = $mshop->getConfigPaths( 'mysql' ); |
62
|
|
|
$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
63
|
|
|
|
64
|
|
|
$conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
65
|
|
|
$ctx->setConfig( $conf ); |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
69
|
|
|
$ctx->setDatabaseManager( $dbm ); |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG ); |
73
|
|
|
$ctx->setLogger( $logger ); |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
$session = new \Aimeos\MW\Session\None(); |
77
|
|
|
$ctx->setSession( $session ); |
78
|
|
|
|
79
|
|
|
$ctx->setEditor( 'ai-flow:lib/custom' ); |
80
|
|
|
|
81
|
|
|
return $ctx; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|