AttributeSpec.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace spec\Sylius\Component\Attribute\Model;
  11. use PhpSpec\ObjectBehavior;
  12. use Sylius\Component\Attribute\Model\AttributeTypes;
  13. /**
  14. * @author Paweł Jędrzejewski <pawel@sylius.org>
  15. * @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
  16. */
  17. class AttributeSpec extends ObjectBehavior
  18. {
  19. public function let()
  20. {
  21. $this->setCurrentLocale('en');
  22. }
  23. function it_is_initializable()
  24. {
  25. $this->shouldHaveType('Sylius\Component\Attribute\Model\Attribute');
  26. }
  27. function it_implements_Sylius_attribute_interface()
  28. {
  29. $this->shouldImplement('Sylius\Component\Attribute\Model\AttributeInterface');
  30. }
  31. function it_has_no_id_by_default()
  32. {
  33. $this->getId()->shouldReturn(null);
  34. }
  35. function it_has_no_name_by_default()
  36. {
  37. $this->getName()->shouldReturn(null);
  38. }
  39. function its_name_is_mutable()
  40. {
  41. $this->setName('T-Shirt collection');
  42. $this->getName()->shouldReturn('T-Shirt collection');
  43. }
  44. function it_returns_name_when_converted_to_string()
  45. {
  46. $this->setName('T-Shirt material');
  47. $this->__toString()->shouldReturn('T-Shirt material');
  48. }
  49. function it_has_no_presentation_by_default()
  50. {
  51. $this->getPresentation()->shouldReturn(null);
  52. }
  53. function its_presentation_is_mutable()
  54. {
  55. $this->setPresentation('Size');
  56. $this->getPresentation()->shouldReturn('Size');
  57. }
  58. function it_has_text_type_by_default()
  59. {
  60. $this->getType()->shouldReturn(AttributeTypes::TEXT);
  61. }
  62. function its_type_is_mutable()
  63. {
  64. $this->setType(AttributeTypes::CHECKBOX);
  65. $this->getType()->shouldReturn(AttributeTypes::CHECKBOX);
  66. }
  67. function it_initializes_empty_configuration_array_by_default()
  68. {
  69. $this->getConfiguration()->shouldReturn(array());
  70. }
  71. function its_configuration_is_mutable()
  72. {
  73. $this->setConfiguration(array('choices' => array('Red', 'Blue')));
  74. $this->getConfiguration()->shouldReturn(array('choices' => array('Red', 'Blue')));
  75. }
  76. function it_initializes_creation_date_by_default()
  77. {
  78. $this->getCreatedAt()->shouldHaveType('DateTime');
  79. }
  80. function its_creation_date_is_mutable()
  81. {
  82. $date = new \DateTime();
  83. $this->setCreatedAt($date);
  84. $this->getCreatedAt()->shouldReturn($date);
  85. }
  86. function it_has_no_last_update_date_by_default()
  87. {
  88. $this->getUpdatedAt()->shouldReturn(null);
  89. }
  90. function its_last_update_date_is_mutable()
  91. {
  92. $date = new \DateTime();
  93. $this->setUpdatedAt($date);
  94. $this->getUpdatedAt()->shouldReturn($date);
  95. }
  96. function it_has_fluent_interface()
  97. {
  98. $date = new \DateTime();
  99. $this->setName('T-Shirt brand')->shouldReturn($this);
  100. $this->setPresentation('Brand')->shouldReturn($this);
  101. $this->setType(AttributeTypes::CHOICE)->shouldReturn($this);
  102. $this->setConfiguration(array())->shouldReturn($this);
  103. $this->setCreatedAt($date)->shouldReturn($this);
  104. $this->setUpdatedAt($date)->shouldReturn($this);
  105. }
  106. }