Пример #1
0
 /**
  * @test
  */
 public function it_adds_a_product_to_a_site()
 {
     $wps = new Sdk();
     $new_product = ['id' => 3, 'supplier_product_id' => '123456', 'variableproduct_id' => 13, 'brand_id' => 1, 'country_id' => 3, 'name' => 'test product', 'list_price' => '1.73', 'estimated_weight' => "25.676", 'sku' => '12-1234', 'upc' => '123456789123', 'description' => 'Here is a description of product 1', 'published_at' => '2015-06-05', 'has_map_policy' => false];
     $response = $wps->productsResponse();
     array_push($response['data'], $new_product);
     $wps->addMockResults([new Response(200, [], json_encode($wps->siteResponse(1))), new Response(200, [], json_encode($wps->productResponse(3))), new Response(200, [], json_encode($response))]);
     $site = $wps->site()->find(1);
     $product = $wps->product(['supplier_product_id' => '123456', 'variableproduct_id' => 13, 'brand_id' => 1, 'country_id' => 3, 'name' => 'test product', 'list_price' => '1.73', 'estimated_weight' => "25.676", 'sku' => '12-1234', 'upc' => '123456789123', 'description' => 'Here is a description of product 1', 'published_at' => '2015-06-05', 'has_map_policy' => false]);
     $product->save();
     $site->products()->attach([$product->id]);
     $keys = $site->products->map(function ($item, $key) {
         return $item->getKey();
     });
     $this->assertEquals(['/sites/1/', '/products/', '/sites/1/products/'], $wps->getRequestUris());
     $this->assertEquals([null, '{"supplier_product_id":"123456","variableproduct_id":13,"brand_id":1,"country_id":3,"name":"test product","list_price":"1.73","estimated_weight":"25.676","sku":"12-1234","upc":"123456789123","description":"Here is a description of product 1","published_at":"2015-06-05 00:00:00","has_map_policy":false}', '[{"id":3}]'], $wps->getRequestBodies());
     $this->assertContainsOnlyInstancesOf(Wps\Models\Product::class, $site->products);
     $this->assertTrue($keys->contains(3));
 }
Пример #2
0
 /**
  * @test
  */
 public function it_gets_the_tags_from_a_product()
 {
     $wps = new Sdk();
     $wps->addMockResults([new Response(200, [], json_encode($wps->productResponse(1))), new Response(200, [], json_encode($wps->tagsResponse()))]);
     $product = $wps->product()->find(1);
     $this->assertContainsOnlyInstancesOf(Wps\Models\Tag::class, $product->tags);
     $this->assertEquals(['/products/1/', '/products/1/tags/'], $wps->getRequestUris());
 }