diff --git a/library/templates/Chili/View/RenderAccordionCarousel.php b/library/templates/Chili/View/RenderAccordionCarousel.php index 50ca851f5c58b43b99e9238a7bdb06b558a5ba3a..55117683b4c9f1e2ddf78dd7f2272f8efd27dbb1 100644 --- a/library/templates/Chili/View/RenderAccordionCarousel.php +++ b/library/templates/Chili/View/RenderAccordionCarousel.php @@ -41,66 +41,90 @@ class Chili_View_RenderAccordionCarousel extends ZendAfi_View_Helper_BaseHelper $first_element = array_shift($elements); - $id = uniqid(); - - $html = [$this->_expandedButton($first_element, $id), - $this->_showContent($first_element, $content_callback, $id)]; + $html = [(new Chili_View_RenderAccordionCarousel_Content($this->view, + $first_element, + $this->_id)) + ->render($content_callback)]; foreach($elements as $element) { - $id = uniqid(); - $html [] = $this->_collapsedButton($element, $id); - $html [] = $this->_collapsedContent($element, $content_callback, $id); + $html []= (new Chili_View_RenderAccordionCarousel_Content($this->view, + $element, + $this->_id)) + ->beCollapsed() + ->render($content_callback); + } return $this->_div(['class' => 'card'], implode($html)); } +} + + + + +class Chili_View_RenderAccordionCarousel_Content extends ZendAfi_View_Helper_BaseHelper { + protected + $_id, + $_expanded = true, + $_collapse_id, + $_heading_id, + $_parent_id, + $_element; + + + public function __construct($view, $element, $parent_id) { + parent::__construct(); + $this->_id = uniqid(); + $this->_collapse_id = 'collapse_' . $this->_id; + $this->_heading_id = 'heading_' . $this->_id; + $this->_parent_id = $parent_id; + $this->_element = $element; + $this->setView($view); + } - protected function _collapsedButton($element, $id) { - return $this->_button($element, $id, 'false', ' collapsed'); + public function beCollapsed() { + $this->_expanded = false; + return $this; } - protected function _expandedButton($element, $id) { - return $this->_button($element, $id, 'true'); + public function render($content_callback) { + return + $this->_button() + . + $this->_content($content_callback); } - protected function _button($element, $id, $expanded, $class = '') { + protected function _button() { + $class = $this->_expanded ? '' : ' collapsed'; + return $this->_div(['class' => 'card-header', - 'id' => 'heading_' . $id ], + 'id' => $this->_heading_id ], $this->_tag('h2', $this->_tag('button', - $element->getMainTitle(), + $this->_element->getMainTitle(), ['class' => 'accordion_button' . $class, 'type' => 'button', 'data-toggle' => 'collapse', - 'data-target' => '#collapse_' . $id, - 'aria-expanded' => $expanded, - 'aria-controls' => 'collapse_' . $id + 'data-target' => '#' . $this->_collapse_id, + 'aria-expanded' => $this->_expanded ? 'true' : 'false', + 'aria-controls' => $this->_collapse_id ]))); } - protected function _collapsedContent($element, $content_callback, $id) { - return $this->_content($element, $content_callback, $id); - } - - - protected function _showContent($element, $content_callback, $id) { - return $this->_content($element, $content_callback, $id, ' show'); - } - - - protected function _content($element, $content_callback, $id, $class = '') { - $attribs = ['id' => 'collapse_' . $id, - 'class' => 'accordion_content collapse' . $class, - 'aria-labelled-by' => 'heading_' . $id, - 'data-parent' => '#' . $this->_id]; + protected function _content($content_callback) { + $class = $this->_expanded ? 'show' : ''; + $attribs = ['id' => $this->_collapse_id, + 'class' => 'accordion_content collapse ' . $class, + 'aria-labelledby' => $this->_heading_id, + 'data-parent' => '#' . $this->_parent_id]; return $this->_div($attribs, $this->_div(['class' => 'card-body'], - $content_callback($element))); + $content_callback($this->_element))); } } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Agenda/Form.php b/library/templates/Intonation/Library/Widget/Carousel/Agenda/Form.php index b984b7c50d253ab43ba5458add5eb545bd747cdf..8a558518ad1ee5e279e7952bf07d3cc34d1fc77f 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Agenda/Form.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Agenda/Form.php @@ -25,12 +25,8 @@ class Intonation_Library_Widget_Carousel_Agenda_Form extends Intonation_Library_ public function init() { parent::init(); - $layouts = $this->getLayouts(); - unset($layouts[Intonation_Library_Widget_Carousel_Agenda_Definition::CALENDAR]); - $visible_for_values = implode('", "', array_keys($layouts)); - Class_ScriptLoader::getInstance() - ->addJQueryReady('formSelectToggleVisibilityForElement("#layout", $("#rendering, #order, #enabled_filters, #size").closest("tr"), ["' . $visible_for_values . '"]);'); + ->addJQueryReady('formSelectToggleVisibilityForElement("#layout", $("#rendering, #order, #enabled_filters, #size").closest("tr"), ["' . $this->_layoutsWithoutCalendar() . '"]);'); $this ->addElement('treeSelect', @@ -76,4 +72,11 @@ class Intonation_Library_Widget_Carousel_Agenda_Form extends Intonation_Library_ return $layouts; } + + + protected function _layoutsWithoutCalendar() { + $layouts = $this->getLayouts(); + unset($layouts[Intonation_Library_Widget_Carousel_Agenda_Definition::CALENDAR]); + return implode('", "', array_keys($layouts)); + } } \ No newline at end of file diff --git a/tests/scenarios/Templates/ChiliAccordionTest.php b/tests/scenarios/Templates/ChiliAccordionTest.php index 38b533160726950770df3119493aa1b58c794da9..e12eca63190688487627ccfc66c690b8e8a8a3ca 100644 --- a/tests/scenarios/Templates/ChiliAccordionTest.php +++ b/tests/scenarios/Templates/ChiliAccordionTest.php @@ -97,9 +97,15 @@ class ChiliAccordionWidgetTest extends AbstractControllerTestCase { div class=card-header id=heading_XX h2 button aria-controls=collapse_XX - div id=collapse_XX aria-labelled-by=heading_XX + div id=collapse_XX aria-labelledby=heading_XX */ - $this->assertXPathCount('//div[@id=following-sibling::div[contains(@id, "collapse_")]/@aria-labelled-by]/h2/button[@aria-controls=ancestor::div[contains(@class, "card-header")]/following-sibling::div/@id]', + $this->assertXPathCount('//div[@id=following-sibling::div[contains(@id, "collapse_")]/@aria-labelledby]/h2/button[@aria-controls=ancestor::div[contains(@class, "card-header")]/following-sibling::div/@id]', 2); } + + + /** @test */ + public function pageShouldBeHTML5Valid() { + $this->assertHTML5(); + } } diff --git a/tests/scenarios/Templates/ChiliTest.php b/tests/scenarios/Templates/ChiliTest.php index b5bcbeab6cbe3dd44c36a8bc9858b77a193b9e66..d46d5c01e3cb1128b661848275184b285777071a 100644 --- a/tests/scenarios/Templates/ChiliTest.php +++ b/tests/scenarios/Templates/ChiliTest.php @@ -548,6 +548,12 @@ class ChiliEditWidgetLibraryTest extends ChiliTemplateTestCase { public function layoutSelectorShouldContainsAccordionCarousel() { $this->assertXPath('//form//select[@name="layout"]/option[@value="accordion"]'); } + + + /** @test */ + public function calendarShouldNotBeInFormSelectToggleVisibility() { + $this->assertXPathContentContains('//script', '["accordion", "carousel", "top_highlight_carousel", "left_highlight_carousel", "multiple_carousel", "multiple_carousel_plus", "map", "grid", "horizontal_list", "list", "list_with_options", "wall"]'); + } }