forked from Thijzer/csv-validation-header.wip
-
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.
- Loading branch information
Showing
7 changed files
with
271 additions
and
77 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
42 changes: 42 additions & 0 deletions
42
tests/Component/AttributeFormatter/BooleanAttributeFormatterTest.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,42 @@ | ||
<?php | ||
|
||
namespace Tests\Misery\Component\AttributeFormatter; | ||
|
||
use Induxx\Twig\Extension\TranslationBundleExtension; | ||
use Misery\Component\AttributeFormatter\BooleanAttributeFormatter; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
class BooleanAttributeFormatterTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function test_it_should_boolean_type_a_value(): void | ||
{ | ||
$format = new BooleanAttributeFormatter(); | ||
|
||
$context = [ | ||
'label' => [ | ||
'Y' => 'YES', | ||
'N' => 'NO', | ||
], | ||
'current-attribute-type' => 'pim_catalog_boolean', | ||
]; | ||
|
||
$this->assertSame($format->format(true, $context), 'YES'); | ||
$this->assertSame($format->format(false, $context), 'NO'); | ||
|
||
$this->assertTrue($format->requires($context)); | ||
$this->assertTrue($format->supports('pim_catalog_boolean')); | ||
|
||
$context = [ | ||
'label' => [ | ||
'Y' => 'Ja', | ||
'N' => 'Nee', | ||
], | ||
'current-attribute-type' => 'pim_catalog_boolean', | ||
]; | ||
|
||
$this->assertSame($format->format(true, $context), 'Ja'); | ||
$this->assertSame($format->format(false, $context), 'Nee'); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/Component/AttributeFormatter/MetricAttributeFormatterTest.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,56 @@ | ||
<?php | ||
|
||
namespace Tests\Misery\Component\AttributeFormatter; | ||
|
||
use Misery\Component\AttributeFormatter\AttributeValueFormatter; | ||
use Misery\Component\AttributeFormatter\MetricAttributeFormatter; | ||
use Misery\Component\AttributeFormatter\MultiValuePresenterFormatter; | ||
use Misery\Component\AttributeFormatter\PropertyFormatterRegistry; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
class MetricAttributeFormatterTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function test_it_should_metric_type_a_value(): void | ||
{ | ||
$registry = new PropertyFormatterRegistry(); | ||
$registry->add(new MetricAttributeFormatter()); | ||
$registry->add(new MultiValuePresenterFormatter()); | ||
$attributeValueFormatter = new AttributeValueFormatter($registry); | ||
$attributeValueFormatter->setAttributeTypesAndCodes([ | ||
'weight' => 'pim_catalog_metric', | ||
]); | ||
|
||
$value = ['amount' => '1', 'unit' => 'GRAM']; | ||
|
||
$context = [ | ||
'pim_catalog_metric' => [ | ||
'format' => '%amount% %unit%', | ||
] | ||
]; | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('weight', $value, $context), | ||
'1 GRAM' | ||
); | ||
|
||
$context = ['map' => ['GRAM' => 'gr']]; | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('weight', $value, $context), | ||
'1 gr' | ||
); | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('weight', $value, $context+['metric-display-unit' => false]), | ||
'1' | ||
); | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('weight', $value, $context+['metric-separator' => '']), | ||
'1gr' | ||
); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/Component/AttributeFormatter/MultiValuePresenterFormatterTest.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,54 @@ | ||
<?php | ||
|
||
namespace Tests\Misery\Component\AttributeFormatter; | ||
|
||
use Misery\Component\AttributeFormatter\AttributeValueFormatter; | ||
use Misery\Component\AttributeFormatter\MetricAttributeFormatter; | ||
use Misery\Component\AttributeFormatter\MultiValuePresenterFormatter; | ||
use Misery\Component\AttributeFormatter\PriceCollectionFormatter; | ||
use Misery\Component\AttributeFormatter\PropertyFormatterRegistry; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
class MultiValuePresenterFormatterTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function test_it_should_price_collection_type_a_value(): void | ||
{ | ||
$registry = new PropertyFormatterRegistry(); | ||
$registry->add(new MultiValuePresenterFormatter()); | ||
$attributeValueFormatter = new AttributeValueFormatter($registry); | ||
$attributeValueFormatter->setAttributeTypesAndCodes([ | ||
'list' => 'pim_catalog_simpleselect' | ||
]); | ||
|
||
$value = ['a', 'b', 'c']; | ||
|
||
$context = ['value-separator' => ',']; | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('list', $value, $context), | ||
'a,b,c' | ||
); | ||
|
||
$context = []; # default seperator ', ' | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('list', $value, $context), | ||
'a, b, c' | ||
); | ||
|
||
$value = ['unit' => 'GRAM', 'amount' => 100, 'dosis' => 'per day']; | ||
|
||
|
||
$context = [ | ||
'format' => '%amount% %unit% %dosis%', | ||
]; | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('list', $value, $context), | ||
'100 GRAM per day' | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/Component/AttributeFormatter/PriceCollectionFormatterTest.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,50 @@ | ||
<?php | ||
|
||
namespace Tests\Misery\Component\AttributeFormatter; | ||
|
||
use Misery\Component\AttributeFormatter\AttributeValueFormatter; | ||
use Misery\Component\AttributeFormatter\MetricAttributeFormatter; | ||
use Misery\Component\AttributeFormatter\MultiValuePresenterFormatter; | ||
use Misery\Component\AttributeFormatter\PriceCollectionFormatter; | ||
use Misery\Component\AttributeFormatter\PropertyFormatterRegistry; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
class PriceCollectionFormatterTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function test_it_should_price_collection_type_a_value(): void | ||
{ | ||
$registry = new PropertyFormatterRegistry(); | ||
$registry->add(new PriceCollectionFormatter()); | ||
$registry->add(new MultiValuePresenterFormatter()); | ||
$attributeValueFormatter = new AttributeValueFormatter($registry); | ||
|
||
$attributeValueFormatter->setAttributeTypesAndCodes([ | ||
'price' => 'pim_catalog_price_collection' | ||
]); | ||
|
||
$value = [ | ||
['amount' => '1.0000', 'currency' => 'EUR'], | ||
['amount' => '2.0000', 'currency' => 'US'] | ||
]; | ||
|
||
$context = ['currency' => 'EUR']; | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('price', $value, $context), | ||
'1 EUR' | ||
); | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('price', $value, $context+['format' => '%currency% %amount%']), | ||
'EUR 1' | ||
); | ||
|
||
$this->assertSame( | ||
$attributeValueFormatter->format('price', $value, $context+['format' => '%currency% %amount%', 'dec' => 2, 'dec_point' => ',']), | ||
'EUR 1,00' | ||
); | ||
} | ||
} |
Oops, something went wrong.