Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ini name="error_log" value="/dev/null"/>
<env name="EMAIL" value="email"/>
<env name="PASSWORD" value="password"/>
<env name="DOMAIN" value="http://acc-pms.multipost.com/"/>
<env name="DOMAIN" value="domain"/>
</php>
<testsuite name="Unit Tests">
<directory suffix='.php'>tests/</directory>
Expand Down
93 changes: 91 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,63 @@ protected function request($method = null, $path = null, $body = null)
if ($response_code == 200) {
return json_decode($response->getBody(), true);
} else {
return $response_code;
return $response->getBody()->getContents();
}
}

//Clients
public function getClients($company_uuid)
{
return $this->request(Client::HTTP_GET, '/'.$company_uuid.'/clients');
}

public function createClient($company_uuid, $data)
{
return $this->request(Client::HTTP_POST, '/'.$company_uuid.'/clients', $data);
}

//Companies
public function getCompanies()
{
return $this->request(Client::HTTP_GET, '/company');
}

public function createCompany($data)
{
return $this->request(Client::HTTP_POST, '/company', $data);
}

public function getCompany($company_uuid)
{
return $this->request(Client::HTTP_GET, '/company/'.$company_uuid);
}

public function deleteCompany($company_uuid)
{
return $this->request(Client::HTTP_DELETE, '/company/'.$company_uuid);
}

public function listUsers($company_uuid)
{
return $this->request(Client::HTTP_GET, '/'.$company_uuid.'/users');
}

public function addUser($company_uuid, array $users)
{
return $this->request(Client::HTTP_POST, '/'.$company_uuid.'/users', $users);
}

//Documents
public function createDocument($company_uuid, $data)
{
return $this->request(Client::HTTP_POST, '/'.$company_uuid.'/document', $data);
}

public function getDocument($company_uuid, $document_uuid)
{
return $this->request(Client::HTTP_GET, '/'.$company_uuid.'/document/'.$document_uuid);
}

//Envelopes
public function getEnvelopes($company_uuid)
{
Expand Down Expand Up @@ -164,7 +211,38 @@ public function createEnvelope($company_uuid, $name, $description, $envelope_det
];
$envelope = array_merge($envelope, $envelope_design);
}
return $this->request(Client::HTTP_POST, '/' . $company_uuid . '/envelope', $envelope);
return $this->request(Client::HTTP_POST, '/' . $company_id . '/envelope', $envelope);
}

public function getEnvelope($company_uuid, $envelope_uuid)
{
return $this->request(Client::HTTP_GET, '/'.$company_uuid.'/envelope/'.$envelope_uuid);
}

public function deleteEnvelope($company_uuid, $envelope_uuid)
{
return $this->request(Client::HTTP_DELETE, '/'.$company_uuid.'/envelope/'.$envelope_uuid);
}

public function orderEnvelope($company_uuid, $envelope_uuid, $quantity)
{
return $this->request(Client::HTTP_POST, '/'.$company_uuid.'/envelope/'.$envelope_uuid.'/order', ['quantity' => $quantity]);
}

public function getEnvelopeOrder($company_uuid, $order_uuid)
{
return $this->request(Client::HTTP_POST, '/'.$company_uuid.'/envelope/order/'.$order_uuid.'');
}

//Mailbox
public function getMailboxes($company_uuid)
{
return $this->request(Client::HTTP_GET, '/'.$company_uuid.'/mailbox');
}

public function getMailbox($company_uuid, $mailbox_uuid)
{
return $this->request(Client::HTTP_GET, '/'.$company_uuid.'/mailbox/'.$mailbox_uuid);
}

//Paper
Expand Down Expand Up @@ -194,6 +272,17 @@ public function cancelPrintOrder($company_uuid, $print_order_uuid)
return $this->request(Client::HTTP_DELETE, '/'.$company_uuid.'/print/'.$print_order_uuid);
}

//Print processing types
public function getPrintProcessingTypes()
{
return $this->request(Client::HTTP_GET, '/processing');
}

