|
@@ 16-37 (lines=22) @@
|
| 13 |
|
* |
| 14 |
|
* @test |
| 15 |
|
*/ |
| 16 |
|
public function getProduct_AllRequiredFieldsPresent_ValidationPasses_ProductIsReturned() |
| 17 |
|
{ |
| 18 |
|
// arrange |
| 19 |
|
$contentMapperMock = $this->createMock(ContentMapper::class); |
| 20 |
|
$contentMapperMock->method("getContent")->willReturn(new Content("Summary", "...")); |
| 21 |
|
|
| 22 |
|
/** @var ContentMapper $contentMapperMock */ |
| 23 |
|
$productMapper = new ProductMapper($contentMapperMock); |
| 24 |
|
|
| 25 |
|
$productData = array( |
| 26 |
|
"sku" => "a-product", |
| 27 |
|
"slug" => "A-Product", |
| 28 |
|
"title" => "Super fancy product", |
| 29 |
|
"summary" => "A super fancy product", |
| 30 |
|
); |
| 31 |
|
|
| 32 |
|
// act |
| 33 |
|
$product = $productMapper->getProduct($productData); |
| 34 |
|
|
| 35 |
|
// assert |
| 36 |
|
$this->assertNotNull($product, "getProduct() should have returned a product"); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
/** |
| 40 |
|
* If given product data is missing one of the mandatory fields and exception should be thrown. |
|
@@ 68-86 (lines=19) @@
|
| 65 |
|
* @test |
| 66 |
|
* @expectedException Wambo\Catalog\Error\ProductException |
| 67 |
|
*/ |
| 68 |
|
public function getProduct_AllRequiredFieldsPresent_SkuValidationFails_ProductIsReturned() |
| 69 |
|
{ |
| 70 |
|
// arrange |
| 71 |
|
$contentMapperMock = $this->createMock(ContentMapper::class); |
| 72 |
|
$contentMapperMock->method("getContent")->willReturn(new Content("Summary", "...")); |
| 73 |
|
|
| 74 |
|
/** @var ContentMapper $contentMapperMock */ |
| 75 |
|
$productMapper = new ProductMapper($contentMapperMock); |
| 76 |
|
|
| 77 |
|
$productData = array( |
| 78 |
|
"sku" => "a", |
| 79 |
|
"slug" => "A-Product", |
| 80 |
|
"title" => "Super fancy product", |
| 81 |
|
"summary" => "A super fancy product", |
| 82 |
|
); |
| 83 |
|
|
| 84 |
|
// act |
| 85 |
|
$productMapper->getProduct($productData); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
/** |
| 89 |
|
* If the Slug validation fails and exception should be thrown |
|
@@ 94-112 (lines=19) @@
|
| 91 |
|
* @test |
| 92 |
|
* @expectedException Wambo\Catalog\Error\ProductException |
| 93 |
|
*/ |
| 94 |
|
public function getProduct_AllRequiredFieldsPresent_SlugValidationFails_ProductIsReturned() |
| 95 |
|
{ |
| 96 |
|
// arrange |
| 97 |
|
$contentMapperMock = $this->createMock(ContentMapper::class); |
| 98 |
|
$contentMapperMock->method("getContent")->willReturn(new Content("A super fancy product", "...")); |
| 99 |
|
|
| 100 |
|
/** @var ContentMapper $contentMapperMock */ |
| 101 |
|
$productMapper = new ProductMapper($contentMapperMock); |
| 102 |
|
|
| 103 |
|
$productData = array( |
| 104 |
|
"sku" => "a-product", |
| 105 |
|
"slug" => "A/Product", |
| 106 |
|
"title" => "Super fancy product", |
| 107 |
|
"summary" => "A super fancy product", |
| 108 |
|
); |
| 109 |
|
|
| 110 |
|
// act |
| 111 |
|
$productMapper->getProduct($productData); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
/** |
| 115 |
|
* Get product data with one or more missing attributes. |