diff --git a/library/Class/Article.php b/library/Class/Article.php index b94601bcb858ca6e4724b473356c08e9b493958c..f0c1b547e889059cf73e2444ddbee27130a2569c 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -618,23 +618,21 @@ class Class_Article extends Storm_Model_Abstract { public function getFirstCarouselData() : array { - return $this->_getCarouselData('preg_match'); + return $this->_getCarouselDataFrom('preg_match', $this->getSummary()); } - public function getAllCarouselsData() { - return $this->_getCarouselData('preg_match_all'); + public function getAllCarouselsData() : array { + return $this->_getCarouselDataFrom('preg_match_all', + $this->getSummary() . $this->getFullContent()); } - protected function _getCarouselData(string $preg_function) : array { + protected function _getCarouselDataFrom(string $preg_function, string $content) : array { + $pattern = '|(?P<allimg><img[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>[^"]+)[^>]*>)|'; $matches = []; - $expression = '|(?P<allimg><img[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>[^"]+)[^>]*>)|'; - - return $preg_function($expression, - $this->getSummary() . $this->getFullContent(), - $matches) > 0 + return $preg_function($pattern, $content, $matches) > 0 ? $matches : []; } diff --git a/library/templates/Intonation/Library/View/Wrapper/Abstract.php b/library/templates/Intonation/Library/View/Wrapper/Abstract.php index 73faf2ab6314d1fb82a11f9e76942c72767679b2..9a4f6e15c873618d1d7b66c3adf0a6505db93c34 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Abstract.php +++ b/library/templates/Intonation/Library/View/Wrapper/Abstract.php @@ -236,6 +236,11 @@ abstract class Intonation_Library_View_Wrapper_Abstract { } + protected function _isWidgetContextLayoutCarousel() : bool { + return $this->getWidgetContext()->isLayoutCarousel(); + } + + /** @return string */ abstract public function getMainTitle(); diff --git a/library/templates/Intonation/Library/View/Wrapper/Article.php b/library/templates/Intonation/Library/View/Wrapper/Article.php index bcf27c5f3146488bb98b38c20352b1e3e39a7379..807a4d3c4b947a938105a60e105ef9c300b668d4 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Article.php +++ b/library/templates/Intonation/Library/View/Wrapper/Article.php @@ -255,6 +255,9 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr public function getHtmlPicture() { + if ($this->_isWidgetContextLayoutCarousel()) + return ''; + $carousel_data = $this->_model->getFirstCarouselData(); if (empty($carousel_data)) diff --git a/library/templates/Intonation/Library/Widget/Carousel/NullContext.php b/library/templates/Intonation/Library/Widget/Carousel/NullContext.php index e7e066892ab23123e25697a66617d474e312177f..b56669b1611e50b7933ca38743b5f8b3a8902d8c 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/NullContext.php +++ b/library/templates/Intonation/Library/Widget/Carousel/NullContext.php @@ -32,4 +32,9 @@ class Intonation_Library_Widget_Carousel_NullContext extends Class_Entity { public function newCollectionWith($order) { return new Storm_Collection; } + + + public function isLayoutCarousel() : bool { + return false; + } } diff --git a/library/templates/Intonation/Library/Widget/Carousel/View.php b/library/templates/Intonation/Library/Widget/Carousel/View.php index c70df1da2016404c7a1696ab91469b4a790f77ea..2b4664a54c93dbbd93f4eb0b3605bac56184f482 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/View.php @@ -396,6 +396,13 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help } + public function isLayoutCarousel() : bool { + return + array_key_exists($this->_settings->getLayout(), + (new Intonation_Library_Widget_Carousel_Definition)->getCarouselLayouts()); + } + + Abstract protected function _findElements(); abstract protected function _getWrapper(); abstract protected function _getLinkToAllTitle(); diff --git a/tests/scenarios/Templates/TemplatesArticlesTest.php b/tests/scenarios/Templates/TemplatesArticlesTest.php index 780e369c2fb6c72e7834609f9952e2df95698c85..785616c41fc2e64a49bec7732803a40f5933391c 100644 --- a/tests/scenarios/Templates/TemplatesArticlesTest.php +++ b/tests/scenarios/Templates/TemplatesArticlesTest.php @@ -42,7 +42,9 @@ abstract class TemplatesArticlesWidgetTestCase extends Admin_AbstractControllerT 'link_to_all' => 1, 'embeded_code'=> 1, 'IntonationShowFooter' => 1, - 'layout' => 'multiple_carousel']) + 'layout' => 'multiple_carousel', + 'cycle' => 4, + 'rendering' => 'card']) ->assertSave(); @@ -62,7 +64,7 @@ abstract class TemplatesArticlesWidgetTestCase extends Admin_AbstractControllerT ['id' => 6, 'id_cat' => 34, 'titre' => 'Sprechen Sie Deutsch ?', - 'contenu' => '<p>Ich ...</p>']); + 'contenu' => '<p>Ich ...</p><img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=123&">']); $this->fixture(Class_Article::class, ['id' => 7, @@ -174,8 +176,8 @@ class TemplatesArticlesEditWidgetTest extends TemplatesArticlesWidgetTestCase { /** @test */ - public function formCycleShouldBeEqualsToZero() { - $this->assertXPath('//input[@type="number"][@name="cycle"][@value="0"]'); + public function formCycleShouldBeEqualsToFour() { + $this->assertXPath('//input[@type="number"][@name="cycle"][@value="4"]'); } @@ -541,9 +543,9 @@ class TemplatesArticlesMapTest extends TemplatesArticlesWithLocationTestCase { parent::setUp(); ZendAfi_Auth::getInstance()->clearIdentity(); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') - ->whenCalled('getArticlesByPreferences') - ->answers([Class_Article::find(7), Class_Article::find(8)]); + $this->onLoaderOfModel(Class_Article::class) + ->whenCalled('getArticlesByPreferences') + ->answers([Class_Article::find(7), Class_Article::find(8)]); Class_Profil::find(1) ->setBoiteOfTypeInDivision(3, @@ -627,6 +629,12 @@ class TemplatesArticlesWithOrderCreationDateTest extends TemplatesArticlesWidget $this->assertXPathContentContains('//a[contains(@href, "admin/cms/add")]', 'Ajouter un nouvel article'); } + + + /** @test */ + public function recordsWidgetShouldNotBeInNewsWidgetCarousel() { + $this->assertNotXPath('//div[contains(@class, "boite news")]//div[contains(@class, "boite kiosque")]'); + } } @@ -941,24 +949,22 @@ abstract class TemplatesArticlesWithWidgetRenderWallTestCase extends AbstractCon $this->_logAdmin(); - $this->fixture(Class_Article::class, - [ 'id' => 55, + ['id' => 55, 'titre' => 'Mes dvds', 'description' => 'Un article avec un kiosque dans du data-code', - 'contenu' => '<img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=123&"> -<img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=124&">']); + 'contenu' => '<img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=123&"><img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=124&">']); - $this->_dispatch(); + $this->_dispatch(); } + protected function _dispatch() { $this->dispatch('/cms/articleview/id/55'); } - protected function _logAdmin() { - } + protected function _logAdmin() { } } @@ -1063,9 +1069,6 @@ class TemplatesArticlesWithWidgetRenderWallNotLoggedTest class TemplatesArticlesRenderAllFromArticleTest extends TemplatesArticlesWithWidgetRenderWallTestCase { - protected $_storm_default_to_volatile = true; - - protected function _dispatch() {}