ComponentParameterCurrencyTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace CMText\RichContent\Templates\Whatsapp;
  3. use PHPUnit\Framework\TestCase;
  4. class ComponentParameterCurrencyTest extends TestCase
  5. {
  6. public function testJsonSerialize()
  7. {
  8. $currency = new ComponentParameterCurrency(
  9. '€20,20',
  10. 'EUR',
  11. 20200
  12. );
  13. $this->assertJson(
  14. json_encode($currency)
  15. );
  16. $json = json_decode( json_encode($currency) );
  17. $this->assertObjectHasAttribute(
  18. 'currency',
  19. $json
  20. );
  21. $this->assertObjectHasAttribute(
  22. 'code',
  23. $json->currency
  24. );
  25. $this->assertObjectHasAttribute(
  26. 'amount_1000',
  27. $json->currency
  28. );
  29. $this->assertEquals(
  30. 20200,
  31. $json->currency->amount_1000
  32. );
  33. $this->assertObjectHasAttribute(
  34. 'fallback_value',
  35. $json->currency
  36. );
  37. }
  38. public function test__construct()
  39. {
  40. $currency = new ComponentParameterCurrency(
  41. '€50,11',
  42. 'EUR',
  43. 50110
  44. );
  45. $this->assertInstanceOf(
  46. ComponentParameterBase::class,
  47. $currency
  48. );
  49. }
  50. }