aimeos /
ai-gettext
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | class TestHelper |
||
| 5 | { |
||
| 6 | private static $aimeos; |
||
| 7 | private static $context = []; |
||
| 8 | |||
| 9 | |||
| 10 | public static function bootstrap() |
||
| 11 | { |
||
| 12 | $aimeos = self::getAimeos(); |
||
| 13 | |||
| 14 | $includepaths = $aimeos->getIncludePaths(); |
||
| 15 | $includepaths[] = get_include_path(); |
||
| 16 | set_include_path( implode( PATH_SEPARATOR, $includepaths ) ); |
||
| 17 | } |
||
| 18 | |||
| 19 | |||
| 20 | public static function context( $site = 'unittest' ) |
||
| 21 | { |
||
| 22 | if( !isset( self::$context[$site] ) ) { |
||
| 23 | self::$context[$site] = self::createContext( $site ); |
||
| 24 | } |
||
| 25 | |||
| 26 | return clone self::$context[$site]; |
||
| 27 | } |
||
| 28 | |||
| 29 | |||
| 30 | private static function getAimeos() |
||
| 31 | { |
||
| 32 | if( !isset( self::$aimeos ) ) |
||
| 33 | { |
||
| 34 | require_once 'Bootstrap.php'; |
||
| 35 | spl_autoload_register( 'Aimeos\Bootstrap::autoload' ); |
||
| 36 | |||
| 37 | $extdir = dirname( dirname( dirname( __DIR__ ) ) ); |
||
| 38 | self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false ); |
||
| 39 | } |
||
| 40 | |||
| 41 | return self::$aimeos; |
||
| 42 | } |
||
| 43 | |||
| 44 | |||
| 45 | private static function createContext( $site ) |
||
| 46 | { |
||
| 47 | $ctx = new \Aimeos\MShop\Context\Item\Standard(); |
||
| 48 | $aimeos = self::getAimeos(); |
||
| 49 | |||
| 50 | |||
| 51 | $paths = $aimeos->getConfigPaths( 'mysql' ); |
||
| 52 | $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
||
| 53 | |||
| 54 | $conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
||
| 55 | $ctx->setConfig( $conf ); |
||
| 56 | |||
| 57 | |||
| 58 | $dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
||
| 59 | $ctx->setDatabaseManager( $dbm ); |
||
| 60 | |||
| 61 | |||
| 62 | $logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Iface::DEBUG ); |
||
| 63 | $ctx->setLogger( $logger ); |
||
| 64 | |||
| 65 | |||
| 66 | $cache = new \Aimeos\MW\Cache\None(); |
||
| 67 | $ctx->setCache( $cache ); |
||
| 68 | |||
| 69 | |||
| 70 | $i18n = new \Aimeos\MW\Translation\None( 'de' ); |
||
| 71 | $ctx->setI18n( array( 'de' => $i18n ) ); |
||
| 72 | |||
| 73 | |||
| 74 | $session = new \Aimeos\MW\Session\None(); |
||
| 75 | $ctx->setSession( $session ); |
||
| 76 | |||
| 77 | |||
| 78 | $localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx ); |
||
| 79 | $localeItem = $localeManager->bootstrap( $site, '', '', false ); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 80 | |||
| 81 | $ctx->setLocale( $localeItem ); |
||
| 82 | |||
| 83 | $ctx->setEditor( 'ai-gettext:lib/custom' ); |
||
| 84 | |||
| 85 | return $ctx; |
||
| 86 | } |
||
| 87 | } |
||
| 88 |