-
Notifications
You must be signed in to change notification settings - Fork 56
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 #64 from akeneo/API-305_API-306_API-307
API-305_API-306_API-307: Add create association type, upsert association type and upsert list of association types
- Loading branch information
Showing
6 changed files
with
377 additions
and
1 deletion.
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
77 changes: 77 additions & 0 deletions
77
tests/v1_8/Api/AssociationType/CreateAssociationTypeApiIntegration.php
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,77 @@ | ||
<?php | ||
|
||
namespace Akeneo\Pim\tests\v1_8\Api\AssociationType; | ||
|
||
use Akeneo\Pim\Exception\UnprocessableEntityHttpException; | ||
use Akeneo\Pim\tests\Common\Api\ApiTestCase; | ||
|
||
class CreateAssociationTypeApiIntegration extends ApiTestCase | ||
{ | ||
public function testCreate() | ||
{ | ||
$api = $this->createClient()->getAssociationTypeApi(); | ||
$response = $api->create( | ||
'NEW_SELL', | ||
[ | ||
'labels' => [ | ||
'en_US' => 'New sell', | ||
'fr_FR' => 'Nouvelle vente', | ||
], | ||
] | ||
); | ||
|
||
$this->assertSame(201, $response); | ||
|
||
$associationType = $api->get('NEW_SELL'); | ||
$this->assertSameContent( | ||
[ | ||
'code' => 'NEW_SELL', | ||
'labels' => [ | ||
'en_US' => 'New sell', | ||
'fr_FR' => 'Nouvelle vente', | ||
], | ||
], | ||
$associationType | ||
); | ||
} | ||
|
||
public function testCreateAnExistingAssociationType() | ||
{ | ||
$api = $this->createClient()->getAssociationTypeApi(); | ||
|
||
try { | ||
$api->create( | ||
'UPSELL', | ||
[ | ||
'labels' => [ | ||
'en_US' => 'Upsell', | ||
], | ||
] | ||
); | ||
} catch (UnprocessableEntityHttpException $exception) { | ||
$this->assertSame( | ||
[ | ||
[ | ||
'property' => 'code', | ||
'message' => 'This value is already used.', | ||
], | ||
], | ||
$exception->getResponseErrors() | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @expectedException \Akeneo\Pim\Exception\UnprocessableEntityHttpException | ||
*/ | ||
public function testCreateAnInvalidAssociationType() | ||
{ | ||
$api = $this->createClient()->getAssociationTypeApi(); | ||
$api->create( | ||
'fail', | ||
[ | ||
'labels' => 'Upsell', | ||
] | ||
); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
tests/v1_8/Api/AssociationType/UpsertAssociationTypeApiIntegration.php
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,90 @@ | ||
<?php | ||
|
||
namespace Akeneo\Pim\tests\v1_8\Api\AssociationType; | ||
|
||
use Akeneo\Pim\tests\Common\Api\ApiTestCase; | ||
|
||
class UpsertAssociationTypeApiIntegration extends ApiTestCase | ||
{ | ||
public function testUpsertDoingUpdate() | ||
{ | ||
$api = $this->createClient()->getAssociationTypeApi(); | ||
|
||
$response = $api->upsert( | ||
'X_SELL', | ||
[ | ||
'labels' => [ | ||
'en_US' => 'Cross sell', | ||
'fr_FR' => 'Vente croisée', | ||
], | ||
] | ||
); | ||
|
||
$this->assertSame(204, $response); | ||
|
||
$associationType = $api->get('X_SELL'); | ||
$this->assertSameContent( | ||
[ | ||
'code' => 'X_SELL', | ||
'labels' => [ | ||
'en_US' => 'Cross sell', | ||
'fr_FR' => 'Vente croisée', | ||
], | ||
], | ||
$associationType | ||
); | ||
} | ||
|
||
public function testUpsertDoingCreate() | ||
{ | ||
$api = $this->createClient()->getAssociationTypeApi(); | ||
$response = $api->upsert( | ||
'NEW_SELL', | ||
[ | ||
'labels' => [ | ||
'en_US' => 'New sell', | ||
'fr_FR' => 'Nouvelle vente', | ||
], | ||
] | ||
); | ||
|
||
$this->assertSame(201, $response); | ||
|
||
$associationType = $api->get('NEW_SELL'); | ||
$this->assertSameContent( | ||
[ | ||
'code' => 'NEW_SELL', | ||
'labels' => [ | ||
'en_US' => 'New sell', | ||
'fr_FR' => 'Nouvelle vente', | ||
], | ||
], | ||
$associationType | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \Akeneo\Pim\Exception\UnprocessableEntityHttpException | ||
*/ | ||
public function testUpsertWrongDataTypeFail() | ||
{ | ||
$api = $this->createClient()->getAssociationTypeApi(); | ||
$api->upsert( | ||
'NEW_SELL', | ||
[ | ||
'labels' => [ | ||
'en_US' => ['New sell'], | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \Akeneo\Pim\Exception\UnprocessableEntityHttpException | ||
*/ | ||
public function testUpsertInvalidCodeFail() | ||
{ | ||
$api = $this->createClient()->getCategoryApi(); | ||
$api->upsert('invalid code !'); | ||
} | ||
} |
Oops, something went wrong.