AbstractTranslatableSpec.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace spec\Sylius\Component\Translation\Model;
  3. use PhpSpec\ObjectBehavior;
  4. use Sylius\Component\Translation\Model\TranslationInterface;
  5. use Sylius\Component\Translation\Model\AbstractTranslatable;
  6. use Sylius\Component\Translation\Model\AbstractTranslation;
  7. class AbstractTranslatableSpec extends ObjectBehavior
  8. {
  9. function let()
  10. {
  11. $this->beAnInstanceOf('spec\Sylius\Component\Translation\Model\ConcreteTranslatable');
  12. }
  13. function it_is_translatable()
  14. {
  15. $this->shouldImplement('Sylius\Component\Translation\Model\TranslatableInterface');
  16. }
  17. function it_initializes_translattion_collection_by_default()
  18. {
  19. $this->getTranslations()->shouldHaveType('Doctrine\Common\Collections\Collection');
  20. }
  21. function it_adds_translation(TranslationInterface $translation)
  22. {
  23. $translation->getLocale()->willReturn('en');
  24. $translation->setTranslatable($this)->shouldBeCalled();
  25. $this->addTranslation($translation)->shouldReturn($this);
  26. $this->hasTranslation($translation)->shouldReturn(true);
  27. }
  28. function it_removes_translation(TranslationInterface $translation)
  29. {
  30. $this->addTranslation($translation);
  31. $this->removeTranslation($translation)->shouldReturn($this);
  32. $this->hasTranslation($translation)->shouldReturn(false);
  33. }
  34. function its_current_locale_is_mutable()
  35. {
  36. $this->setCurrentLocale('en')->shouldReturn($this);
  37. $this->getCurrentLocale()->shouldReturn('en');
  38. }
  39. function its_current_translation_is_mutable(TranslationInterface $translation)
  40. {
  41. $this->setCurrentTranslation($translation);
  42. $this->getCurrentTranslation()->shouldReturn($translation);
  43. }
  44. function its_fallback_locale_is_mutable()
  45. {
  46. $this->setFallbackLocale('en');
  47. $this->getFallbackLocale()->shouldReturn('en');
  48. }
  49. function it_throws_exception_if_no_locale_has_been_set()
  50. {
  51. $this->shouldThrow('\RuntimeException')->duringTranslate();
  52. }
  53. function it_translates_properly(TranslationInterface $translation)
  54. {
  55. $translation->getLocale()->willReturn('en');
  56. $translation->setTranslatable($this)->shouldBeCalled();
  57. $this->addTranslation($translation);
  58. $this->setCurrentLocale('en');
  59. $this->translate()->shouldReturn($translation);
  60. }
  61. function it_creates_new_empty_translation_properly()
  62. {
  63. $this->setCurrentLocale('en');
  64. $this->translate()->shouldHaveType('spec\Sylius\Component\Translation\Model\ConcreteTranslatableTranslation');
  65. }
  66. function it_clones_new_translation_properly(TranslationInterface $translation)
  67. {
  68. $translation->getLocale()->willReturn('en');
  69. $translation->setTranslatable($this)->shouldBeCalled();
  70. $translation->acmeProperty = 'acmeProp';
  71. $this->addTranslation($translation);
  72. $this->setCurrentLocale('en');
  73. $translation = $this->translate();
  74. $translation->shouldImplement('Sylius\Component\Translation\Model\TranslationInterface');
  75. $translation->acmeProperty->shouldBe('acmeProp');
  76. }
  77. }
  78. class ConcreteTranslatable extends AbstractTranslatable
  79. {
  80. protected function getTranslationEntityClass(){
  81. return 'spec\Sylius\Component\Translation\Model\ConcreteTranslatableTranslation';
  82. }
  83. }
  84. class ConcreteTranslatableTranslation extends AbstractTranslation
  85. {
  86. }