Exemplo n.º 1
0
 /**
  * @test
  */
 public function it_gets_a_block_collection()
 {
     $wps = new Sdk();
     $wps->addMockResults([new Response(200, [], json_encode($wps->blocksResponse()))]);
     $blocks = $wps->block()->all();
     $this->assertEquals(['/blocks/'], $wps->getRequestUris());
     $this->assertInstanceOf(Illuminate\Support\Collection::class, $blocks);
     $this->assertContainsOnlyInstancesOf(Block::class, $blocks);
     $this->assertEquals([1, 2], [$blocks[0]->id, $blocks[1]->id]);
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function it_syncs_blocks_for_a_product_on_a_site()
 {
     $wps = new Sdk();
     $response = $wps->blocksResponse();
     $response['data'] = array_reverse($response['data']);
     $wps->addMockResults([new Response(200, [], json_encode($wps->siteResponse(1))), new Response(200, [], json_encode($wps->productResponse(1))), new Response(200, [], json_encode($response))]);
     $site = $wps->site()->find(1);
     $product = $site->products(1);
     $product->blocks()->sync([2, 1]);
     $keys = $product->blocks->map(function ($item, $key) {
         return $item->getKey();
     });
     $this->assertEquals(['/sites/1/', '/products/1/', '/sites/1/products/1/blocks/'], $wps->getRequestUris());
     $this->assertEquals([null, null, '[{"id":2},{"id":1}]'], $wps->getRequestBodies());
     $this->assertContainsOnlyInstancesOf(Wps\Models\Block::class, $product->blocks);
     $this->assertEquals([2, 1], $keys->toArray());
 }