public function getPrintProcessingType($print_processing_uuid)
{
return $this->request(Client::HTTP_GET, '/processing/'.$print_processing_uuid);
}

//Shipping
public function getShippingProducts()
{
Expand Down
68 changes: 68 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare (strict_types = 1);
use BureauPartners\MultiPost\Client;
use PHPUnit\Framework\TestCase;

class ClientTest extends TestCase
{
protected $clientApi;
protected $client;
protected $testCompany;

public function setUp(): void
{
$this->clientApi = new Client(getenv('EMAIL'), getenv('PASSWORD'), getenv('DOMAIN'));
$this->testCompany = $this->clientApi->createCompany([
'name' => 'testCompany',
'data_retention_period' => 5
]);

$this->client = $this->clientApi->createClient($this->testCompany['uuid'], [
'clientnumber' => 2454987,
'name' => 'testClient',
'initials' => 't',
'firstname' => 'test',
'insertion' => 'ewf',
'lastname' => 'van tester',
'street' => 'testlaan',
'housenumber' => '22',
'housenumberaddon' => 'a',
'postalcode' => '3311YU',
'city' => 'Dordrecht',
'country' => 'Nederland',
'mobile' => '061785245856',
'emailaddress' => 'test@test.nl',
'preferred_channel' => 'email',
]);
}

public function testCanUserSeeClients()
{
$this->assertCount(1, $this->clientApi->getClients($this->testCompany['uuid']));
}

public function testCanUserCreateClients()
{
$result = $this->clientApi->createClient($this->testCompany['uuid'], [
'clientnumber' => 2454987,
'name' => 'testClient2',
'initials' => 't2',
'firstname' => 'test2',
'insertion' => 'ewf2',
'lastname' => 'van tester2',
'street' => 'testlaan2',
'housenumber' => '222',
'housenumberaddon' => 'a2',
'postalcode' => '3311YU',
'city' => 'Dordrecht2',
'country' => 'Nederland2',
'mobile' => '0617852458562',
'emailaddress' => 'test@test.nl2',
'preferred_channel' => 'email',
]);

$this->assertEquals('testClient2', $result['name']);
$this->assertCount(2, $this->clientApi->getClients($this->testCompany['uuid']));
}
}
51 changes: 50 additions & 1 deletion tests/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,63 @@
class CompanyTest extends TestCase
{
protected $client;
protected $countCompanies;
protected $testCompany;

public function setUp(): void
{
$this->client = new Client(getenv('EMAIL'), getenv('PASSWORD'), getenv('DOMAIN'));
$this->testCompany = $this->client->createCompany([
'name' => getenv('testCompanyName'),
'data_retention_period' => 5
]);
$this->countCompanies = count($this->client->getCompanies());
}

public function testCanUserSeeCompanies()
{
$this->assertCount(2, $this->client->getCompanies());
$this->assertCount($this->countCompanies, $this->client->getCompanies());
}

public function testCanUserCreateCompany()
{
$response = $this->client->createCompany([
'name' => getenv('testCompanyName').'2',
'parent_company' => $this->testCompany['uuid'],
'data_retention_period' => 5
]);

$checkCompanies = ($this->countCompanies + 1);

$this->assertCount($checkCompanies, $this->client->getCompanies());
}

public function testCanUserSeeCompany()
{
$company = $this->client->getCompany($this->testCompany['uuid']);

$this->assertEquals('testCompany', $company['name']);
}

public function testCanUserDeleteCompany()
{
$this->client->deleteCompany($this->testCompany['uuid']);

$checkCompanies = ($this->countCompanies - 1);

$this->assertCount($checkCompanies, $this->client->getCompanies());
}

public function testCanUserSeeUsersInCompany()
{
$this->assertCount(1, $this->client->listUsers($this->testCompany['uuid']));
}

public function testCanUserAddUser()
{
$result = $this->client->addUser($this->testCompany['uuid'], [
'users' => [0 => '78e6b040-799c-11ea-abf1-8db850624fbe']
]);
$this->assertCount(2, $this->client->listUsers($this->testCompany['uuid']));
}
}
44 changes: 44 additions & 0 deletions tests/DocumentTest.php

Large diffs are not rendered by default.

47 changes: 46 additions & 1 deletion tests/EnvelopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,59 @@
class EnvelopeTest extends TestCase
{
protected $client;
protected $testCompany;
protected $testEnvelope;
protected $testOrder;

public function setUp(): void
{
$this->client = new Client(getenv('EMAIL'), getenv('PASSWORD'), getenv('DOMAIN'));
$this->testCompany = $this->client->createCompany([
'name' => 'testCompany',
'data_retention_period' => 5
]);
$this->testEnvelope = $this->client->createEnvelope($this->testCompany['uuid'], 'test envelope', 'test description');
$this->testOrder = $this->client->orderEnvelope($this->testCompany['uuid'], $this->testEnvelope['uuid'], 100);
}

public function testCanUserGetEnvelopes()
{
$this->assertCount(1, $this->client->getEnvelopes('test'));
$result = $this->client->getEnvelopes($this->testCompany['uuid']);

$this->assertCount(1, $result);
}

public function testCanUserGetEnvelope()
{
$result = $this->client->getEnvelope($this->testCompany['uuid'], $this->testEnvelope['uuid']);
$this->assertEquals('test envelope', $result['name']);
}

public function testCanUserCreateEnvelope()
{
$result = $this->client->createEnvelope($this->testCompany['uuid'], 'test envelope 2', 'test description 2');

$this->assertEquals('test envelope 2', $result['name']);
}

public function testCanUserDeleteEnvelope()
{
$result = $this->client->deleteEnvelope($this->testCompany['uuid'], $this->testEnvelope['uuid']);

$this->assertEquals(true, $result['success']);
}

public function testCanUserOrderEnvelopes()
{
$result = $this->client->orderEnvelope($this->testCompany['uuid'], $this->testEnvelope['uuid'], 100);

$this->assertEquals(100, $result['quantity']);
}

public function testCanUserSeeOrderEnvelopes()
{
$result = $this->client->getEnvelopeOrder($this->testCompany['uuid'], $this->testOrder['uuid']);

$this->assertEquals(100, $result['amount']);
}
}
28 changes: 28 additions & 0 deletions tests/MailboxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare (strict_types = 1);
use BureauPartners\MultiPost\Client;
use PHPUnit\Framework\TestCase;

class MailboxTest extends TestCase
{
protected $client;

public function setUp(): void
{
$this->client = new Client(getenv('EMAIL'), getenv('PASSWORD'), getenv('DOMAIN'));
}

public function testCanUserSeeMailboxes()
{
$result = $this->client->getMailboxes('e23296b0-c4f1-11ea-9834-295ab019a7f7');
$this->assertCount(1, $result);
}

public function testCanUserSeeMailbox()
{
$result = $this->client->getMailbox('e23296b0-c4f1-11ea-9834-295ab019a7f7', 'efwwfewefefewwfewef');
$this->assertEquals('test_box', $result['name']);
}

}
32 changes: 28 additions & 4 deletions tests/PrintOrderTest.php

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions tests/PrintProcessingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare (strict_types = 1);
use BureauPartners\MultiPost\Client;
use PHPUnit\Framework\TestCase;

class PrintProcessingTest extends TestCase
{
protected $client;

public function setUp(): void
{
$this->client = new Client(getenv('EMAIL'), getenv('PASSWORD'), getenv('DOMAIN'));
}

public function testCanUserSeePrintProcessingTypes()
{
$result = $this->client->getPrintProcessingTypes();
$this->assertCount(16, $result);
}

public function testCanUserSeePrintProcessingType()
{
$result = $this->client->getPrintProcessingType('78d2de80-799c-11ea-94e3-a1314fbacc26');
$this->assertEquals('Scoring rule', $result['name']);
}
}