@@ -18,10 +18,10 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - public static function getContext( $site = 'unittest' ) |
|
| 21 | + public static function getContext($site = 'unittest') |
|
| 22 | 22 | { |
| 23 | - if( !isset( self::$context[$site] ) ) { |
|
| 24 | - self::$context[$site] = self::createContext( $site ); |
|
| 23 | + if (!isset(self::$context[$site])) { |
|
| 24 | + self::$context[$site] = self::createContext($site); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | return clone self::$context[$site]; |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public static function getAimeos() |
| 32 | 32 | { |
| 33 | - if( !isset( self::$aimeos ) ) |
|
| 33 | + if (!isset(self::$aimeos)) |
|
| 34 | 34 | { |
| 35 | 35 | require_once 'Bootstrap.php'; |
| 36 | - spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
|
| 36 | + spl_autoload_register('Aimeos\\Bootstrap::autoload'); |
|
| 37 | 37 | |
| 38 | - $extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
|
| 39 | - self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false ); |
|
| 38 | + $extdir = dirname(dirname(dirname(dirname(__FILE__)))); |
|
| 39 | + self::$aimeos = new \Aimeos\Bootstrap(array($extdir), false); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | return self::$aimeos; |
@@ -45,88 +45,88 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public static function getJsonadmPaths() |
| 47 | 47 | { |
| 48 | - return self::getAimeos()->getCustomPaths( 'admin/jsonadm/templates' ); |
|
| 48 | + return self::getAimeos()->getCustomPaths('admin/jsonadm/templates'); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - private static function createContext( $site ) |
|
| 52 | + private static function createContext($site) |
|
| 53 | 53 | { |
| 54 | 54 | $ctx = new \Aimeos\MShop\Context\Item\Standard(); |
| 55 | 55 | $aimeos = self::getAimeos(); |
| 56 | 56 | |
| 57 | 57 | |
| 58 | - $paths = $aimeos->getConfigPaths( 'mysql' ); |
|
| 58 | + $paths = $aimeos->getConfigPaths('mysql'); |
|
| 59 | 59 | $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
| 60 | 60 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
| 61 | 61 | |
| 62 | - $conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
|
| 63 | - $conf = new \Aimeos\MW\Config\Decorator\Memory( $conf ); |
|
| 64 | - $conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file ); |
|
| 65 | - $ctx->setConfig( $conf ); |
|
| 62 | + $conf = new \Aimeos\MW\Config\PHPArray([], $paths); |
|
| 63 | + $conf = new \Aimeos\MW\Config\Decorator\Memory($conf); |
|
| 64 | + $conf = new \Aimeos\MW\Config\Decorator\Documentor($conf, $file); |
|
| 65 | + $ctx->setConfig($conf); |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - $dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
|
| 69 | - $ctx->setDatabaseManager( $dbm ); |
|
| 68 | + $dbm = new \Aimeos\MW\DB\Manager\PDO($conf); |
|
| 69 | + $ctx->setDatabaseManager($dbm); |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - $logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG ); |
|
| 73 | - $ctx->setLogger( $logger ); |
|
| 72 | + $logger = new \Aimeos\MW\Logger\File($site . '.log', \Aimeos\MW\Logger\Base::DEBUG); |
|
| 73 | + $ctx->setLogger($logger); |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | 76 | $session = new \Aimeos\MW\Session\None(); |
| 77 | - $ctx->setSession( $session ); |
|
| 77 | + $ctx->setSession($session); |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | - $i18n = new \Aimeos\MW\Translation\None( 'de' ); |
|
| 81 | - $ctx->setI18n( array( 'de' => $i18n ) ); |
|
| 80 | + $i18n = new \Aimeos\MW\Translation\None('de'); |
|
| 81 | + $ctx->setI18n(array('de' => $i18n)); |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - $localeManager = \Aimeos\MShop::create( $ctx, 'locale' ); |
|
| 85 | - $locale = $localeManager->bootstrap( $site, 'de', '', false ); |
|
| 86 | - $ctx->setLocale( $locale ); |
|
| 84 | + $localeManager = \Aimeos\MShop::create($ctx, 'locale'); |
|
| 85 | + $locale = $localeManager->bootstrap($site, 'de', '', false); |
|
| 86 | + $ctx->setLocale($locale); |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - $view = self::createView( $conf ); |
|
| 90 | - $ctx->setView( $view ); |
|
| 89 | + $view = self::createView($conf); |
|
| 90 | + $ctx->setView($view); |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - $ctx->setEditor( 'core:admin/jsonadm' ); |
|
| 93 | + $ctx->setEditor('core:admin/jsonadm'); |
|
| 94 | 94 | |
| 95 | 95 | return $ctx; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - protected static function createView( \Aimeos\MW\Config\Iface $config ) |
|
| 99 | + protected static function createView(\Aimeos\MW\Config\Iface $config) |
|
| 100 | 100 | { |
| 101 | - $tmplpaths = self::getAimeos()->getCustomPaths( 'admin/jsonadm/templates' ); |
|
| 101 | + $tmplpaths = self::getAimeos()->getCustomPaths('admin/jsonadm/templates'); |
|
| 102 | 102 | |
| 103 | - $view = new \Aimeos\MW\View\Standard( $tmplpaths ); |
|
| 103 | + $view = new \Aimeos\MW\View\Standard($tmplpaths); |
|
| 104 | 104 | |
| 105 | - $helper = new \Aimeos\MW\View\Helper\Access\All( $view ); |
|
| 106 | - $view->addHelper( 'access', $helper ); |
|
| 105 | + $helper = new \Aimeos\MW\View\Helper\Access\All($view); |
|
| 106 | + $view->addHelper('access', $helper); |
|
| 107 | 107 | |
| 108 | - $trans = new \Aimeos\MW\Translation\None( 'de_DE' ); |
|
| 109 | - $helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans ); |
|
| 110 | - $view->addHelper( 'translate', $helper ); |
|
| 108 | + $trans = new \Aimeos\MW\Translation\None('de_DE'); |
|
| 109 | + $helper = new \Aimeos\MW\View\Helper\Translate\Standard($view, $trans); |
|
| 110 | + $view->addHelper('translate', $helper); |
|
| 111 | 111 | |
| 112 | - $helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' ); |
|
| 113 | - $view->addHelper( 'url', $helper ); |
|
| 112 | + $helper = new \Aimeos\MW\View\Helper\Url\Standard($view, 'http://baseurl'); |
|
| 113 | + $view->addHelper('url', $helper); |
|
| 114 | 114 | |
| 115 | - $helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' ); |
|
| 116 | - $view->addHelper( 'number', $helper ); |
|
| 115 | + $helper = new \Aimeos\MW\View\Helper\Number\Standard($view, '.', ''); |
|
| 116 | + $view->addHelper('number', $helper); |
|
| 117 | 117 | |
| 118 | - $helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' ); |
|
| 119 | - $view->addHelper( 'date', $helper ); |
|
| 118 | + $helper = new \Aimeos\MW\View\Helper\Date\Standard($view, 'Y-m-d'); |
|
| 119 | + $view->addHelper('date', $helper); |
|
| 120 | 120 | |
| 121 | - $config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'admin/jsonadm' ) ); |
|
| 122 | - $helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config ); |
|
| 123 | - $view->addHelper( 'config', $helper ); |
|
| 121 | + $config = new \Aimeos\MW\Config\Decorator\Protect($config, array('admin/jsonadm')); |
|
| 122 | + $helper = new \Aimeos\MW\View\Helper\Config\Standard($view, $config); |
|
| 123 | + $view->addHelper('config', $helper); |
|
| 124 | 124 | |
| 125 | - $helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, new \Zend\Diactoros\ServerRequest() ); |
|
| 126 | - $view->addHelper( 'request', $helper ); |
|
| 125 | + $helper = new \Aimeos\MW\View\Helper\Request\Standard($view, new \Zend\Diactoros\ServerRequest()); |
|
| 126 | + $view->addHelper('request', $helper); |
|
| 127 | 127 | |
| 128 | - $helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, new \Zend\Diactoros\Response() ); |
|
| 129 | - $view->addHelper( 'response', $helper ); |
|
| 128 | + $helper = new \Aimeos\MW\View\Helper\Response\Standard($view, new \Zend\Diactoros\Response()); |
|
| 129 | + $view->addHelper('response', $helper); |
|
| 130 | 130 | |
| 131 | 131 | return $view; |
| 132 | 132 | } |
@@ -18,20 +18,20 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | protected function setUp() |
| 20 | 20 | { |
| 21 | - \Aimeos\MShop::cache( true ); |
|
| 21 | + \Aimeos\MShop::cache(true); |
|
| 22 | 22 | |
| 23 | 23 | $this->context = \TestHelperJadm::getContext(); |
| 24 | 24 | $this->view = $this->context->getView(); |
| 25 | 25 | |
| 26 | - $this->object = new \Aimeos\Admin\JsonAdm\Catalog\Standard( $this->context, 'catalog' ); |
|
| 27 | - $this->object->setAimeos( \TestHelperJadm::getAimeos() ); |
|
| 28 | - $this->object->setView( $this->view ); |
|
| 26 | + $this->object = new \Aimeos\Admin\JsonAdm\Catalog\Standard($this->context, 'catalog'); |
|
| 27 | + $this->object->setAimeos(\TestHelperJadm::getAimeos()); |
|
| 28 | + $this->object->setView($this->view); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | protected function tearDown() |
| 33 | 33 | { |
| 34 | - \Aimeos\MShop::cache( false ); |
|
| 34 | + \Aimeos\MShop::cache(false); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
@@ -39,142 +39,142 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $params = array( |
| 41 | 41 | 'filter' => array( |
| 42 | - '==' => array( 'catalog.code' => 'cafe' ) |
|
| 42 | + '==' => array('catalog.code' => 'cafe') |
|
| 43 | 43 | ), |
| 44 | 44 | 'include' => 'text' |
| 45 | 45 | ); |
| 46 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 47 | - $this->view->addHelper( 'param', $helper ); |
|
| 46 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 47 | + $this->view->addHelper('param', $helper); |
|
| 48 | 48 | |
| 49 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 50 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 49 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 50 | + $result = json_decode((string) $response->getBody(), true); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 54 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 53 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 54 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 55 | 55 | |
| 56 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 57 | - $this->assertEquals( 1, count( $result['data'] ) ); |
|
| 58 | - $this->assertEquals( 'catalog', $result['data'][0]['type'] ); |
|
| 59 | - $this->assertEquals( 6, count( $result['data'][0]['relationships']['text'] ) ); |
|
| 60 | - $this->assertEquals( 6, count( $result['included'] ) ); |
|
| 56 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 57 | + $this->assertEquals(1, count($result['data'])); |
|
| 58 | + $this->assertEquals('catalog', $result['data'][0]['type']); |
|
| 59 | + $this->assertEquals(6, count($result['data'][0]['relationships']['text'])); |
|
| 60 | + $this->assertEquals(6, count($result['included'])); |
|
| 61 | 61 | |
| 62 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 62 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | public function testGetTree() |
| 67 | 67 | { |
| 68 | 68 | $params = array( |
| 69 | - 'id' => $this->getCatalogItem( 'root' )->getId(), |
|
| 69 | + 'id' => $this->getCatalogItem('root')->getId(), |
|
| 70 | 70 | 'include' => 'catalog,text' |
| 71 | 71 | ); |
| 72 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 73 | - $this->view->addHelper( 'param', $helper ); |
|
| 72 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 73 | + $this->view->addHelper('param', $helper); |
|
| 74 | 74 | |
| 75 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 76 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 75 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 76 | + $result = json_decode((string) $response->getBody(), true); |
|
| 77 | 77 | |
| 78 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 79 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 78 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 79 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 80 | 80 | |
| 81 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 82 | - $this->assertEquals( 'catalog', $result['data']['type'] ); |
|
| 83 | - $this->assertEquals( 2, count( $result['data']['relationships']['catalog'] ) ); |
|
| 84 | - $this->assertEquals( 2, count( $result['included'] ) ); |
|
| 81 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 82 | + $this->assertEquals('catalog', $result['data']['type']); |
|
| 83 | + $this->assertEquals(2, count($result['data']['relationships']['catalog'])); |
|
| 84 | + $this->assertEquals(2, count($result['included'])); |
|
| 85 | 85 | |
| 86 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 86 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | public function testPatch() |
| 91 | 91 | { |
| 92 | - $stub = $this->getCatalogMock( array( 'getItem', 'moveItem', 'saveItem' ) ); |
|
| 92 | + $stub = $this->getCatalogMock(array('getItem', 'moveItem', 'saveItem')); |
|
| 93 | 93 | |
| 94 | - $stub->expects( $this->once() )->method( 'moveItem' ); |
|
| 95 | - $stub->expects( $this->once() )->method( 'saveItem' ) |
|
| 96 | - ->will( $this->returnValue( $stub->createItem() ) ); |
|
| 97 | - $stub->expects( $this->exactly( 2 ) )->method( 'getItem' ) // 2x due to decorator |
|
| 98 | - ->will( $this->returnValue( $stub->createItem() ) ); |
|
| 94 | + $stub->expects($this->once())->method('moveItem'); |
|
| 95 | + $stub->expects($this->once())->method('saveItem') |
|
| 96 | + ->will($this->returnValue($stub->createItem())); |
|
| 97 | + $stub->expects($this->exactly(2))->method('getItem') // 2x due to decorator |
|
| 98 | + ->will($this->returnValue($stub->createItem())); |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - $params = array( 'id' => '-1' ); |
|
| 102 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 103 | - $this->view->addHelper( 'param', $helper ); |
|
| 101 | + $params = array('id' => '-1'); |
|
| 102 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 103 | + $this->view->addHelper('param', $helper); |
|
| 104 | 104 | |
| 105 | 105 | $body = '{"data": {"parentid": "1", "targetid": 2, "type": "catalog", "attributes": {"catalog.label": "test"}}}'; |
| 106 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 106 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 107 | 107 | |
| 108 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 109 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 108 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 109 | + $result = json_decode((string) $response->getBody(), true); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 113 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 112 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 113 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 114 | 114 | |
| 115 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 116 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 117 | - $this->assertEquals( 'catalog', $result['data']['type'] ); |
|
| 115 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 116 | + $this->assertArrayHasKey('data', $result); |
|
| 117 | + $this->assertEquals('catalog', $result['data']['type']); |
|
| 118 | 118 | |
| 119 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 120 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 119 | + $this->assertArrayNotHasKey('included', $result); |
|
| 120 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | public function testPost() |
| 125 | 125 | { |
| 126 | - $stub = $this->getCatalogMock( array( 'getItem', 'insertItem' ) ); |
|
| 126 | + $stub = $this->getCatalogMock(array('getItem', 'insertItem')); |
|
| 127 | 127 | |
| 128 | - $stub->expects( $this->any() )->method( 'getItem' ) |
|
| 129 | - ->will( $this->returnValue( $stub->createItem() ) ); |
|
| 130 | - $stub->expects( $this->once() )->method( 'insertItem' ); |
|
| 128 | + $stub->expects($this->any())->method('getItem') |
|
| 129 | + ->will($this->returnValue($stub->createItem())); |
|
| 130 | + $stub->expects($this->once())->method('insertItem'); |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | $body = '{"data": {"type": "catalog", "attributes": {"catalog.code": "test", "catalog.label": "Test catalog"}}}'; |
| 134 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 134 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 135 | 135 | |
| 136 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 137 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 136 | + $response = $this->object->post($request, $this->view->response()); |
|
| 137 | + $result = json_decode((string) $response->getBody(), true); |
|
| 138 | 138 | |
| 139 | 139 | |
| 140 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
| 141 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 140 | + $this->assertEquals(201, $response->getStatusCode()); |
|
| 141 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 142 | 142 | |
| 143 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 144 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 145 | - $this->assertEquals( 'catalog', $result['data']['type'] ); |
|
| 143 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 144 | + $this->assertArrayHasKey('data', $result); |
|
| 145 | + $this->assertEquals('catalog', $result['data']['type']); |
|
| 146 | 146 | |
| 147 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 148 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 147 | + $this->assertArrayNotHasKey('included', $result); |
|
| 148 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
| 152 | - protected function getCatalogItem( $code ) |
|
| 152 | + protected function getCatalogItem($code) |
|
| 153 | 153 | { |
| 154 | - $manager = \Aimeos\MShop::create( $this->context, 'catalog' ); |
|
| 154 | + $manager = \Aimeos\MShop::create($this->context, 'catalog'); |
|
| 155 | 155 | $search = $manager->createSearch(); |
| 156 | - $search->setConditions( $search->compare( '==', 'catalog.code', $code ) ); |
|
| 157 | - $items = $manager->searchItems( $search ); |
|
| 156 | + $search->setConditions($search->compare('==', 'catalog.code', $code)); |
|
| 157 | + $items = $manager->searchItems($search); |
|
| 158 | 158 | |
| 159 | - if( ( $item = reset( $items ) ) === false ) { |
|
| 160 | - throw new \RuntimeException( sprintf( 'No catalog item with code "%1$s" found', $code ) ); |
|
| 159 | + if (($item = reset($items)) === false) { |
|
| 160 | + throw new \RuntimeException(sprintf('No catalog item with code "%1$s" found', $code)); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | return $item; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
| 167 | - protected function getCatalogMock( array $methods ) |
|
| 167 | + protected function getCatalogMock(array $methods) |
|
| 168 | 168 | { |
| 169 | 169 | $name = 'ClientJsonAdmStandard'; |
| 170 | - $this->context->getConfig()->set( 'mshop/catalog/manager/name', $name ); |
|
| 170 | + $this->context->getConfig()->set('mshop/catalog/manager/name', $name); |
|
| 171 | 171 | |
| 172 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Catalog\\Manager\\Standard' ) |
|
| 173 | - ->setConstructorArgs( array( $this->context ) ) |
|
| 174 | - ->setMethods( $methods ) |
|
| 172 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Catalog\\Manager\\Standard') |
|
| 173 | + ->setConstructorArgs(array($this->context)) |
|
| 174 | + ->setMethods($methods) |
|
| 175 | 175 | ->getMock(); |
| 176 | 176 | |
| 177 | - \Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Catalog\\Manager\\' . $name, $stub ); |
|
| 177 | + \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Catalog\\Manager\\' . $name, $stub); |
|
| 178 | 178 | |
| 179 | 179 | return $stub; |
| 180 | 180 | } |
@@ -18,212 +18,212 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | protected function setUp() |
| 20 | 20 | { |
| 21 | - \Aimeos\MShop::cache( true ); |
|
| 21 | + \Aimeos\MShop::cache(true); |
|
| 22 | 22 | |
| 23 | 23 | $this->context = \TestHelperJadm::getContext(); |
| 24 | 24 | $this->view = $this->context->getView(); |
| 25 | 25 | |
| 26 | - $this->object = new \Aimeos\Admin\JsonAdm\Standard( $this->context, 'product' ); |
|
| 27 | - $this->object->setAimeos( \TestHelperJadm::getAimeos() ); |
|
| 28 | - $this->object->setView( $this->view ); |
|
| 26 | + $this->object = new \Aimeos\Admin\JsonAdm\Standard($this->context, 'product'); |
|
| 27 | + $this->object->setAimeos(\TestHelperJadm::getAimeos()); |
|
| 28 | + $this->object->setView($this->view); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | protected function tearDown() |
| 33 | 33 | { |
| 34 | - \Aimeos\MShop::cache( false ); |
|
| 34 | + \Aimeos\MShop::cache(false); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | public function testDelete() |
| 39 | 39 | { |
| 40 | - $this->getProductMock( array( 'deleteItem' ) )->expects( $this->once() )->method( 'deleteItem' ); |
|
| 40 | + $this->getProductMock(array('deleteItem'))->expects($this->once())->method('deleteItem'); |
|
| 41 | 41 | |
| 42 | - $params = array( 'id' => $this->getProductItem()->getId() ); |
|
| 43 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 44 | - $this->view->addHelper( 'param', $helper ); |
|
| 42 | + $params = array('id' => $this->getProductItem()->getId()); |
|
| 43 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 44 | + $this->view->addHelper('param', $helper); |
|
| 45 | 45 | |
| 46 | - $response = $this->object->delete( $this->view->request(), $this->view->response() ); |
|
| 47 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 46 | + $response = $this->object->delete($this->view->request(), $this->view->response()); |
|
| 47 | + $result = json_decode((string) $response->getBody(), true); |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 51 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 50 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 51 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 52 | 52 | |
| 53 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 53 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 54 | 54 | |
| 55 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 56 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
| 57 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 55 | + $this->assertArrayNotHasKey('included', $result); |
|
| 56 | + $this->assertArrayNotHasKey('data', $result); |
|
| 57 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | public function testDeleteBulk() |
| 62 | 62 | { |
| 63 | - $this->getProductMock( array( 'deleteItems' ) )->expects( $this->once() )->method( 'deleteItems' ); |
|
| 63 | + $this->getProductMock(array('deleteItems'))->expects($this->once())->method('deleteItems'); |
|
| 64 | 64 | |
| 65 | 65 | $body = '{"data":[{"type": "product", "id": "-1"},{"type": "product", "id": "-2"}]}'; |
| 66 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 66 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 67 | 67 | |
| 68 | - $response = $this->object->delete( $request, $this->view->response() ); |
|
| 69 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 68 | + $response = $this->object->delete($request, $this->view->response()); |
|
| 69 | + $result = json_decode((string) $response->getBody(), true); |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 73 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 72 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 73 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 74 | 74 | |
| 75 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
| 76 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 77 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
| 78 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 75 | + $this->assertEquals(2, $result['meta']['total']); |
|
| 76 | + $this->assertArrayNotHasKey('included', $result); |
|
| 77 | + $this->assertArrayNotHasKey('data', $result); |
|
| 78 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | public function testDeleteInvalid() |
| 83 | 83 | { |
| 84 | 84 | $body = '{"data":null}'; |
| 85 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 85 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 86 | 86 | |
| 87 | - $response = $this->object->delete( $request, $this->view->response() ); |
|
| 88 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 87 | + $response = $this->object->delete($request, $this->view->response()); |
|
| 88 | + $result = json_decode((string) $response->getBody(), true); |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
| 92 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 91 | + $this->assertEquals(400, $response->getStatusCode()); |
|
| 92 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 93 | 93 | |
| 94 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
| 95 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 96 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 97 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
| 94 | + $this->assertEquals(0, $result['meta']['total']); |
|
| 95 | + $this->assertArrayHasKey('errors', $result); |
|
| 96 | + $this->assertArrayNotHasKey('included', $result); |
|
| 97 | + $this->assertArrayNotHasKey('data', $result); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | public function testDeleteException() |
| 102 | 102 | { |
| 103 | - $this->getProductMock( array( 'deleteItem' ) )->expects( $this->once() )->method( 'deleteItem' ) |
|
| 104 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
| 103 | + $this->getProductMock(array('deleteItem'))->expects($this->once())->method('deleteItem') |
|
| 104 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
| 105 | 105 | |
| 106 | - $params = array( 'id' => $this->getProductItem()->getId() ); |
|
| 107 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 108 | - $this->view->addHelper( 'param', $helper ); |
|
| 106 | + $params = array('id' => $this->getProductItem()->getId()); |
|
| 107 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 108 | + $this->view->addHelper('param', $helper); |
|
| 109 | 109 | |
| 110 | - $response = $this->object->delete( $this->view->request(), $this->view->response() ); |
|
| 111 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 110 | + $response = $this->object->delete($this->view->request(), $this->view->response()); |
|
| 111 | + $result = json_decode((string) $response->getBody(), true); |
|
| 112 | 112 | |
| 113 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
| 114 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 113 | + $this->assertEquals(500, $response->getStatusCode()); |
|
| 114 | + $this->assertArrayHasKey('errors', $result); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | public function testDeleteMShopException() |
| 119 | 119 | { |
| 120 | - $this->getProductMock( array( 'deleteItem' ) )->expects( $this->once() )->method( 'deleteItem' ) |
|
| 121 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
| 120 | + $this->getProductMock(array('deleteItem'))->expects($this->once())->method('deleteItem') |
|
| 121 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
| 122 | 122 | |
| 123 | - $params = array( 'id' => $this->getProductItem()->getId() ); |
|
| 124 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 125 | - $this->view->addHelper( 'param', $helper ); |
|
| 123 | + $params = array('id' => $this->getProductItem()->getId()); |
|
| 124 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 125 | + $this->view->addHelper('param', $helper); |
|
| 126 | 126 | |
| 127 | - $response = $this->object->delete( $this->view->request(), $this->view->response() ); |
|
| 128 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 127 | + $response = $this->object->delete($this->view->request(), $this->view->response()); |
|
| 128 | + $result = json_decode((string) $response->getBody(), true); |
|
| 129 | 129 | |
| 130 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
| 131 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 130 | + $this->assertEquals(404, $response->getStatusCode()); |
|
| 131 | + $this->assertArrayHasKey('errors', $result); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
| 135 | 135 | public function testGet() |
| 136 | 136 | { |
| 137 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 138 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 137 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 138 | + $result = json_decode((string) $response->getBody(), true); |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 142 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 141 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 142 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 143 | 143 | |
| 144 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
| 145 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
| 146 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 147 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
| 148 | - $this->assertArrayHasKey( 'next', $result['links'] ); |
|
| 149 | - $this->assertArrayHasKey( 'last', $result['links'] ); |
|
| 150 | - $this->assertArrayHasKey( 'self', $result['links'] ); |
|
| 151 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 144 | + $this->assertEquals(28, $result['meta']['total']); |
|
| 145 | + $this->assertEquals(25, count($result['data'])); |
|
| 146 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 147 | + $this->assertEquals(0, count($result['included'])); |
|
| 148 | + $this->assertArrayHasKey('next', $result['links']); |
|
| 149 | + $this->assertArrayHasKey('last', $result['links']); |
|
| 150 | + $this->assertArrayHasKey('self', $result['links']); |
|
| 151 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
| 155 | 155 | public function testGetType() |
| 156 | 156 | { |
| 157 | - $object = new \Aimeos\Admin\JsonAdm\Standard( $this->context, 'product/property/type' ); |
|
| 158 | - $object->setView( $this->view ); |
|
| 157 | + $object = new \Aimeos\Admin\JsonAdm\Standard($this->context, 'product/property/type'); |
|
| 158 | + $object->setView($this->view); |
|
| 159 | 159 | |
| 160 | - $response = $object->get( $this->view->request(), $this->view->response() ); |
|
| 161 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 160 | + $response = $object->get($this->view->request(), $this->view->response()); |
|
| 161 | + $result = json_decode((string) $response->getBody(), true); |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 165 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 164 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 165 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 166 | 166 | |
| 167 | - $this->assertEquals( 4, $result['meta']['total'] ); |
|
| 168 | - $this->assertEquals( 4, count( $result['data'] ) ); |
|
| 169 | - $this->assertEquals( 'product/property/type', $result['data'][0]['type'] ); |
|
| 170 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
| 167 | + $this->assertEquals(4, $result['meta']['total']); |
|
| 168 | + $this->assertEquals(4, count($result['data'])); |
|
| 169 | + $this->assertEquals('product/property/type', $result['data'][0]['type']); |
|
| 170 | + $this->assertEquals(0, count($result['included'])); |
|
| 171 | 171 | |
| 172 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 172 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | public function testGetInvalid() |
| 177 | 177 | { |
| 178 | - $object = new \Aimeos\Admin\JsonAdm\Standard( $this->context, 'invalid' ); |
|
| 179 | - $object->setView( $this->view ); |
|
| 178 | + $object = new \Aimeos\Admin\JsonAdm\Standard($this->context, 'invalid'); |
|
| 179 | + $object->setView($this->view); |
|
| 180 | 180 | |
| 181 | - $response = $object->get( $this->view->request(), $this->view->response() ); |
|
| 182 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 181 | + $response = $object->get($this->view->request(), $this->view->response()); |
|
| 182 | + $result = json_decode((string) $response->getBody(), true); |
|
| 183 | 183 | |
| 184 | 184 | |
| 185 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
| 186 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 185 | + $this->assertEquals(404, $response->getStatusCode()); |
|
| 186 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 187 | 187 | |
| 188 | - $this->assertEquals( 1, count( $result['errors'] ) ); |
|
| 189 | - $this->assertArrayHasKey( 'title', $result['errors'][0] ); |
|
| 190 | - $this->assertArrayHasKey( 'detail', $result['errors'][0] ); |
|
| 191 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
| 192 | - $this->assertArrayNotHasKey( 'indluded', $result ); |
|
| 188 | + $this->assertEquals(1, count($result['errors'])); |
|
| 189 | + $this->assertArrayHasKey('title', $result['errors'][0]); |
|
| 190 | + $this->assertArrayHasKey('detail', $result['errors'][0]); |
|
| 191 | + $this->assertArrayNotHasKey('data', $result); |
|
| 192 | + $this->assertArrayNotHasKey('indluded', $result); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | public function testGetException() |
| 197 | 197 | { |
| 198 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
| 199 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
| 198 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
| 199 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
| 200 | 200 | |
| 201 | - $params = array( 'id' => -1 ); |
|
| 202 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 203 | - $this->view->addHelper( 'param', $helper ); |
|
| 201 | + $params = array('id' => -1); |
|
| 202 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 203 | + $this->view->addHelper('param', $helper); |
|
| 204 | 204 | |
| 205 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 206 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 205 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 206 | + $result = json_decode((string) $response->getBody(), true); |
|
| 207 | 207 | |
| 208 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
| 209 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 208 | + $this->assertEquals(500, $response->getStatusCode()); |
|
| 209 | + $this->assertArrayHasKey('errors', $result); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | |
| 213 | 213 | public function testGetMShopException() |
| 214 | 214 | { |
| 215 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
| 216 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
| 215 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
| 216 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
| 217 | 217 | |
| 218 | - $params = array( 'id' => -1 ); |
|
| 219 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 220 | - $this->view->addHelper( 'param', $helper ); |
|
| 218 | + $params = array('id' => -1); |
|
| 219 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 220 | + $this->view->addHelper('param', $helper); |
|
| 221 | 221 | |
| 222 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 223 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 222 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 223 | + $result = json_decode((string) $response->getBody(), true); |
|
| 224 | 224 | |
| 225 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
| 226 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 225 | + $this->assertEquals(404, $response->getStatusCode()); |
|
| 226 | + $this->assertArrayHasKey('errors', $result); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | |
@@ -231,25 +231,25 @@ discard block |
||
| 231 | 231 | { |
| 232 | 232 | $params = array( |
| 233 | 233 | 'filter' => array( |
| 234 | - '==' => array( 'product.type' => 'select' ) |
|
| 234 | + '==' => array('product.type' => 'select') |
|
| 235 | 235 | ) |
| 236 | 236 | ); |
| 237 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 238 | - $this->view->addHelper( 'param', $helper ); |
|
| 237 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 238 | + $this->view->addHelper('param', $helper); |
|
| 239 | 239 | |
| 240 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 241 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 240 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 241 | + $result = json_decode((string) $response->getBody(), true); |
|
| 242 | 242 | |
| 243 | 243 | |
| 244 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 245 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 244 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 245 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 246 | 246 | |
| 247 | - $this->assertEquals( 3, $result['meta']['total'] ); |
|
| 248 | - $this->assertEquals( 3, count( $result['data'] ) ); |
|
| 249 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 250 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
| 247 | + $this->assertEquals(3, $result['meta']['total']); |
|
| 248 | + $this->assertEquals(3, count($result['data'])); |
|
| 249 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 250 | + $this->assertEquals(0, count($result['included'])); |
|
| 251 | 251 | |
| 252 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 252 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -258,27 +258,27 @@ discard block |
||
| 258 | 258 | $params = array( |
| 259 | 259 | 'filter' => array( |
| 260 | 260 | '&&' => array( |
| 261 | - array( '=~' => array( 'product.label' => 'Unittest: Test' ) ), |
|
| 262 | - array( '==' => array( 'product.type' => 'select' ) ), |
|
| 261 | + array('=~' => array('product.label' => 'Unittest: Test')), |
|
| 262 | + array('==' => array('product.type' => 'select')), |
|
| 263 | 263 | ) |
| 264 | 264 | ) |
| 265 | 265 | ); |
| 266 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 267 | - $this->view->addHelper( 'param', $helper ); |
|
| 266 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 267 | + $this->view->addHelper('param', $helper); |
|
| 268 | 268 | |
| 269 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 270 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 269 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 270 | + $result = json_decode((string) $response->getBody(), true); |
|
| 271 | 271 | |
| 272 | 272 | |
| 273 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 274 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 273 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 274 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 275 | 275 | |
| 276 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
| 277 | - $this->assertEquals( 2, count( $result['data'] ) ); |
|
| 278 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 279 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
| 276 | + $this->assertEquals(2, $result['meta']['total']); |
|
| 277 | + $this->assertEquals(2, count($result['data'])); |
|
| 278 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 279 | + $this->assertEquals(0, count($result['included'])); |
|
| 280 | 280 | |
| 281 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 281 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
@@ -290,25 +290,25 @@ discard block |
||
| 290 | 290 | 'limit' => 25 |
| 291 | 291 | ) |
| 292 | 292 | ); |
| 293 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 294 | - $this->view->addHelper( 'param', $helper ); |
|
| 293 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 294 | + $this->view->addHelper('param', $helper); |
|
| 295 | 295 | |
| 296 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 297 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 296 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 297 | + $result = json_decode((string) $response->getBody(), true); |
|
| 298 | 298 | |
| 299 | 299 | |
| 300 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 301 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 300 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 301 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 302 | 302 | |
| 303 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
| 304 | - $this->assertEquals( 3, count( $result['data'] ) ); |
|
| 305 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 306 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
| 307 | - $this->assertArrayHasKey( 'first', $result['links'] ); |
|
| 308 | - $this->assertArrayHasKey( 'prev', $result['links'] ); |
|
| 309 | - $this->assertArrayHasKey( 'self', $result['links'] ); |
|
| 303 | + $this->assertEquals(28, $result['meta']['total']); |
|
| 304 | + $this->assertEquals(3, count($result['data'])); |
|
| 305 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 306 | + $this->assertEquals(0, count($result['included'])); |
|
| 307 | + $this->assertArrayHasKey('first', $result['links']); |
|
| 308 | + $this->assertArrayHasKey('prev', $result['links']); |
|
| 309 | + $this->assertArrayHasKey('self', $result['links']); |
|
| 310 | 310 | |
| 311 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 311 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -317,24 +317,24 @@ discard block |
||
| 317 | 317 | $params = array( |
| 318 | 318 | 'sort' => 'product.label,-product.code' |
| 319 | 319 | ); |
| 320 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 321 | - $this->view->addHelper( 'param', $helper ); |
|
| 320 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 321 | + $this->view->addHelper('param', $helper); |
|
| 322 | 322 | |
| 323 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 324 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 323 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 324 | + $result = json_decode((string) $response->getBody(), true); |
|
| 325 | 325 | |
| 326 | 326 | |
| 327 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 328 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 327 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 328 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 329 | 329 | |
| 330 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
| 331 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
| 332 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 333 | - $this->assertEquals( 'QRST', $result['data'][0]['attributes']['product.code'] ); |
|
| 334 | - $this->assertEquals( '16 discs', $result['data'][0]['attributes']['product.label'] ); |
|
| 335 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
| 330 | + $this->assertEquals(28, $result['meta']['total']); |
|
| 331 | + $this->assertEquals(25, count($result['data'])); |
|
| 332 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 333 | + $this->assertEquals('QRST', $result['data'][0]['attributes']['product.code']); |
|
| 334 | + $this->assertEquals('16 discs', $result['data'][0]['attributes']['product.label']); |
|
| 335 | + $this->assertEquals(0, count($result['included'])); |
|
| 336 | 336 | |
| 337 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 337 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
@@ -347,262 +347,262 @@ discard block |
||
| 347 | 347 | 'sort' => 'product.id', |
| 348 | 348 | 'include' => 'product' |
| 349 | 349 | ); |
| 350 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 351 | - $this->view->addHelper( 'param', $helper ); |
|
| 350 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 351 | + $this->view->addHelper('param', $helper); |
|
| 352 | 352 | |
| 353 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 354 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 353 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 354 | + $result = json_decode((string) $response->getBody(), true); |
|
| 355 | 355 | |
| 356 | 356 | |
| 357 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 358 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 357 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 358 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 359 | 359 | |
| 360 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
| 361 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
| 362 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 363 | - $this->assertEquals( 2, count( $result['data'][0]['attributes'] ) ); |
|
| 360 | + $this->assertEquals(28, $result['meta']['total']); |
|
| 361 | + $this->assertEquals(25, count($result['data'])); |
|
| 362 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 363 | + $this->assertEquals(2, count($result['data'][0]['attributes'])); |
|
| 364 | 364 | |
| 365 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 365 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | |
| 369 | 369 | public function testPatch() |
| 370 | 370 | { |
| 371 | - $productManagerStub = $this->getProductMock( array( 'getItem', 'saveItem' ) ); |
|
| 371 | + $productManagerStub = $this->getProductMock(array('getItem', 'saveItem')); |
|
| 372 | 372 | |
| 373 | 373 | $item = $productManagerStub->createItem(); |
| 374 | - $item->setLabel( 'test' ); |
|
| 375 | - $item->setId( '-1' ); |
|
| 374 | + $item->setLabel('test'); |
|
| 375 | + $item->setId('-1'); |
|
| 376 | 376 | |
| 377 | - $productManagerStub->expects( $this->once() )->method( 'saveItem' ) |
|
| 378 | - ->will( $this->returnValue( $productManagerStub->createItem() ) ); |
|
| 379 | - $productManagerStub->expects( $this->atLeastOnce() )->method( 'getItem' ) |
|
| 380 | - ->will( $this->returnValue( $item ) ); |
|
| 377 | + $productManagerStub->expects($this->once())->method('saveItem') |
|
| 378 | + ->will($this->returnValue($productManagerStub->createItem())); |
|
| 379 | + $productManagerStub->expects($this->atLeastOnce())->method('getItem') |
|
| 380 | + ->will($this->returnValue($item)); |
|
| 381 | 381 | |
| 382 | 382 | |
| 383 | - $params = array( 'id' => '-1' ); |
|
| 384 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 385 | - $this->view->addHelper( 'param', $helper ); |
|
| 383 | + $params = array('id' => '-1'); |
|
| 384 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 385 | + $this->view->addHelper('param', $helper); |
|
| 386 | 386 | |
| 387 | 387 | $body = '{"data": {"type": "product", "attributes": {"product.label": "test"}}}'; |
| 388 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 388 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 389 | 389 | |
| 390 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 391 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 390 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 391 | + $result = json_decode((string) $response->getBody(), true); |
|
| 392 | 392 | |
| 393 | 393 | |
| 394 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 395 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 394 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 395 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 396 | 396 | |
| 397 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 398 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 399 | - $this->assertEquals( '-1', $result['data']['id'] ); |
|
| 400 | - $this->assertEquals( 'product', $result['data']['type'] ); |
|
| 401 | - $this->assertEquals( 'test', $result['data']['attributes']['product.label'] ); |
|
| 397 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 398 | + $this->assertArrayHasKey('data', $result); |
|
| 399 | + $this->assertEquals('-1', $result['data']['id']); |
|
| 400 | + $this->assertEquals('product', $result['data']['type']); |
|
| 401 | + $this->assertEquals('test', $result['data']['attributes']['product.label']); |
|
| 402 | 402 | |
| 403 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 404 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 403 | + $this->assertArrayNotHasKey('included', $result); |
|
| 404 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
| 408 | 408 | public function testPatchBulk() |
| 409 | 409 | { |
| 410 | - $productManagerStub = $this->getProductMock( array( 'getItem', 'saveItem' ) ); |
|
| 410 | + $productManagerStub = $this->getProductMock(array('getItem', 'saveItem')); |
|
| 411 | 411 | |
| 412 | 412 | $item = $productManagerStub->createItem(); |
| 413 | - $item->setLabel( 'test' ); |
|
| 414 | - $item->setId( '-1' ); |
|
| 413 | + $item->setLabel('test'); |
|
| 414 | + $item->setId('-1'); |
|
| 415 | 415 | |
| 416 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'saveItem' ) |
|
| 417 | - ->will( $this->returnValue( $productManagerStub->createItem() ) ); |
|
| 418 | - $productManagerStub->expects( $this->atLeastOnce() )->method( 'getItem' ) |
|
| 419 | - ->will( $this->returnValue( $item ) ); |
|
| 416 | + $productManagerStub->expects($this->exactly(2))->method('saveItem') |
|
| 417 | + ->will($this->returnValue($productManagerStub->createItem())); |
|
| 418 | + $productManagerStub->expects($this->atLeastOnce())->method('getItem') |
|
| 419 | + ->will($this->returnValue($item)); |
|
| 420 | 420 | |
| 421 | 421 | |
| 422 | 422 | $body = '{"data": [{"id": "-1", "type": "product", "attributes": {"product.label": "test"}}, {"id": "-1", "type": "product", "attributes": {"product.label": "test"}}]}'; |
| 423 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 423 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 424 | 424 | |
| 425 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 426 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 425 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 426 | + $result = json_decode((string) $response->getBody(), true); |
|
| 427 | 427 | |
| 428 | 428 | |
| 429 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 430 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 429 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 430 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 431 | 431 | |
| 432 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
| 433 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 434 | - $this->assertEquals( 2, count( $result['data'] ) ); |
|
| 435 | - $this->assertEquals( '-1', $result['data'][0]['id'] ); |
|
| 436 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 437 | - $this->assertEquals( 'test', $result['data'][0]['attributes']['product.label'] ); |
|
| 432 | + $this->assertEquals(2, $result['meta']['total']); |
|
| 433 | + $this->assertArrayHasKey('data', $result); |
|
| 434 | + $this->assertEquals(2, count($result['data'])); |
|
| 435 | + $this->assertEquals('-1', $result['data'][0]['id']); |
|
| 436 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 437 | + $this->assertEquals('test', $result['data'][0]['attributes']['product.label']); |
|
| 438 | 438 | |
| 439 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 440 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 439 | + $this->assertArrayNotHasKey('included', $result); |
|
| 440 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
| 444 | 444 | public function testPatchInvalid() |
| 445 | 445 | { |
| 446 | 446 | $body = '{"data":null}'; |
| 447 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 447 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 448 | 448 | |
| 449 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 450 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 449 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 450 | + $result = json_decode((string) $response->getBody(), true); |
|
| 451 | 451 | |
| 452 | 452 | |
| 453 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
| 454 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 453 | + $this->assertEquals(400, $response->getStatusCode()); |
|
| 454 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 455 | 455 | |
| 456 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
| 457 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 458 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 459 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
| 456 | + $this->assertEquals(0, $result['meta']['total']); |
|
| 457 | + $this->assertArrayHasKey('errors', $result); |
|
| 458 | + $this->assertArrayNotHasKey('included', $result); |
|
| 459 | + $this->assertArrayNotHasKey('data', $result); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
| 463 | 463 | public function testPatchInvalidId() |
| 464 | 464 | { |
| 465 | 465 | $body = '{"data":{"id":-1}}'; |
| 466 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 466 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 467 | 467 | |
| 468 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 469 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 468 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 469 | + $result = json_decode((string) $response->getBody(), true); |
|
| 470 | 470 | |
| 471 | 471 | |
| 472 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
| 473 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 472 | + $this->assertEquals(400, $response->getStatusCode()); |
|
| 473 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 474 | 474 | |
| 475 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
| 476 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 475 | + $this->assertEquals(0, $result['meta']['total']); |
|
| 476 | + $this->assertArrayHasKey('errors', $result); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | |
| 480 | 480 | public function testPatchException() |
| 481 | 481 | { |
| 482 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
| 483 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
| 482 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
| 483 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
| 484 | 484 | |
| 485 | 485 | $body = '{"data":[{"id":-1}]}'; |
| 486 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 486 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 487 | 487 | |
| 488 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 489 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 488 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 489 | + $result = json_decode((string) $response->getBody(), true); |
|
| 490 | 490 | |
| 491 | 491 | |
| 492 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
| 493 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 494 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 492 | + $this->assertEquals(500, $response->getStatusCode()); |
|
| 493 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 494 | + $this->assertArrayHasKey('errors', $result); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | |
| 498 | 498 | public function testPatchMShopException() |
| 499 | 499 | { |
| 500 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
| 501 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
| 500 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
| 501 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
| 502 | 502 | |
| 503 | 503 | $body = '{"data":[{"id":-1}]}'; |
| 504 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 504 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 505 | 505 | |
| 506 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 507 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 506 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 507 | + $result = json_decode((string) $response->getBody(), true); |
|
| 508 | 508 | |
| 509 | 509 | |
| 510 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
| 511 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 512 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 510 | + $this->assertEquals(404, $response->getStatusCode()); |
|
| 511 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 512 | + $this->assertArrayHasKey('errors', $result); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | |
| 516 | 516 | public function testPost() |
| 517 | 517 | { |
| 518 | - $productManagerStub = $this->getProductMock( array( 'createItem', 'getItem', 'saveItem' ) ); |
|
| 518 | + $productManagerStub = $this->getProductMock(array('createItem', 'getItem', 'saveItem')); |
|
| 519 | 519 | |
| 520 | 520 | $item = new \Aimeos\MShop\Product\Item\Standard(); |
| 521 | - $item->setId( '-1' ); |
|
| 521 | + $item->setId('-1'); |
|
| 522 | 522 | |
| 523 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'createItem' ) |
|
| 524 | - ->will( $this->returnValue( $item ) ); |
|
| 525 | - $productManagerStub->expects( $this->any() )->method( 'getItem' ) |
|
| 526 | - ->will( $this->returnValue( $item ) ); |
|
| 527 | - $productManagerStub->expects( $this->once() )->method( 'saveItem' ) |
|
| 528 | - ->will( $this->returnValue( $productManagerStub->createItem() ) ); |
|
| 523 | + $productManagerStub->expects($this->exactly(2))->method('createItem') |
|
| 524 | + ->will($this->returnValue($item)); |
|
| 525 | + $productManagerStub->expects($this->any())->method('getItem') |
|
| 526 | + ->will($this->returnValue($item)); |
|
| 527 | + $productManagerStub->expects($this->once())->method('saveItem') |
|
| 528 | + ->will($this->returnValue($productManagerStub->createItem())); |
|
| 529 | 529 | |
| 530 | 530 | |
| 531 | 531 | $body = '{"data": {"type": "product", "attributes": {"product.type": "default", "product.label": "test"}}}'; |
| 532 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 532 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 533 | 533 | |
| 534 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 535 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 534 | + $response = $this->object->post($request, $this->view->response()); |
|
| 535 | + $result = json_decode((string) $response->getBody(), true); |
|
| 536 | 536 | |
| 537 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
| 538 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 537 | + $this->assertEquals(201, $response->getStatusCode()); |
|
| 538 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 539 | 539 | |
| 540 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 541 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 542 | - $this->assertEquals( '-1', $result['data']['id'] ); |
|
| 543 | - $this->assertEquals( 'product', $result['data']['type'] ); |
|
| 544 | - $this->assertEquals( 'default', $result['data']['attributes']['product.type'] ); |
|
| 545 | - $this->assertEquals( 'test', $result['data']['attributes']['product.label'] ); |
|
| 540 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 541 | + $this->assertArrayHasKey('data', $result); |
|
| 542 | + $this->assertEquals('-1', $result['data']['id']); |
|
| 543 | + $this->assertEquals('product', $result['data']['type']); |
|
| 544 | + $this->assertEquals('default', $result['data']['attributes']['product.type']); |
|
| 545 | + $this->assertEquals('test', $result['data']['attributes']['product.label']); |
|
| 546 | 546 | |
| 547 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 548 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 547 | + $this->assertArrayNotHasKey('included', $result); |
|
| 548 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
| 552 | 552 | public function testPostBulk() |
| 553 | 553 | { |
| 554 | - $productManagerStub = $this->getProductMock( array( 'getItem', 'saveItem' ) ); |
|
| 554 | + $productManagerStub = $this->getProductMock(array('getItem', 'saveItem')); |
|
| 555 | 555 | |
| 556 | 556 | $item = $productManagerStub->createItem(); |
| 557 | - $item->setLabel( 'test' ); |
|
| 558 | - $item->setId( '-1' ); |
|
| 557 | + $item->setLabel('test'); |
|
| 558 | + $item->setId('-1'); |
|
| 559 | 559 | |
| 560 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'saveItem' ) |
|
| 561 | - ->will( $this->returnValue( $productManagerStub->createItem() ) ); |
|
| 562 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'getItem' ) |
|
| 563 | - ->will( $this->returnValue( $item ) ); |
|
| 560 | + $productManagerStub->expects($this->exactly(2))->method('saveItem') |
|
| 561 | + ->will($this->returnValue($productManagerStub->createItem())); |
|
| 562 | + $productManagerStub->expects($this->exactly(2))->method('getItem') |
|
| 563 | + ->will($this->returnValue($item)); |
|
| 564 | 564 | |
| 565 | 565 | |
| 566 | 566 | $body = '{"data": [{"type": "product", "attributes": {"product.label": "test"}}, {"type": "product", "attributes": {"product.label": "test"}}]}'; |
| 567 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 567 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 568 | 568 | |
| 569 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 570 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 569 | + $response = $this->object->post($request, $this->view->response()); |
|
| 570 | + $result = json_decode((string) $response->getBody(), true); |
|
| 571 | 571 | |
| 572 | 572 | |
| 573 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
| 574 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 573 | + $this->assertEquals(201, $response->getStatusCode()); |
|
| 574 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 575 | 575 | |
| 576 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
| 577 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 578 | - $this->assertEquals( 2, count( $result['data'] ) ); |
|
| 579 | - $this->assertEquals( '-1', $result['data'][0]['id'] ); |
|
| 580 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
| 581 | - $this->assertEquals( 'test', $result['data'][0]['attributes']['product.label'] ); |
|
| 576 | + $this->assertEquals(2, $result['meta']['total']); |
|
| 577 | + $this->assertArrayHasKey('data', $result); |
|
| 578 | + $this->assertEquals(2, count($result['data'])); |
|
| 579 | + $this->assertEquals('-1', $result['data'][0]['id']); |
|
| 580 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
| 581 | + $this->assertEquals('test', $result['data'][0]['attributes']['product.label']); |
|
| 582 | 582 | |
| 583 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 584 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 583 | + $this->assertArrayNotHasKey('included', $result); |
|
| 584 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | |
| 588 | 588 | public function testPostRelationships() |
| 589 | 589 | { |
| 590 | - $productManagerStub = $this->getProductMock( array( 'getSubManager', 'createItem', 'getItem', 'saveItem' ) ); |
|
| 591 | - $productManagerListsStub = $this->getProductListsMock( array( 'saveItem' ) ); |
|
| 590 | + $productManagerStub = $this->getProductMock(array('getSubManager', 'createItem', 'getItem', 'saveItem')); |
|
| 591 | + $productManagerListsStub = $this->getProductListsMock(array('saveItem')); |
|
| 592 | 592 | |
| 593 | 593 | $item = new \Aimeos\MShop\Product\Item\Standard(); |
| 594 | - $item->setId( '-1' ); |
|
| 594 | + $item->setId('-1'); |
|
| 595 | 595 | |
| 596 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'createItem' ) |
|
| 597 | - ->will( $this->returnValue( $item ) ); |
|
| 598 | - $productManagerStub->expects( $this->any() )->method( 'getItem' ) |
|
| 599 | - ->will( $this->returnValue( $item ) ); |
|
| 600 | - $productManagerStub->expects( $this->once() )->method( 'getSubManager' ) |
|
| 601 | - ->will( $this->returnValue( $productManagerListsStub ) ); |
|
| 602 | - $productManagerStub->expects( $this->once() )->method( 'saveItem' ) |
|
| 603 | - ->will( $this->returnValue( $productManagerStub->createItem() ) ); |
|
| 596 | + $productManagerStub->expects($this->exactly(2))->method('createItem') |
|
| 597 | + ->will($this->returnValue($item)); |
|
| 598 | + $productManagerStub->expects($this->any())->method('getItem') |
|
| 599 | + ->will($this->returnValue($item)); |
|
| 600 | + $productManagerStub->expects($this->once())->method('getSubManager') |
|
| 601 | + ->will($this->returnValue($productManagerListsStub)); |
|
| 602 | + $productManagerStub->expects($this->once())->method('saveItem') |
|
| 603 | + ->will($this->returnValue($productManagerStub->createItem())); |
|
| 604 | 604 | |
| 605 | - $productManagerListsStub->expects( $this->once() )->method( 'saveItem' ); |
|
| 605 | + $productManagerListsStub->expects($this->once())->method('saveItem'); |
|
| 606 | 606 | |
| 607 | 607 | $body = '{"data": {"type": "product", |
| 608 | 608 | "attributes": {"product.label": "test"}, |
@@ -610,213 +610,213 @@ discard block |
||
| 610 | 610 | {"type": "text", "id": "-2", "attributes": {"product.lists.type": "default"}} |
| 611 | 611 | ]}} |
| 612 | 612 | }}'; |
| 613 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 613 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 614 | 614 | |
| 615 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 616 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 615 | + $response = $this->object->post($request, $this->view->response()); |
|
| 616 | + $result = json_decode((string) $response->getBody(), true); |
|
| 617 | 617 | |
| 618 | 618 | |
| 619 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
| 620 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 619 | + $this->assertEquals(201, $response->getStatusCode()); |
|
| 620 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 621 | 621 | |
| 622 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 623 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 624 | - $this->assertEquals( '-1', $result['data']['id'] ); |
|
| 625 | - $this->assertEquals( 'product', $result['data']['type'] ); |
|
| 626 | - $this->assertEquals( 'test', $result['data']['attributes']['product.label'] ); |
|
| 622 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 623 | + $this->assertArrayHasKey('data', $result); |
|
| 624 | + $this->assertEquals('-1', $result['data']['id']); |
|
| 625 | + $this->assertEquals('product', $result['data']['type']); |
|
| 626 | + $this->assertEquals('test', $result['data']['attributes']['product.label']); |
|
| 627 | 627 | |
| 628 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 629 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 628 | + $this->assertArrayNotHasKey('included', $result); |
|
| 629 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
| 633 | 633 | public function testPostInvalid() |
| 634 | 634 | { |
| 635 | 635 | $body = '{"data":null}'; |
| 636 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 636 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 637 | 637 | |
| 638 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 639 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 638 | + $response = $this->object->post($request, $this->view->response()); |
|
| 639 | + $result = json_decode((string) $response->getBody(), true); |
|
| 640 | 640 | |
| 641 | 641 | |
| 642 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
| 643 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 642 | + $this->assertEquals(400, $response->getStatusCode()); |
|
| 643 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 644 | 644 | |
| 645 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
| 646 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 647 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 648 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
| 645 | + $this->assertEquals(0, $result['meta']['total']); |
|
| 646 | + $this->assertArrayHasKey('errors', $result); |
|
| 647 | + $this->assertArrayNotHasKey('included', $result); |
|
| 648 | + $this->assertArrayNotHasKey('data', $result); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
| 652 | 652 | public function testPostInvalidId() |
| 653 | 653 | { |
| 654 | 654 | $body = '{"data":{"id":-1}}'; |
| 655 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 655 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 656 | 656 | |
| 657 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 658 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 657 | + $response = $this->object->post($request, $this->view->response()); |
|
| 658 | + $result = json_decode((string) $response->getBody(), true); |
|
| 659 | 659 | |
| 660 | 660 | |
| 661 | - $this->assertEquals( 403, $response->getStatusCode() ); |
|
| 662 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 661 | + $this->assertEquals(403, $response->getStatusCode()); |
|
| 662 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 663 | 663 | |
| 664 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
| 665 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 664 | + $this->assertEquals(0, $result['meta']['total']); |
|
| 665 | + $this->assertArrayHasKey('errors', $result); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
| 669 | 669 | public function testPostException() |
| 670 | 670 | { |
| 671 | - $this->getProductMock( array( 'saveItem' ) )->expects( $this->once() )->method( 'saveItem' ) |
|
| 672 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
| 671 | + $this->getProductMock(array('saveItem'))->expects($this->once())->method('saveItem') |
|
| 672 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
| 673 | 673 | |
| 674 | 674 | $body = '{"data":{}}'; |
| 675 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 675 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 676 | 676 | |
| 677 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 678 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 677 | + $response = $this->object->post($request, $this->view->response()); |
|
| 678 | + $result = json_decode((string) $response->getBody(), true); |
|
| 679 | 679 | |
| 680 | 680 | |
| 681 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
| 682 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 683 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 681 | + $this->assertEquals(500, $response->getStatusCode()); |
|
| 682 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 683 | + $this->assertArrayHasKey('errors', $result); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | |
| 687 | 687 | public function testPostMShopException() |
| 688 | 688 | { |
| 689 | - $this->getProductMock( array( 'saveItem' ) )->expects( $this->once() )->method( 'saveItem' ) |
|
| 690 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
| 689 | + $this->getProductMock(array('saveItem'))->expects($this->once())->method('saveItem') |
|
| 690 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
| 691 | 691 | |
| 692 | 692 | $body = '{"data":{}}'; |
| 693 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 693 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 694 | 694 | |
| 695 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 696 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 695 | + $response = $this->object->post($request, $this->view->response()); |
|
| 696 | + $result = json_decode((string) $response->getBody(), true); |
|
| 697 | 697 | |
| 698 | 698 | |
| 699 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
| 700 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 701 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 699 | + $this->assertEquals(404, $response->getStatusCode()); |
|
| 700 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 701 | + $this->assertArrayHasKey('errors', $result); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
| 705 | 705 | public function testPut() |
| 706 | 706 | { |
| 707 | - $response = $this->object->put( $this->view->request(), $this->view->response() ); |
|
| 708 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 707 | + $response = $this->object->put($this->view->request(), $this->view->response()); |
|
| 708 | + $result = json_decode((string) $response->getBody(), true); |
|
| 709 | 709 | |
| 710 | - $this->assertEquals( 501, $response->getStatusCode() ); |
|
| 711 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 712 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 710 | + $this->assertEquals(501, $response->getStatusCode()); |
|
| 711 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 712 | + $this->assertArrayHasKey('errors', $result); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | |
| 716 | 716 | public function testOptions() |
| 717 | 717 | { |
| 718 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
| 719 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 718 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
| 719 | + $result = json_decode((string) $response->getBody(), true); |
|
| 720 | 720 | |
| 721 | 721 | |
| 722 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 723 | - $this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
|
| 724 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 722 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 723 | + $this->assertEquals(1, count($response->getHeader('Allow'))); |
|
| 724 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 725 | 725 | |
| 726 | - $this->assertNull( $result['meta']['prefix'] ); |
|
| 727 | - $this->assertGreaterThan( 65, count( $result['meta']['resources'] ) ); |
|
| 728 | - $this->assertGreaterThan( 0, count( $result['meta']['attributes'] ) ); |
|
| 726 | + $this->assertNull($result['meta']['prefix']); |
|
| 727 | + $this->assertGreaterThan(65, count($result['meta']['resources'])); |
|
| 728 | + $this->assertGreaterThan(0, count($result['meta']['attributes'])); |
|
| 729 | 729 | |
| 730 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 730 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | |
| 734 | 734 | public function testOptionsWithPrefix() |
| 735 | 735 | { |
| 736 | 736 | $this->view->prefix = 'prefix'; |
| 737 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
| 738 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 737 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
| 738 | + $result = json_decode((string) $response->getBody(), true); |
|
| 739 | 739 | |
| 740 | 740 | |
| 741 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 742 | - $this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
|
| 743 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 741 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 742 | + $this->assertEquals(1, count($response->getHeader('Allow'))); |
|
| 743 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 744 | 744 | |
| 745 | - $this->assertEquals( 'prefix', $result['meta']['prefix'] ); |
|
| 746 | - $this->assertGreaterThan( 65, count( $result['meta']['resources'] ) ); |
|
| 747 | - $this->assertGreaterThan( 0, count( $result['meta']['attributes'] ) ); |
|
| 745 | + $this->assertEquals('prefix', $result['meta']['prefix']); |
|
| 746 | + $this->assertGreaterThan(65, count($result['meta']['resources'])); |
|
| 747 | + $this->assertGreaterThan(0, count($result['meta']['attributes'])); |
|
| 748 | 748 | |
| 749 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 749 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | |
| 753 | 753 | public function testOptionsException() |
| 754 | 754 | { |
| 755 | - $this->getProductMock( array( 'getResourceType' ) )->expects( $this->once() )->method( 'getResourceType' ) |
|
| 756 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
| 755 | + $this->getProductMock(array('getResourceType'))->expects($this->once())->method('getResourceType') |
|
| 756 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
| 757 | 757 | |
| 758 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
| 759 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 758 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
| 759 | + $result = json_decode((string) $response->getBody(), true); |
|
| 760 | 760 | |
| 761 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
| 762 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 761 | + $this->assertEquals(500, $response->getStatusCode()); |
|
| 762 | + $this->assertArrayHasKey('errors', $result); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | |
| 766 | 766 | public function testOptionsMShopException() |
| 767 | 767 | { |
| 768 | - $this->getProductMock( array( 'getResourceType' ) )->expects( $this->once() )->method( 'getResourceType' ) |
|
| 769 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
| 768 | + $this->getProductMock(array('getResourceType'))->expects($this->once())->method('getResourceType') |
|
| 769 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
| 770 | 770 | |
| 771 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
| 772 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 771 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
| 772 | + $result = json_decode((string) $response->getBody(), true); |
|
| 773 | 773 | |
| 774 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
| 775 | - $this->assertArrayHasKey( 'errors', $result ); |
|
| 774 | + $this->assertEquals(404, $response->getStatusCode()); |
|
| 775 | + $this->assertArrayHasKey('errors', $result); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
| 779 | - protected function getProductMock( array $methods ) |
|
| 779 | + protected function getProductMock(array $methods) |
|
| 780 | 780 | { |
| 781 | 781 | $name = 'ClientJsonAdmStandard'; |
| 782 | - $this->context->getConfig()->set( 'mshop/product/manager/name', $name ); |
|
| 782 | + $this->context->getConfig()->set('mshop/product/manager/name', $name); |
|
| 783 | 783 | |
| 784 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Product\\Manager\\Standard' ) |
|
| 785 | - ->setConstructorArgs( array( $this->context ) ) |
|
| 786 | - ->setMethods( $methods ) |
|
| 784 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Product\\Manager\\Standard') |
|
| 785 | + ->setConstructorArgs(array($this->context)) |
|
| 786 | + ->setMethods($methods) |
|
| 787 | 787 | ->getMock(); |
| 788 | 788 | |
| 789 | - \Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $stub ); |
|
| 789 | + \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Product\\Manager\\' . $name, $stub); |
|
| 790 | 790 | |
| 791 | 791 | return $stub; |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | |
| 795 | - protected function getProductListsMock( array $methods ) |
|
| 795 | + protected function getProductListsMock(array $methods) |
|
| 796 | 796 | { |
| 797 | 797 | $name = 'ClientJsonAdmStandard'; |
| 798 | - $this->context->getConfig()->set( 'mshop/product/manager/lists/name', $name ); |
|
| 798 | + $this->context->getConfig()->set('mshop/product/manager/lists/name', $name); |
|
| 799 | 799 | |
| 800 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Product\\Manager\\Lists\\Standard' ) |
|
| 801 | - ->setConstructorArgs( array( $this->context ) ) |
|
| 802 | - ->setMethods( $methods ) |
|
| 800 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Product\\Manager\\Lists\\Standard') |
|
| 801 | + ->setConstructorArgs(array($this->context)) |
|
| 802 | + ->setMethods($methods) |
|
| 803 | 803 | ->getMock(); |
| 804 | 804 | |
| 805 | - \Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\Lists\\' . $name, $stub ); |
|
| 805 | + \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Product\\Manager\\Lists\\' . $name, $stub); |
|
| 806 | 806 | |
| 807 | 807 | return $stub; |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
| 811 | - protected function getProductItem( $code = 'CNC' ) |
|
| 811 | + protected function getProductItem($code = 'CNC') |
|
| 812 | 812 | { |
| 813 | - $manager = \Aimeos\MShop::create( $this->context, 'product' ); |
|
| 813 | + $manager = \Aimeos\MShop::create($this->context, 'product'); |
|
| 814 | 814 | $search = $manager->createSearch(); |
| 815 | - $search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
|
| 816 | - $items = $manager->searchItems( $search ); |
|
| 815 | + $search->setConditions($search->compare('==', 'product.code', $code)); |
|
| 816 | + $items = $manager->searchItems($search); |
|
| 817 | 817 | |
| 818 | - if( ( $item = reset( $items ) ) === false ) { |
|
| 819 | - throw new \RuntimeException( sprintf( 'No product item with code "%1$s" found', $code ) ); |
|
| 818 | + if (($item = reset($items)) === false) { |
|
| 819 | + throw new \RuntimeException(sprintf('No product item with code "%1$s" found', $code)); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | return $item; |
@@ -18,45 +18,45 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | protected function setUp() |
| 20 | 20 | { |
| 21 | - \Aimeos\MShop::cache( true ); |
|
| 21 | + \Aimeos\MShop::cache(true); |
|
| 22 | 22 | |
| 23 | 23 | $this->context = \TestHelperJadm::getContext(); |
| 24 | 24 | $this->view = $this->context->getView(); |
| 25 | 25 | |
| 26 | - $this->object = new \Aimeos\Admin\JsonAdm\Locale\Site\Standard( $this->context, 'locale/site' ); |
|
| 27 | - $this->object->setAimeos( \TestHelperJadm::getAimeos() ); |
|
| 28 | - $this->object->setView( $this->view ); |
|
| 26 | + $this->object = new \Aimeos\Admin\JsonAdm\Locale\Site\Standard($this->context, 'locale/site'); |
|
| 27 | + $this->object->setAimeos(\TestHelperJadm::getAimeos()); |
|
| 28 | + $this->object->setView($this->view); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | protected function tearDown() |
| 33 | 33 | { |
| 34 | - \Aimeos\MShop::cache( false ); |
|
| 34 | + \Aimeos\MShop::cache(false); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | public function testGet() |
| 39 | 39 | { |
| 40 | 40 | $params = array( |
| 41 | - 'id' => $this->getSiteItem( 'unittest' )->getId(), |
|
| 41 | + 'id' => $this->getSiteItem('unittest')->getId(), |
|
| 42 | 42 | 'filter' => array( |
| 43 | - '==' => array( 'locale.status' => 0 ) |
|
| 43 | + '==' => array('locale.status' => 0) |
|
| 44 | 44 | ), |
| 45 | 45 | ); |
| 46 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 47 | - $this->view->addHelper( 'param', $helper ); |
|
| 46 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 47 | + $this->view->addHelper('param', $helper); |
|
| 48 | 48 | |
| 49 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 50 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 49 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 50 | + $result = json_decode((string) $response->getBody(), true); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 54 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 53 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 54 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 55 | 55 | |
| 56 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 57 | - $this->assertEquals( 'locale/site', $result['data']['type'] ); |
|
| 56 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 57 | + $this->assertEquals('locale/site', $result['data']['type']); |
|
| 58 | 58 | |
| 59 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 59 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -64,124 +64,124 @@ discard block |
||
| 64 | 64 | { |
| 65 | 65 | $params = array( |
| 66 | 66 | 'filter' => array( |
| 67 | - '==' => array( 'locale.site.code' => 'unittest' ) |
|
| 67 | + '==' => array('locale.site.code' => 'unittest') |
|
| 68 | 68 | ), |
| 69 | 69 | ); |
| 70 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 71 | - $this->view->addHelper( 'param', $helper ); |
|
| 70 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 71 | + $this->view->addHelper('param', $helper); |
|
| 72 | 72 | |
| 73 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
| 74 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 73 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
| 74 | + $result = json_decode((string) $response->getBody(), true); |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 78 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 77 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 78 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 79 | 79 | |
| 80 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 81 | - $this->assertEquals( 1, count( $result['data'] ) ); |
|
| 82 | - $this->assertEquals( 'locale/site', $result['data'][0]['type'] ); |
|
| 80 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 81 | + $this->assertEquals(1, count($result['data'])); |
|
| 82 | + $this->assertEquals('locale/site', $result['data'][0]['type']); |
|
| 83 | 83 | |
| 84 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 84 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | public function testPatch() |
| 89 | 89 | { |
| 90 | - $stub = $this->getSiteMock( array( 'getItem', 'moveItem', 'saveItem' ) ); |
|
| 90 | + $stub = $this->getSiteMock(array('getItem', 'moveItem', 'saveItem')); |
|
| 91 | 91 | $item = $stub->createItem(); |
| 92 | 92 | |
| 93 | - $stub->expects( $this->once() )->method( 'saveItem' ) |
|
| 94 | - ->will( $this->returnValue( $stub->createItem() ) ); |
|
| 95 | - $stub->expects( $this->exactly( 2 ) )->method( 'getItem' ) // 2x due to decorator |
|
| 96 | - ->will( $this->returnValue( $item ) ); |
|
| 93 | + $stub->expects($this->once())->method('saveItem') |
|
| 94 | + ->will($this->returnValue($stub->createItem())); |
|
| 95 | + $stub->expects($this->exactly(2))->method('getItem') // 2x due to decorator |
|
| 96 | + ->will($this->returnValue($item)); |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | - $params = array( 'id' => '-1' ); |
|
| 100 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 101 | - $this->view->addHelper( 'param', $helper ); |
|
| 99 | + $params = array('id' => '-1'); |
|
| 100 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 101 | + $this->view->addHelper('param', $helper); |
|
| 102 | 102 | |
| 103 | 103 | $body = '{"data": {"parentid": "1", "targetid": 2, "type": "locale/site", "attributes": {"locale.site.label": "test"}}}'; |
| 104 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 104 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 105 | 105 | |
| 106 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
| 107 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 106 | + $response = $this->object->patch($request, $this->view->response()); |
|
| 107 | + $result = json_decode((string) $response->getBody(), true); |
|
| 108 | 108 | |
| 109 | 109 | |
| 110 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
| 111 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 110 | + $this->assertEquals(200, $response->getStatusCode()); |
|
| 111 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 112 | 112 | |
| 113 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 114 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 115 | - $this->assertEquals( 'locale/site', $result['data']['type'] ); |
|
| 113 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 114 | + $this->assertArrayHasKey('data', $result); |
|
| 115 | + $this->assertEquals('locale/site', $result['data']['type']); |
|
| 116 | 116 | |
| 117 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 118 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 117 | + $this->assertArrayNotHasKey('included', $result); |
|
| 118 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
| 122 | 122 | public function testPost() |
| 123 | 123 | { |
| 124 | - $stub = $this->getSiteMock( array( 'getItem', 'insertItem' ) ); |
|
| 124 | + $stub = $this->getSiteMock(array('getItem', 'insertItem')); |
|
| 125 | 125 | $item = $stub->createItem(); |
| 126 | 126 | |
| 127 | - $stub->expects( $this->any() )->method( 'getItem' ) |
|
| 128 | - ->will( $this->returnValue( $item ) ); |
|
| 129 | - $stub->expects( $this->once() )->method( 'insertItem' ); |
|
| 127 | + $stub->expects($this->any())->method('getItem') |
|
| 128 | + ->will($this->returnValue($item)); |
|
| 129 | + $stub->expects($this->once())->method('insertItem'); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | $body = '{"data": {"type": "locale/site", "attributes": {"locale.site.code": "unittest", "locale.site.label": "Unit test"}}}'; |
| 133 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
| 133 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
| 134 | 134 | |
| 135 | - $response = $this->object->post( $request, $this->view->response() ); |
|
| 136 | - $result = json_decode( (string) $response->getBody(), true ); |
|
| 135 | + $response = $this->object->post($request, $this->view->response()); |
|
| 136 | + $result = json_decode((string) $response->getBody(), true); |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
| 140 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
| 139 | + $this->assertEquals(201, $response->getStatusCode()); |
|
| 140 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
| 141 | 141 | |
| 142 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 143 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 144 | - $this->assertEquals( 'locale/site', $result['data']['type'] ); |
|
| 142 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 143 | + $this->assertArrayHasKey('data', $result); |
|
| 144 | + $this->assertEquals('locale/site', $result['data']['type']); |
|
| 145 | 145 | |
| 146 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 147 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 146 | + $this->assertArrayNotHasKey('included', $result); |
|
| 147 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
| 151 | - protected function getSiteItem( $code ) |
|
| 151 | + protected function getSiteItem($code) |
|
| 152 | 152 | { |
| 153 | - $manager = \Aimeos\MShop::create( $this->context, 'locale/site' ); |
|
| 153 | + $manager = \Aimeos\MShop::create($this->context, 'locale/site'); |
|
| 154 | 154 | $search = $manager->createSearch(); |
| 155 | - $search->setConditions( $search->compare( '==', 'locale.site.code', $code ) ); |
|
| 156 | - $items = $manager->searchItems( $search ); |
|
| 155 | + $search->setConditions($search->compare('==', 'locale.site.code', $code)); |
|
| 156 | + $items = $manager->searchItems($search); |
|
| 157 | 157 | |
| 158 | - if( ( $item = reset( $items ) ) === false ) { |
|
| 159 | - throw new \RuntimeException( sprintf( 'No locale site item with code "%1$s" found', $code ) ); |
|
| 158 | + if (($item = reset($items)) === false) { |
|
| 159 | + throw new \RuntimeException(sprintf('No locale site item with code "%1$s" found', $code)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | return $item; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
| 166 | - protected function getSiteMock( array $methods ) |
|
| 166 | + protected function getSiteMock(array $methods) |
|
| 167 | 167 | { |
| 168 | 168 | $name = 'AdminJsonAdmStandard'; |
| 169 | - $this->context->getConfig()->set( 'mshop/locale/manager/name', $name ); |
|
| 169 | + $this->context->getConfig()->set('mshop/locale/manager/name', $name); |
|
| 170 | 170 | |
| 171 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Locale\\Manager\\Standard' ) |
|
| 172 | - ->setConstructorArgs( array( $this->context ) ) |
|
| 173 | - ->setMethods( array( 'getSubManager' ) ) |
|
| 171 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Locale\\Manager\\Standard') |
|
| 172 | + ->setConstructorArgs(array($this->context)) |
|
| 173 | + ->setMethods(array('getSubManager')) |
|
| 174 | 174 | ->getMock(); |
| 175 | 175 | |
| 176 | - $siteStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Locale\\Manager\\Site\\Standard' ) |
|
| 177 | - ->setConstructorArgs( array( $this->context ) ) |
|
| 178 | - ->setMethods( $methods ) |
|
| 176 | + $siteStub = $this->getMockBuilder('\\Aimeos\\MShop\\Locale\\Manager\\Site\\Standard') |
|
| 177 | + ->setConstructorArgs(array($this->context)) |
|
| 178 | + ->setMethods($methods) |
|
| 179 | 179 | ->getMock(); |
| 180 | 180 | |
| 181 | - $stub->expects( $this->once() )->method( 'getSubManager' ) |
|
| 182 | - ->will( $this->returnValue( $siteStub ) ); |
|
| 181 | + $stub->expects($this->once())->method('getSubManager') |
|
| 182 | + ->will($this->returnValue($siteStub)); |
|
| 183 | 183 | |
| 184 | - \Aimeos\MShop\Locale\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Locale\\Manager\\' . $name, $stub ); |
|
| 184 | + \Aimeos\MShop\Locale\Manager\Factory::injectManager('\\Aimeos\\MShop\\Locale\\Manager\\' . $name, $stub); |
|
| 185 | 185 | |
| 186 | 186 | return $siteStub; |
| 187 | 187 | } |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | $context = \TestHelperJadm::getContext(); |
| 17 | 17 | $aimeos = \TestHelperJadm::getAimeos(); |
| 18 | 18 | |
| 19 | - $client = \Aimeos\Admin\JsonAdm::create( $context, $aimeos, 'order' ); |
|
| 20 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client ); |
|
| 21 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Order\\Standard', $client ); |
|
| 19 | + $client = \Aimeos\Admin\JsonAdm::create($context, $aimeos, 'order'); |
|
| 20 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client); |
|
| 21 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Order\\Standard', $client); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | $context = \TestHelperJadm::getContext(); |
| 28 | 28 | $aimeos = \TestHelperJadm::getAimeos(); |
| 29 | 29 | |
| 30 | - $client = \Aimeos\Admin\JsonAdm::create( $context, $aimeos, 'order/base' ); |
|
| 31 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client ); |
|
| 32 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Order\\Base\\Standard', $client ); |
|
| 30 | + $client = \Aimeos\Admin\JsonAdm::create($context, $aimeos, 'order/base'); |
|
| 31 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client); |
|
| 32 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Order\\Base\\Standard', $client); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | $context = \TestHelperJadm::getContext(); |
| 39 | 39 | $aimeos = \TestHelperJadm::getAimeos(); |
| 40 | 40 | |
| 41 | - $client = \Aimeos\Admin\JsonAdm::create( $context, $aimeos, 'stock/type' ); |
|
| 42 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client ); |
|
| 43 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Standard', $client ); |
|
| 41 | + $client = \Aimeos\Admin\JsonAdm::create($context, $aimeos, 'stock/type'); |
|
| 42 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client); |
|
| 43 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Standard', $client); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | $context = \TestHelperJadm::getContext(); |
| 50 | 50 | $aimeos = \TestHelperJadm::getAimeos(); |
| 51 | 51 | |
| 52 | - $client = \Aimeos\Admin\JsonAdm::create( $context, $aimeos, '' ); |
|
| 53 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client ); |
|
| 54 | - $this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Standard', $client ); |
|
| 52 | + $client = \Aimeos\Admin\JsonAdm::create($context, $aimeos, ''); |
|
| 53 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client); |
|
| 54 | + $this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Standard', $client); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | $context = \TestHelperJadm::getContext(); |
| 61 | 61 | $aimeos = \TestHelperJadm::getAimeos(); |
| 62 | 62 | |
| 63 | - $this->setExpectedException( '\\Aimeos\\Admin\\JsonAdm\\Exception' ); |
|
| 64 | - \Aimeos\Admin\JsonAdm::create( $context, $aimeos, '%^' ); |
|
| 63 | + $this->setExpectedException('\\Aimeos\\Admin\\JsonAdm\\Exception'); |
|
| 64 | + \Aimeos\Admin\JsonAdm::create($context, $aimeos, '%^'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $context = \TestHelperJadm::getContext(); |
| 71 | 71 | $aimeos = \TestHelperJadm::getAimeos(); |
| 72 | 72 | |
| 73 | - $this->setExpectedException( '\\Aimeos\\Admin\\JsonAdm\\Exception' ); |
|
| 74 | - \Aimeos\Admin\JsonAdm::create( $context, $aimeos, '', '%^' ); |
|
| 73 | + $this->setExpectedException('\\Aimeos\\Admin\\JsonAdm\\Exception'); |
|
| 74 | + \Aimeos\Admin\JsonAdm::create($context, $aimeos, '', '%^'); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | \ No newline at end of file |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | * @return \Aimeos\Admin\JsonAdm\Iface JSON admin instance |
| 35 | 35 | * @throws \Aimeos\Admin\JsonAdm\Exception If the given path is invalid |
| 36 | 36 | */ |
| 37 | - static public function create( \Aimeos\MShop\Context\Item\Iface $context, |
|
| 38 | - \Aimeos\Bootstrap $aimeos, $path, $name = null ) |
|
| 37 | + static public function create(\Aimeos\MShop\Context\Item\Iface $context, |
|
| 38 | + \Aimeos\Bootstrap $aimeos, $path, $name = null) |
|
| 39 | 39 | { |
| 40 | - if( empty( $path ) ) { |
|
| 41 | - return self::createRoot( $context, $aimeos, $path, $name ); |
|
| 40 | + if (empty($path)) { |
|
| 41 | + return self::createRoot($context, $aimeos, $path, $name); |
|
| 42 | 42 | } else { |
| 43 | - return self::createNew( $context, $aimeos, $path, $name ); |
|
| 43 | + return self::createNew($context, $aimeos, $path, $name); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
@@ -55,53 +55,53 @@ discard block |
||
| 55 | 55 | * @return \Aimeos\Admin\JsonAdm\Iface JSON admin instance |
| 56 | 56 | * @throws \Aimeos\Admin\JsonAdm\Exception If the given path is invalid |
| 57 | 57 | */ |
| 58 | - protected static function createNew( \Aimeos\MShop\Context\Item\Iface $context, |
|
| 59 | - \Aimeos\Bootstrap $aimeos, $path, $name ) |
|
| 58 | + protected static function createNew(\Aimeos\MShop\Context\Item\Iface $context, |
|
| 59 | + \Aimeos\Bootstrap $aimeos, $path, $name) |
|
| 60 | 60 | { |
| 61 | 61 | $pname = $name; |
| 62 | - $parts = explode( '/', $path ); |
|
| 62 | + $parts = explode('/', $path); |
|
| 63 | 63 | |
| 64 | - foreach( $parts as $key => $part ) |
|
| 64 | + foreach ($parts as $key => $part) |
|
| 65 | 65 | { |
| 66 | - if( ctype_alnum( $part ) === false ) |
|
| 66 | + if (ctype_alnum($part) === false) |
|
| 67 | 67 | { |
| 68 | - $msg = sprintf( 'Invalid client "%1$s"', $path ); |
|
| 69 | - throw new \Aimeos\Admin\JsonAdm\Exception( $msg, 400 ); |
|
| 68 | + $msg = sprintf('Invalid client "%1$s"', $path); |
|
| 69 | + throw new \Aimeos\Admin\JsonAdm\Exception($msg, 400); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $parts[$key] = ucwords( $part ); |
|
| 72 | + $parts[$key] = ucwords($part); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if( $pname === null ) { |
|
| 76 | - $pname = $context->getConfig()->get( 'admin/jsonadm/' . $path . '/name', 'Standard' ); |
|
| 75 | + if ($pname === null) { |
|
| 76 | + $pname = $context->getConfig()->get('admin/jsonadm/' . $path . '/name', 'Standard'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $view = $context->getView(); |
| 80 | 80 | $config = $context->getConfig(); |
| 81 | 81 | |
| 82 | - if( $view->access( $config->get( 'admin/jsonadm/resource/' . $path . '/groups', [] ) ) !== true ) { |
|
| 83 | - throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Not allowed to access JsonAdm "%1$s" client', $path ) ); |
|
| 82 | + if ($view->access($config->get('admin/jsonadm/resource/' . $path . '/groups', [])) !== true) { |
|
| 83 | + throw new \Aimeos\Admin\JQAdm\Exception(sprintf('Not allowed to access JsonAdm "%1$s" client', $path)); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | $view = $context->getView(); |
| 88 | 88 | $iface = \Aimeos\Admin\JsonAdm\Iface::class; |
| 89 | - $classname = '\\Aimeos\\Admin\\JsonAdm\\' . join( '\\', $parts ) . '\\' . $pname; |
|
| 89 | + $classname = '\\Aimeos\\Admin\\JsonAdm\\' . join('\\', $parts) . '\\' . $pname; |
|
| 90 | 90 | |
| 91 | - if( ctype_alnum( $pname ) === false ) |
|
| 91 | + if (ctype_alnum($pname) === false) |
|
| 92 | 92 | { |
| 93 | - $classname = is_string( $pname ) ? $classname : '<not a string>'; |
|
| 94 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid class name "%1$s"', $classname ) ); |
|
| 93 | + $classname = is_string($pname) ? $classname : '<not a string>'; |
|
| 94 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid class name "%1$s"', $classname)); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if( class_exists( $classname ) === false ) { |
|
| 98 | - return self::createRoot( $context, $aimeos, $path, $name ); |
|
| 97 | + if (class_exists($classname) === false) { |
|
| 98 | + return self::createRoot($context, $aimeos, $path, $name); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $client = self::createAdmin( $classname, $iface, $context, $path ); |
|
| 102 | - $client = self::addClientDecorators( $client, $context, $path ); |
|
| 101 | + $client = self::createAdmin($classname, $iface, $context, $path); |
|
| 102 | + $client = self::addClientDecorators($client, $context, $path); |
|
| 103 | 103 | |
| 104 | - return $client->setAimeos( $aimeos )->setView( $view ); |
|
| 104 | + return $client->setAimeos($aimeos)->setView($view); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | * @return \Aimeos\Admin\JsonAdm\Iface JSON admin instance |
| 116 | 116 | * @throws \Aimeos\Admin\JsonAdm\Exception If the client couldn't be created |
| 117 | 117 | */ |
| 118 | - protected static function createRoot( \Aimeos\MShop\Context\Item\Iface $context, |
|
| 119 | - \Aimeos\Bootstrap $aimeos, $path, $name = null ) |
|
| 118 | + protected static function createRoot(\Aimeos\MShop\Context\Item\Iface $context, |
|
| 119 | + \Aimeos\Bootstrap $aimeos, $path, $name = null) |
|
| 120 | 120 | { |
| 121 | 121 | /** admin/jsonadm/name |
| 122 | 122 | * Class name of the used JSON API client implementation |
@@ -151,21 +151,21 @@ discard block |
||
| 151 | 151 | * @since 2015.12 |
| 152 | 152 | * @category Developer |
| 153 | 153 | */ |
| 154 | - if( $name === null ) { |
|
| 155 | - $name = $context->getConfig()->get( 'admin/jsonadm/name', 'Standard' ); |
|
| 154 | + if ($name === null) { |
|
| 155 | + $name = $context->getConfig()->get('admin/jsonadm/name', 'Standard'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if( ctype_alnum( $name ) === false ) |
|
| 158 | + if (ctype_alnum($name) === false) |
|
| 159 | 159 | { |
| 160 | - $classname = is_string( $name ) ? '\\Aimeos\\Admin\\JsonAdm\\' . $name : '<not a string>'; |
|
| 161 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid class name "%1$s"', $classname ) ); |
|
| 160 | + $classname = is_string($name) ? '\\Aimeos\\Admin\\JsonAdm\\' . $name : '<not a string>'; |
|
| 161 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid class name "%1$s"', $classname)); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $view = $context->getView(); |
| 165 | 165 | $iface = '\\Aimeos\\Admin\\JsonAdm\\Iface'; |
| 166 | 166 | $classname = '\\Aimeos\\Admin\\JsonAdm\\' . $name; |
| 167 | 167 | |
| 168 | - $client = self::createAdmin( $classname, $iface, $context, $path ); |
|
| 168 | + $client = self::createAdmin($classname, $iface, $context, $path); |
|
| 169 | 169 | |
| 170 | 170 | /** admin/jsonadm/decorators/excludes |
| 171 | 171 | * Excludes decorators added by the "common" option from the JSON API clients |
@@ -245,8 +245,8 @@ discard block |
||
| 245 | 245 | * @see admin/jsonadm/decorators/global |
| 246 | 246 | */ |
| 247 | 247 | |
| 248 | - $client = self::addClientDecorators( $client, $context, $path ); |
|
| 248 | + $client = self::addClientDecorators($client, $context, $path); |
|
| 249 | 249 | |
| 250 | - return $client->setAimeos( $aimeos )->setView( $view ); |
|
| 250 | + return $client->setAimeos($aimeos)->setView($view); |
|
| 251 | 251 | } |
| 252 | 252 | } |