@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | $templatePaths = \TestHelperJadm::getJsonadmPaths(); |
| 23 | 23 | $this->view = $this->context->getView(); |
| 24 | 24 | |
| 25 | - $this->object = new \Aimeos\Admin\JsonAdm\Catalog\Standard( $this->context, $this->view, $templatePaths, 'catalog' ); |
|
| 25 | + $this->object = new \Aimeos\Admin\JsonAdm\Catalog\Standard($this->context, $this->view, $templatePaths, 'catalog'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -30,137 +30,137 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $params = array( |
| 32 | 32 | 'filter' => array( |
| 33 | - '==' => array( 'catalog.code' => 'cafe' ) |
|
| 33 | + '==' => array('catalog.code' => 'cafe') |
|
| 34 | 34 | ), |
| 35 | 35 | 'include' => 'text' |
| 36 | 36 | ); |
| 37 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 38 | - $this->view->addHelper( 'param', $helper ); |
|
| 37 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 38 | + $this->view->addHelper('param', $helper); |
|
| 39 | 39 | |
| 40 | 40 | $header = array(); |
| 41 | 41 | $status = 500; |
| 42 | 42 | |
| 43 | - $result = json_decode( $this->object->get( '', $header, $status ), true ); |
|
| 43 | + $result = json_decode($this->object->get('', $header, $status), true); |
|
| 44 | 44 | |
| 45 | - $this->assertEquals( 200, $status ); |
|
| 46 | - $this->assertEquals( 1, count( $header ) ); |
|
| 47 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 48 | - $this->assertEquals( 1, count( $result['data'] ) ); |
|
| 49 | - $this->assertEquals( 'catalog', $result['data'][0]['type'] ); |
|
| 50 | - $this->assertEquals( 6, count( $result['data'][0]['relationships']['text'] ) ); |
|
| 51 | - $this->assertEquals( 6, count( $result['included'] ) ); |
|
| 52 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 45 | + $this->assertEquals(200, $status); |
|
| 46 | + $this->assertEquals(1, count($header)); |
|
| 47 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 48 | + $this->assertEquals(1, count($result['data'])); |
|
| 49 | + $this->assertEquals('catalog', $result['data'][0]['type']); |
|
| 50 | + $this->assertEquals(6, count($result['data'][0]['relationships']['text'])); |
|
| 51 | + $this->assertEquals(6, count($result['included'])); |
|
| 52 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | public function testGetTree() |
| 57 | 57 | { |
| 58 | 58 | $params = array( |
| 59 | - 'id' => $this->getCatalogItem( 'group' )->getId(), |
|
| 59 | + 'id' => $this->getCatalogItem('group')->getId(), |
|
| 60 | 60 | 'filter' => array( |
| 61 | - '==' => array( 'catalog.status' => 1 ) |
|
| 61 | + '==' => array('catalog.status' => 1) |
|
| 62 | 62 | ), |
| 63 | 63 | 'include' => 'catalog,text' |
| 64 | 64 | ); |
| 65 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 66 | - $this->view->addHelper( 'param', $helper ); |
|
| 65 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 66 | + $this->view->addHelper('param', $helper); |
|
| 67 | 67 | |
| 68 | 68 | $header = array(); |
| 69 | 69 | $status = 500; |
| 70 | 70 | |
| 71 | - $result = json_decode( $this->object->get( '', $header, $status ), true ); |
|
| 71 | + $result = json_decode($this->object->get('', $header, $status), true); |
|
| 72 | 72 | |
| 73 | - $this->assertEquals( 200, $status ); |
|
| 74 | - $this->assertEquals( 1, count( $header ) ); |
|
| 75 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 76 | - $this->assertEquals( 'catalog', $result['data']['type'] ); |
|
| 77 | - $this->assertEquals( 2, count( $result['data']['relationships']['catalog'] ) ); |
|
| 78 | - $this->assertEquals( 2, count( $result['included'] ) ); |
|
| 79 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 73 | + $this->assertEquals(200, $status); |
|
| 74 | + $this->assertEquals(1, count($header)); |
|
| 75 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 76 | + $this->assertEquals('catalog', $result['data']['type']); |
|
| 77 | + $this->assertEquals(2, count($result['data']['relationships']['catalog'])); |
|
| 78 | + $this->assertEquals(2, count($result['included'])); |
|
| 79 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | public function testPatch() |
| 84 | 84 | { |
| 85 | - $stub = $this->getCatalogMock( array( 'getItem', 'moveItem', 'saveItem' ) ); |
|
| 85 | + $stub = $this->getCatalogMock(array('getItem', 'moveItem', 'saveItem')); |
|
| 86 | 86 | |
| 87 | - $stub->expects( $this->once() )->method( 'moveItem' ); |
|
| 88 | - $stub->expects( $this->once() )->method( 'saveItem' ); |
|
| 89 | - $stub->expects( $this->exactly( 2 ) )->method( 'getItem' ) // 2x due to decorator |
|
| 90 | - ->will( $this->returnValue( $stub->createItem() ) ); |
|
| 87 | + $stub->expects($this->once())->method('moveItem'); |
|
| 88 | + $stub->expects($this->once())->method('saveItem'); |
|
| 89 | + $stub->expects($this->exactly(2))->method('getItem') // 2x due to decorator |
|
| 90 | + ->will($this->returnValue($stub->createItem())); |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - $params = array( 'id' => '-1' ); |
|
| 94 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
| 95 | - $this->view->addHelper( 'param', $helper ); |
|
| 93 | + $params = array('id' => '-1'); |
|
| 94 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
| 95 | + $this->view->addHelper('param', $helper); |
|
| 96 | 96 | |
| 97 | 97 | $body = '{"data": {"parentid": "1", "targetid": 2, "type": "catalog", "attributes": {"catalog.label": "test"}}}'; |
| 98 | 98 | $header = array(); |
| 99 | 99 | $status = 500; |
| 100 | 100 | |
| 101 | - $result = json_decode( $this->object->patch( $body, $header, $status ), true ); |
|
| 101 | + $result = json_decode($this->object->patch($body, $header, $status), true); |
|
| 102 | 102 | |
| 103 | - $this->assertEquals( 200, $status ); |
|
| 104 | - $this->assertEquals( 1, count( $header ) ); |
|
| 105 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 106 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 107 | - $this->assertEquals( 'catalog', $result['data']['type'] ); |
|
| 108 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 109 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 103 | + $this->assertEquals(200, $status); |
|
| 104 | + $this->assertEquals(1, count($header)); |
|
| 105 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 106 | + $this->assertArrayHasKey('data', $result); |
|
| 107 | + $this->assertEquals('catalog', $result['data']['type']); |
|
| 108 | + $this->assertArrayNotHasKey('included', $result); |
|
| 109 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
| 113 | 113 | public function testPost() |
| 114 | 114 | { |
| 115 | - $stub = $this->getCatalogMock( array( 'getItem', 'insertItem' ) ); |
|
| 115 | + $stub = $this->getCatalogMock(array('getItem', 'insertItem')); |
|
| 116 | 116 | |
| 117 | - $stub->expects( $this->any() )->method( 'getItem' ) |
|
| 118 | - ->will( $this->returnValue( $stub->createItem() ) ); |
|
| 119 | - $stub->expects( $this->once() )->method( 'insertItem' ); |
|
| 117 | + $stub->expects($this->any())->method('getItem') |
|
| 118 | + ->will($this->returnValue($stub->createItem())); |
|
| 119 | + $stub->expects($this->once())->method('insertItem'); |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | 122 | $body = '{"data": {"type": "catalog", "attributes": {"catalog.code": "test", "catalog.label": "Test catalog"}}}'; |
| 123 | 123 | $header = array(); |
| 124 | 124 | $status = 500; |
| 125 | 125 | |
| 126 | - $result = json_decode( $this->object->post( $body, $header, $status ), true ); |
|
| 126 | + $result = json_decode($this->object->post($body, $header, $status), true); |
|
| 127 | 127 | |
| 128 | - $this->assertEquals( 201, $status ); |
|
| 129 | - $this->assertEquals( 1, count( $header ) ); |
|
| 130 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
| 131 | - $this->assertArrayHasKey( 'data', $result ); |
|
| 132 | - $this->assertEquals( 'catalog', $result['data']['type'] ); |
|
| 133 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
| 134 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
| 128 | + $this->assertEquals(201, $status); |
|
| 129 | + $this->assertEquals(1, count($header)); |
|
| 130 | + $this->assertEquals(1, $result['meta']['total']); |
|
| 131 | + $this->assertArrayHasKey('data', $result); |
|
| 132 | + $this->assertEquals('catalog', $result['data']['type']); |
|
| 133 | + $this->assertArrayNotHasKey('included', $result); |
|
| 134 | + $this->assertArrayNotHasKey('errors', $result); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
| 138 | - protected function getCatalogItem( $code ) |
|
| 138 | + protected function getCatalogItem($code) |
|
| 139 | 139 | { |
| 140 | - $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context ); |
|
| 140 | + $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context); |
|
| 141 | 141 | $search = $manager->createSearch(); |
| 142 | - $search->setConditions( $search->compare( '==', 'catalog.code', $code ) ); |
|
| 143 | - $items = $manager->searchItems( $search ); |
|
| 142 | + $search->setConditions($search->compare('==', 'catalog.code', $code)); |
|
| 143 | + $items = $manager->searchItems($search); |
|
| 144 | 144 | |
| 145 | - if( ( $item = reset( $items ) ) === false ) { |
|
| 146 | - throw new \Exception( sprintf( 'No catalog item with code "%1$s" found', $code ) ); |
|
| 145 | + if (($item = reset($items)) === false) { |
|
| 146 | + throw new \Exception(sprintf('No catalog item with code "%1$s" found', $code)); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $item; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
| 153 | - protected function getCatalogMock( array $methods ) |
|
| 153 | + protected function getCatalogMock(array $methods) |
|
| 154 | 154 | { |
| 155 | 155 | $name = 'ClientJsonAdmStandard'; |
| 156 | - $this->context->getConfig()->set( 'mshop/catalog/manager/name', $name ); |
|
| 156 | + $this->context->getConfig()->set('mshop/catalog/manager/name', $name); |
|
| 157 | 157 | |
| 158 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Catalog\\Manager\\Standard' ) |
|
| 159 | - ->setConstructorArgs( array( $this->context ) ) |
|
| 160 | - ->setMethods( $methods ) |
|
| 158 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Catalog\\Manager\\Standard') |
|
| 159 | + ->setConstructorArgs(array($this->context)) |
|
| 160 | + ->setMethods($methods) |
|
| 161 | 161 | ->getMock(); |
| 162 | 162 | |
| 163 | - \Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Catalog\\Manager\\' . $name, $stub ); |
|
| 163 | + \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Catalog\\Manager\\' . $name, $stub); |
|
| 164 | 164 | |
| 165 | 165 | return $stub; |
| 166 | 166 | } |