1 | <?php |
||
7 | class TestHelperCustom |
||
8 | { |
||
9 | private static $aimeos; |
||
10 | private static $context = []; |
||
11 | |||
12 | |||
13 | public static function bootstrap() |
||
14 | { |
||
15 | self::getAimeos(); |
||
16 | \Aimeos\MShop::cache( false ); |
||
17 | } |
||
18 | |||
19 | |||
20 | public static function getContext( $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 | public static function getView( $site = 'unittest', \Aimeos\MW\Config\Iface $config = null ) |
||
31 | { |
||
32 | if( $config === null ) { |
||
33 | $config = self::getContext( $site )->getConfig(); |
||
34 | } |
||
35 | |||
36 | $view = new \Aimeos\MW\View\Standard( self::getTemplatePaths() ); |
||
37 | |||
38 | $param = ['site' => 'unittest']; |
||
39 | $helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
||
40 | $view->addHelper( 'param', $helper ); |
||
41 | |||
42 | $trans = new \Aimeos\MW\Translation\None( 'de_DE' ); |
||
43 | $helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans ); |
||
44 | $view->addHelper( 'translate', $helper ); |
||
45 | |||
46 | $helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' ); |
||
47 | $view->addHelper( 'url', $helper ); |
||
48 | |||
49 | $helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' ); |
||
50 | $view->addHelper( 'number', $helper ); |
||
51 | |||
52 | $helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' ); |
||
53 | $view->addHelper( 'date', $helper ); |
||
54 | |||
55 | $config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'admin', 'client/html', 'controller/jsonadm' ) ); |
||
56 | $helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config ); |
||
57 | $view->addHelper( 'config', $helper ); |
||
58 | |||
59 | $helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' ); |
||
60 | $view->addHelper( 'csrf', $helper ); |
||
61 | |||
62 | $fcn = function() { return array( 'admin' ); }; |
||
63 | $helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, $fcn ); |
||
64 | $view->addHelper( 'access', $helper ); |
||
65 | |||
66 | return $view; |
||
67 | } |
||
68 | |||
69 | |||
70 | public static function getTemplatePaths() |
||
73 | } |
||
74 | |||
75 | |||
76 | private static function getAimeos() |
||
77 | { |
||
78 | if( !isset( self::$aimeos ) ) |
||
79 | { |
||
80 | require_once 'Bootstrap.php'; |
||
81 | spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
||
82 | |||
83 | $extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
||
84 | self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false ); |
||
85 | } |
||
86 | |||
87 | return self::$aimeos; |
||
88 | } |
||
89 | |||
90 | |||
91 | /** |
||
92 | * @param string $site |
||
93 | */ |
||
94 | private static function createContext( $site ) |
||
143 | } |
||
144 | } |
||
145 |