Example #1
0
 public function testFromArray()
 {
     $item = new \Aimeos\MShop\Product\Item\Standard();
     $list = array('product.id' => 1, 'product.typeid' => 2, 'product.type' => 'test', 'product.typename' => 'Test', 'product.label' => 'test item', 'product.code' => 'test', 'product.datestart' => '2000-01-01 00:00:00', 'product.dateend' => '2001-01-01 00:00:00', 'product.config' => array('key' => 'value'), 'product.status' => 0);
     $unknown = $item->fromArray($list);
     $this->assertEquals(array(), $unknown);
     $this->assertEquals($list['product.id'], $item->getId());
     $this->assertEquals($list['product.code'], $item->getCode());
     $this->assertEquals($list['product.label'], $item->getLabel());
     $this->assertEquals($list['product.typeid'], $item->getTypeId());
     $this->assertEquals($list['product.datestart'], $item->getDateStart());
     $this->assertEquals($list['product.dateend'], $item->getDateEnd());
     $this->assertEquals($list['product.config'], $item->getConfig());
     $this->assertEquals($list['product.status'], $item->getStatus());
     $this->assertNull($item->getSiteId());
     $this->assertNull($item->getTypeName());
     $this->assertNull($item->getType());
 }
Example #2
0
    public function testPostRelationships()
    {
        $productManagerStub = $this->getProductMock(array('getSubManager', 'createItem', 'getItem', 'saveItem'));
        $productManagerListsStub = $this->getProductListsMock(array('saveItem'));
        $item = new \Aimeos\MShop\Product\Item\Standard();
        $item->setId('-1');
        $productManagerStub->expects($this->once())->method('createItem')->will($this->returnValue($item));
        $productManagerStub->expects($this->any())->method('getItem')->will($this->returnValue($item));
        $productManagerStub->expects($this->once())->method('getSubManager')->will($this->returnValue($productManagerListsStub));
        $productManagerStub->expects($this->once())->method('saveItem');
        $productManagerListsStub->expects($this->once())->method('saveItem');
        $body = '{"data": {"type": "product",
			"attributes": {"product.label": "test"},
			"relationships": {"text": {"data": [
				{"type": "text", "id": "-2", "attributes": {"product.lists.type": "default"}}
			]}}
		}}';
        $header = array();
        $status = 500;
        $result = json_decode($this->object->post($body, $header, $status), true);
        $this->assertEquals(201, $status);
        $this->assertEquals(1, count($header));
        $this->assertEquals(1, $result['meta']['total']);
        $this->assertArrayHasKey('data', $result);
        $this->assertEquals('-1', $result['data']['id']);
        $this->assertEquals('product', $result['data']['type']);
        $this->assertEquals('test', $result['data']['attributes']['product.label']);
        $this->assertArrayNotHasKey('included', $result);
        $this->assertArrayNotHasKey('errors', $result);
    }