Skip to content

Commit 71ca3d2

Browse files
authored
Merge pull request #165 from escopecz/category-assignment-test
A test for category assignment added
2 parents 56fb0da + d700774 commit 71ca3d2

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

tests/Api/AssetsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class AssetsTest extends MauticApiTestCase
1313
{
1414
protected $skipPayloadAssertion = array('file');
1515

16-
public function setUp() {
16+
public function setUp()
17+
{
1718
$this->api = $this->getContext('assets');
1819
$this->testPayload = array(
1920
'title' => 'Mautic Logo sent as a API request',

tests/Api/CategoriesTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,43 @@ public function testGetListOfSpecificIds()
3131

3232
public function testCreateGetAndDelete()
3333
{
34-
$this->standardTestCreateGetAndDelete();
34+
// Create category
35+
$response = $this->api->create($this->testPayload);
36+
$this->assertErrors($response);
37+
$this->assertPayload($response, $this->testPayload);
38+
$categoryId = $response[$this->api->itemName()]['id'];
39+
40+
// GET category
41+
$response = $this->api->get($categoryId);
42+
$this->assertErrors($response);
43+
$this->assertPayload($response, $this->testPayload);
44+
45+
// Add an asset to this category
46+
$assetApi = $this->getContext('assets');
47+
$assetPayload = array(
48+
'title' => 'Mautic Logo sent as a API request',
49+
'storageLocation' => 'remote',
50+
'file' => 'https://www.mautic.org/media/logos/logo/Mautic_Logo_DB.pdf',
51+
'category' => $categoryId,
52+
);
53+
54+
// Create Asset
55+
$assetResponse = $assetApi->create($assetPayload);
56+
$assetCategory = $assetResponse[$assetApi->itemName()]['category'];
57+
$this->assertEquals($categoryId, $assetCategory['id']);
58+
$this->assertErrors($assetPayload);
59+
60+
// Delete asset
61+
$response = $assetApi->delete($assetResponse[$assetApi->itemName()]['id']);
62+
$this->assertErrors($response);
63+
64+
// Delete category
65+
$response = $this->api->delete($categoryId);
66+
$this->assertErrors($response);
67+
68+
// Expect an error when assigning a non existing category when creating a new asset
69+
$assetResponse = $assetApi->create($assetPayload);
70+
$this->assertContains("Category $categoryId does not exist", $assetResponse['errors'][0]['message']);
3571
}
3672

3773
public function testEditPatch()

0 commit comments

Comments
 (0)