forked from mautic/api-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#69 from escopecz/api-improvements
API updates for 3060
- Loading branch information
Showing
8 changed files
with
325 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* @package Mautic | ||
* @copyright 2014 Mautic, NP. All rights reserved. | ||
* @author Mautic | ||
* @link http://mautic.org | ||
* @license MIT http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace Mautic\Api; | ||
|
||
/** | ||
* Devices Context | ||
*/ | ||
class Devices extends Api | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $endpoint = 'devices'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* @package Mautic | ||
* @copyright 2014 Mautic, NP. All rights reserved. | ||
* @author Mautic | ||
* @link http://mautic.org | ||
* @license MIT http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace Mautic\Tests\Api; | ||
|
||
class DevicesTest extends MauticApiTestCase | ||
{ | ||
protected $testPayload = array( | ||
'device' => 'desktop', | ||
'deviceOsName' => 'Ubuntu', | ||
'deviceOsShortName' => 'UBT', | ||
'deviceOsPlatform' => 'x64', | ||
); | ||
|
||
protected $context = 'devices'; | ||
|
||
protected $itemName = 'device'; | ||
|
||
protected $skipPayloadAssertion = array('lead'); | ||
|
||
public function setUp() { | ||
// Create a contact for test | ||
$apiContext = $this->getContext('contacts'); | ||
$response = $apiContext->create(array('firstname' => 'Device API test')); | ||
$this->assertErrors($response); | ||
$this->testPayload['lead'] = $response['contact']['id']; | ||
} | ||
|
||
public function tearDown() { | ||
// Delete a contact from test | ||
$apiContext = $this->getContext('contacts'); | ||
$response = $apiContext->delete($this->testPayload['lead']); | ||
$this->assertErrors($response); | ||
} | ||
|
||
public function testGetList() | ||
{ | ||
$apiContext = $this->getContext($this->context); | ||
$response = $apiContext->getList(); | ||
$this->assertErrors($response); | ||
$this->assertTrue(isset($response[$this->context])); | ||
} | ||
|
||
public function testCreateGetAndDelete() | ||
{ | ||
$apiContext = $this->getContext($this->context); | ||
|
||
$response = $apiContext->create($this->testPayload); | ||
$this->assertPayload($response); | ||
|
||
// Test get contact notes endpoint | ||
$contactContext = $this->getContext('contacts'); | ||
$responseDevices = $contactContext->getContactDevices($this->testPayload['lead']); | ||
$this->assertErrors($responseDevices); | ||
$this->assertEquals($responseDevices['total'], 1); | ||
$this->assertFalse(empty($responseDevices['devices'])); | ||
|
||
$response = $apiContext->get($response[$this->itemName]['id']); | ||
$this->assertPayload($response); | ||
|
||
$response = $apiContext->delete($response[$this->itemName]['id']); | ||
$this->assertErrors($response); | ||
} | ||
|
||
public function testEditPatch() | ||
{ | ||
$apiContext = $this->getContext($this->context); | ||
$response = $apiContext->edit(10000, $this->testPayload); | ||
|
||
//there should be an error as the form shouldn't exist | ||
$this->assertTrue(isset($response['error']), $response['error']['message']); | ||
|
||
$response = $apiContext->create($this->testPayload); | ||
$this->assertErrors($response); | ||
|
||
$updatePayload = array( | ||
'deviceOsName' => 'Edubuntu', | ||
); | ||
|
||
$response = $apiContext->edit($response[$this->itemName]['id'], $updatePayload); | ||
$this->assertPayload($response, $updatePayload); | ||
|
||
//now delete the form | ||
$response = $apiContext->delete($response[$this->itemName]['id']); | ||
$this->assertErrors($response); | ||
} | ||
|
||
public function testEditPut() | ||
{ | ||
$apiContext = $this->getContext($this->context); | ||
$response = $apiContext->edit(10000, $this->testPayload, true); | ||
$this->assertPayload($response); | ||
|
||
//now delete the form | ||
$response = $apiContext->delete($response[$this->itemName]['id']); | ||
$this->assertErrors($response); | ||
} | ||
} |
Oops, something went wrong.