Skip to content

Commit 0ec5d82

Browse files
authored
Merge pull request #178 from lwilkowskeBC/WEB-299
WEB-299: Web Content API Client Endpoints
2 parents 72322cf + d6d3eb8 commit 0ec5d82

4 files changed

Lines changed: 162 additions & 1 deletion

File tree

src/Bigcommerce/Api/Client.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,4 +1551,60 @@ public static function deleteProductImage($productId, $imageId)
15511551
{
15521552
return self::deleteResource('/products/' . $productId . '/images/' . $imageId);
15531553
}
1554+
1555+
/**
1556+
* Get all content pages
1557+
*
1558+
* @return mixed
1559+
*/
1560+
public static function getPages()
1561+
{
1562+
return self::getCollection('/pages', 'Page');
1563+
}
1564+
1565+
/**
1566+
* Get single content pages
1567+
*
1568+
* @param int $pageId
1569+
* @return mixed
1570+
*/
1571+
public static function getPage($pageId)
1572+
{
1573+
return self::getResource('/pages/' . $pageId, 'Page');
1574+
}
1575+
1576+
/**
1577+
* Create a new content pages
1578+
*
1579+
* @param $object
1580+
* @return mixed
1581+
*/
1582+
public static function createPage($object)
1583+
{
1584+
return self::createResource('/pages', $object);
1585+
}
1586+
1587+
/**
1588+
* Update an existing content page
1589+
*
1590+
* @param int $pageId
1591+
* @param $object
1592+
* @return mixed
1593+
*/
1594+
public static function updatePage($pageId, $object)
1595+
{
1596+
return self::updateResource('/pages/' . $pageId, $object);
1597+
}
1598+
1599+
/**
1600+
* Delete an existing content page
1601+
*
1602+
* @param int $pageId
1603+
* @return mixed
1604+
*/
1605+
public static function deletePage($pageId)
1606+
{
1607+
return self::deleteResource('/pages/' . $pageId);
1608+
}
1609+
15541610
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Bigcommerce\Api\Resources;
4+
5+
use Bigcommerce\Api\Resource;
6+
use Bigcommerce\Api\Client;
7+
8+
class Page extends Resource
9+
{
10+
protected $ignoreOnCreate = array(
11+
'id',
12+
);
13+
14+
protected $ignoreOnUpdate = array(
15+
'id',
16+
);
17+
18+
public function create()
19+
{
20+
return Client::createPage($this->getCreateFields());
21+
}
22+
23+
public function update()
24+
{
25+
return Client::updatePage($this->id, $this->getUpdateFields());
26+
}
27+
28+
public function delete()
29+
{
30+
return Client::deletePage($this->id);
31+
}
32+
33+
public function getAll()
34+
{
35+
return Client::getPages();
36+
}
37+
38+
public function get()
39+
{
40+
return Client::getPage($this->id);
41+
}
42+
}

test/Unit/Api/ClientTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public function collections()
292292
array('products/skus', 'getSkus', 'Sku'),
293293
array('requestlogs', 'getRequestLogs', 'RequestLog'),
294294
array('currencies', 'getCurrencies', 'Currency'),
295+
array('pages', 'getPages', 'Page'),
295296
);
296297
}
297298

@@ -317,7 +318,7 @@ public function testGettingASpecificResourceReturnsACollectionOfThatResource($pa
317318
*/
318319
public function testGettingTheCountOfACollectionReturnsThatCollectionsCount($path, $fnName, $class)
319320
{
320-
if (in_array($path, array('order_statuses', 'requestlogs'))) {
321+
if (in_array($path, array('order_statuses', 'requestlogs', 'pages'))) {
321322
//$this->markTestSkipped(sprintf('The API does not currently support getting the count of %s', $path));
322323
return;
323324
}
@@ -345,6 +346,7 @@ public function resources()
345346
array('optionsets', '%sOptionSet', 'OptionSet'),
346347
array('coupons', '%sCoupon', 'Coupon'),
347348
array('currencies', '%sCurrency', 'Currency'),
349+
array('pages', '%sPage', 'Page'),
348350
);
349351
}
350352

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace Bigcommerce\Test\Unit\Api\Resources;
3+
4+
use Bigcommerce\Api\Resources\Page;
5+
use Bigcommerce\Api\Client;
6+
7+
class PageTest extends ResourceTestBase
8+
{
9+
public function testGetAllPassesThroughToConnection()
10+
{
11+
$page = new Page();
12+
13+
$this->connection->expects($this->once())
14+
->method('get')
15+
->with($this->basePath . '/pages');
16+
17+
$page->getAll();
18+
}
19+
20+
public function testGetPassesThroughToConnection()
21+
{
22+
$page = new Page((object)(array('id' => 1)));
23+
24+
$this->connection->expects($this->once())
25+
->method('get')
26+
->with($this->basePath . '/pages/1');
27+
28+
$page->get();
29+
}
30+
31+
public function testCreatePassesThroughToConnection()
32+
{
33+
$page = new Page();
34+
$this->connection->expects($this->once())
35+
->method('post')
36+
->with($this->basePath . '/pages', $page->getCreateFields());
37+
38+
$page->create();
39+
}
40+
41+
public function testUpdatePassesThroughToConnection()
42+
{
43+
$page = new Page((object)(array('id' => 1)));
44+
$this->connection->expects($this->once())
45+
->method('put')
46+
->with($this->basePath . '/pages/1', $page->getUpdateFields());
47+
48+
$page->update();
49+
}
50+
51+
public function testDeletePassesThroughToConnection()
52+
{
53+
$page = new Page((object)(array('id' => 1)));
54+
$this->connection->expects($this->once())
55+
->method('delete')
56+
->with($this->basePath . '/pages/1');
57+
58+
$page->delete();
59+
}
60+
61+
}

0 commit comments

Comments
 (0)