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