Skip to content

Commit

Permalink
Merge pull request #165 from escopecz/category-assignment-test
Browse files Browse the repository at this point in the history
A test for category assignment added
  • Loading branch information
escopecz authored Oct 24, 2018
2 parents 56fb0da + d700774 commit 71ca3d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/Api/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class AssetsTest extends MauticApiTestCase
{
protected $skipPayloadAssertion = array('file');

public function setUp() {
public function setUp()
{
$this->api = $this->getContext('assets');
$this->testPayload = array(
'title' => 'Mautic Logo sent as a API request',
Expand Down
38 changes: 37 additions & 1 deletion tests/Api/CategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,43 @@ public function testGetListOfSpecificIds()

public function testCreateGetAndDelete()
{
$this->standardTestCreateGetAndDelete();
// Create category
$response = $this->api->create($this->testPayload);
$this->assertErrors($response);
$this->assertPayload($response, $this->testPayload);
$categoryId = $response[$this->api->itemName()]['id'];

// GET category
$response = $this->api->get($categoryId);
$this->assertErrors($response);
$this->assertPayload($response, $this->testPayload);

// Add an asset to this category
$assetApi = $this->getContext('assets');
$assetPayload = array(
'title' => 'Mautic Logo sent as a API request',
'storageLocation' => 'remote',
'file' => 'https://www.mautic.org/media/logos/logo/Mautic_Logo_DB.pdf',
'category' => $categoryId,
);

// Create Asset
$assetResponse = $assetApi->create($assetPayload);
$assetCategory = $assetResponse[$assetApi->itemName()]['category'];
$this->assertEquals($categoryId, $assetCategory['id']);
$this->assertErrors($assetPayload);

// Delete asset
$response = $assetApi->delete($assetResponse[$assetApi->itemName()]['id']);
$this->assertErrors($response);

// Delete category
$response = $this->api->delete($categoryId);
$this->assertErrors($response);

// Expect an error when assigning a non existing category when creating a new asset
$assetResponse = $assetApi->create($assetPayload);
$this->assertContains("Category $categoryId does not exist", $assetResponse['errors'][0]['message']);
}

public function testEditPatch()
Expand Down

0 comments on commit 71ca3d2

Please sign in to comment.