| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace Aimeos\Shop\Tests\Unit\Base; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  | class ContextTest extends \Neos\Flow\Tests\UnitTestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | 	private $object; | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | 	public function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | 		$this->object = new \Aimeos\Shop\Base\Context(); | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | 		$aimeos = new \Aimeos\Shop\Base\Aimeos(); | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | 		$config = new \Aimeos\Shop\Base\Config(); | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 		$i18n = new \Aimeos\Shop\Base\I18n(); | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | 		$locale = new \Aimeos\Shop\Base\Locale(); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 		$mailer = function() {}; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 		$session = $this->getMockBuilder( 'Neos\Flow\Session\Session' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 		$resource = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 			'host' => '127.0.0.1', | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 			'dbname' => 'flow', | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 			'user' => 'root', | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 			'password' => '', | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		$settings = array( 'flow' => array( 'apc' => array ( 'enable' => true ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		$this->inject( $config, 'aimeos', $aimeos ); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 		$this->inject( $i18n, 'aimeos', $aimeos ); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 		$this->inject( $this->object, 'i18n', $i18n ); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 		$this->inject( $this->object, 'aimeos', $aimeos ); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 		$this->inject( $this->object, 'config', $config ); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 		$this->inject( $this->object, 'locale', $locale ); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		$this->inject( $this->object, 'mailer', $mailer ); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 		$this->inject( $this->object, 'session', $session ); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 		$this->inject( $this->object, 'settings', $settings ); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 	public function tearDown() | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 		\Aimeos\MShop\Locale\Manager\Factory::injectManager( '\Aimeos\MShop\Locale\Manager\Standard', null ); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 	 * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  | 	public function get() | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 		$request = $this->getMockBuilder( '\Neos\Flow\Mvc\ActionRequest' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 			->setMethods( array( 'getArguments', 'getHttpRequest' ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 		$request->expects( $this->once() )->method( 'getArguments' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 			->will( $this->returnValue( array( 'site' => 'unittest', 'locale' => 'de', 'currency' => 'EUR' ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 		$httpRequest = $this->getMockBuilder( '\Neos\Flow\Http\Request' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  | 		$request->expects( $this->once() )->method( 'getHttpRequest' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 			->will( $this->returnValue( $httpRequest ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 		$localeManager = $this->getMockBuilder( '\Aimeos\MShop\Locale\Manager\Standard' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 			->setMethods( array( 'bootstrap' ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 		$localeManager->expects( $this->once() )->method( 'bootstrap' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 			->will( $this->returnValue( new \Aimeos\MShop\Locale\Item\Standard( array( 'locale.languageid' => 'de' ) ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 		\Aimeos\MShop\Locale\Manager\Factory::injectManager( '\Aimeos\MShop\Locale\Manager\Standard', $localeManager ); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 		$cache = $this->getMockBuilder( '\Neos\Cache\Frontend\StringFrontend' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 		$this->object->setCache( $cache ); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 		$context = $this->object->get( $request ); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 		$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $context ); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 	 * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 	public function getNoCache() | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 		$request = $this->getMockBuilder( '\Neos\Flow\Mvc\ActionRequest' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 			->setMethods( array( 'getArguments', 'getHttpRequest' ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 		$request->expects( $this->once() )->method( 'getArguments' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 			->will( $this->returnValue( array() ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 		$httpRequest = $this->getMockBuilder( '\Neos\Flow\Http\Request' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 		$request->expects( $this->once() )->method( 'getHttpRequest' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 			->will( $this->returnValue( $httpRequest ); | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  | 		$localeManager = $this->getMockBuilder( '\Aimeos\MShop\Locale\Manager\Standard' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  | 			->setMethods( array( 'bootstrap' ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  | 		$localeManager->expects( $this->once() )->method( 'bootstrap' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 			->will( $this->returnValue( new \Aimeos\MShop\Locale\Item\Standard( array( 'locale.languageid' => 'de' ) ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 		\Aimeos\MShop\Locale\Manager\Factory::injectManager( '\Aimeos\MShop\Locale\Manager\Standard', $localeManager ); | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  | 		$this->object->injectSettings( array( 'flow' => array( 'cache' => array( 'name' => 'None' ) ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 		$context = $this->object->get( $request ); | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 		$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $context ); | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  | 	 * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 	public function getCustomCache() | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 		$request = $this->getMockBuilder( '\Neos\Flow\Mvc\ActionRequest' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  | 			->setMethods( array( 'getArguments', 'getHttpRequest' ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 		$request->expects( $this->once() )->method( 'getArguments' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 			->will( $this->returnValue( array() ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  | 		$httpRequest = $this->getMockBuilder( '\Neos\Flow\Http\Request' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  | 		$request->expects( $this->once() )->method( 'getHttpRequest' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  | 			->will( $this->returnValue( $httpRequest ); | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  | 		$localeManager = $this->getMockBuilder( '\Aimeos\MShop\Locale\Manager\Standard' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  | 			->setMethods( array( 'bootstrap' ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  | 		$localeManager->expects( $this->once() )->method( 'bootstrap' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  | 			->will( $this->returnValue( new \Aimeos\MShop\Locale\Item\Standard( array( 'locale.languageid' => 'de' ) ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  | 		\Aimeos\MShop\Locale\Manager\Factory::injectManager( '\Aimeos\MShop\Locale\Manager\Standard', $localeManager ); | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  | 		$this->object->injectSettings( array( 'flow' => array( 'cache' => array( 'name' => 'Custom' ) ) ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  | 		$context = $this->object->get( $request ); | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  | 		$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $context ); | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 	 * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 	public function injectSettings() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 		$this->object->injectSettings( array( 'test' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 		$this->assertEquals( array( 'test' ), \PHPUnit_Framework_Assert::readAttribute( $this->object, 'settings' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 	 * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	public function setCache() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 		$cache = $this->getMockBuilder( '\Neos\Cache\Frontend\StringFrontend' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 		$this->object->setCache( $cache ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 		$this->assertEquals( $cache, \PHPUnit_Framework_Assert::readAttribute( $this->object, 'cache' ) ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 202 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 203 |  |  | } |