Ejemplo n.º 1
0
 public function testBuildBooleanAttribute()
 {
     // prepare
     $htmlTagBuilder = new HtmlTagBuilder('iframe', array('class' => 'videoWrapper', 'allowfullscreen' => null));
     // execute
     $tag = $htmlTagBuilder->toString();
     // verify
     $this->assertContains('<iframe class="videoWrapper" allowfullscreen></iframe>', $tag);
 }
Ejemplo n.º 2
0
 /**
  * @param $renderApi
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  */
 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     $child = new ChildModuleDependency();
     if ($child->isInsideModule($renderApi, $unit, 'rz_form')) {
         $this->renderFormFieldContent($renderApi, $unit);
     } else {
         $i18n = new Translator($renderApi, $moduleInfo);
         $msg = $i18n->translate('error.moduleOnlyWorkingInForm');
         $errorTag = new HtmlTagBuilder('div', array('class' => 'RUKZUKmissingInputHint'), array(new HtmlTagBuilder('button', array('style' => 'cursor: default;'), array($msg))));
         echo $errorTag->toString();
     }
 }
Ejemplo n.º 3
0
 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     $moduleDependency = new \LightboxModuleDependency();
     if (!$moduleDependency->isInsideModule($renderApi, $unit, 'rz_lightbox')) {
         $renderApi->renderChildren($unit);
     } else {
         $i18n = new Translator($renderApi, $moduleInfo);
         $msg = $i18n->translate('error.noLightboxModuleInheritance');
         $errorTag = new HtmlTagBuilder('div', array('class' => 'RUKZUKmissingInputHint'), array(new HtmlTagBuilder('button', array('style' => 'cursor: default;'), array($msg))));
         echo $errorTag->toString();
     }
 }
Ejemplo n.º 4
0
 protected function buildKeyValueTable($items)
 {
     $table = HtmlTagBuilder::table();
     foreach ($items as $k => $v) {
         $table->append(HtmlTagBuilder::tr(HtmlTagBuilder::td($k), HtmlTagBuilder::td($v)));
     }
     return $table;
 }
Ejemplo n.º 5
0
 /**
  * Cart Table
  *
  * @param CartWithShipping $cart
  * @param bool             $edit - show edit input fields
  *
  * @return HtmlTagBuilder
  */
 public function renderCart($cart, $edit = false)
 {
     $cartWrapper = new HtmlTagBuilder('div', array('class' => 'cartOverview'));
     $cartTable = new HtmlTagBuilder('table', array('class' => 'cartTable'));
     $cartTable->append($this->createTableHeader());
     $cartWrapper->append($cartTable);
     // empty cart
     if ($cart->totalUniqueItems() === 0) {
         $this->addEmptyCartRow($cartTable);
     } else {
         /** @var CartItem $item */
         foreach ($cart->all() as $item) {
             $cartTable->append($this->renderCartRow($edit, $item));
         }
         $this->addCartSummary($cart, $cartTable);
     }
     return $cartWrapper;
 }
Ejemplo n.º 6
0
 public function test_process()
 {
     // ARRANGE
     $uniqueString = __CLASS__ . '::' . __METHOD__ . '::' . __LINE__;
     $settingsMock = $this->getShopSettingsMock(null, null, array('getEmailNotificationAdr' => array($this->once(), $uniqueString . '*****@*****.**'), 'getEmailConfirmationText' => array($this->once(), $uniqueString . '*****@*****.**')));
     $cartMock = $this->getCartMock();
     $translatorMock = $this->getTranslatorMock();
     $checkoutMock = $this->getCheckoutMock();
     $mailerMock = $this->getMailerMock();
     $strategy = $this->getCompleteStrategyMock(array('renderCart' => array($this->once(), HtmlTagBuilder::div()->appendText('CartOutput')), 'renderCheckoutSummary' => array($this->once(), HtmlTagBuilder::div()->appendText('CheckoutSummaryOutput')), 'getMailer' => array($this->exactly(2), $mailerMock)), array($settingsMock, $checkoutMock, $cartMock, $translatorMock));
     // ACT
     $actualResponse = $strategy->process();
     // ASSERT
     $expectedShopResponse = new ShopModeResponse('showSuccess');
     $this->assertEquals($expectedShopResponse, $actualResponse);
 }
Ejemplo n.º 7
0
 public function insertCssAssets($moduleData)
 {
     foreach ($moduleData as $moduleId => $data) {
         if (isset($data['cssAssets'])) {
             foreach ($data['cssAssets'] as $cssAssets) {
                 echo HtmlTagBuilder::link()->set(array('rel' => 'stylesheet', 'href' => $cssAssets));
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Creates the html code for a single unit and writes it to output buffer.
  * This is an empty implementation and should be overridden if you want
  * to output any html code.
  *
  * @param \Render\APIs\APIv1\RenderAPI $renderApi - reference to the module api
  * @param \Render\Unit $unit - an object which provides general unit specific
  *    data (e.g. unit id, form values, ... etc.)
  * @param \Render\ModuleInfo $moduleInfo - reference an object which provides
  *    the general module information (e.g. module id, asset url, manifest
  *    data, ... etc.)
  */
 public function render($renderApi, $unit, $moduleInfo)
 {
     if ($moduleInfo->isExtension()) {
         return;
     }
     $tag = new HtmlTagBuilder('div');
     $tag->set('id', $unit->getId());
     $tag->addClass($moduleInfo->getId());
     $tag->addClass('isModule');
     $tag->addClass($unit->getHtmlClass());
     // call hook
     $this->modifyWrapperTag($tag, $renderApi, $unit, $moduleInfo);
     echo $tag->getOpenString();
     $this->renderContent($renderApi, $unit, $moduleInfo);
     echo $tag->getCloseString();
 }
 /**
  * Creates an html tag object that output build the basis for the javascript
  * responsive image lib
  *
  * @param string|\Render\APIs\APIv1\MediaImage $image
  *    The media image object or its id
  * @param array $imageCfg
  *    The image manipulations; The following keys/values are supported
  *    # 'crop'    => array('x' => int, 'y' => int, 'width' => int, 'height' => int)
  *    # 'resize'  => array('width' => int, 'height' => int)
  *    # 'quality' => int
  * @param array attributes
  *    A set of additional tag attributes (key -> attribute name, value -> attribute value)
  * @return \Rukzuk\Modules\HtmlTagBuilder
  */
 public function getImageTag($image = null, $imageCfg = null, $attributes = null)
 {
     // wrapper
     $wrapper = new HtmlTagBuilder('div', array('class' => 'responsiveImageWrapper'));
     // image tag
     $imgTag = new HtmlTagBuilder('img', array('alt' => ''));
     $imgTag->set($attributes);
     $imgTag->addClass('imgSize');
     // fill height element which helps to keep aspect ratio of image (using %-padding technique)
     $fillHeight = new HtmlTagBuilder('div', array('class' => 'fillHeight'));
     try {
         if (is_string($image)) {
             // get the image object if a image id was given
             $image = $this->api->getMediaItem($image)->getImage();
         }
     } catch (Exception $e) {
     }
     // we have a image (object)
     if (is_object($image)) {
         // height in percent of the width (used for padding trick)
         $origWidth = $image->getOriginalWidth();
         $origHeight = $image->getOriginalHeight();
         $origHeightRatio = $origHeight / $origWidth * 100;
         // create the image urls for each of the pre-defined and most common device resolutions
         $imgUrls = $this->getResponsiveImageUrls($image->getMediaItem(), $imageCfg);
         // provide big, not cropped image,
         // used in image cropper (panzoom) and for rz_lightbox
         try {
             $image->resetOperations();
             $image = $image->resizeScale(ResponsiveImageBuilder::$maxResponsiveImageResolution);
             $imgTag->set('data-cms-origsrc', $image->getUrl());
         } catch (Exception $e) {
             // do nothing
         }
         // indicate that we have an actual image
         $wrapper->addClass('hasImage');
         // data for js image replacement code (lazy sizes)
         // build src set
         $srcSet = array();
         foreach ($imgUrls as $w => $u) {
             $srcSet[] = $u . ' ' . $w . 'w';
         }
         $imgTag->set(array('data-sizes' => 'auto', 'data-srcset' => implode(', ', $srcSet)));
         $imgTag->addClass('lazyload');
         $imgTag->addClass('responsiveImage');
         // set default image (smallest resolution LQIP for fast responses)
         $image->resetOperations();
         $preloadSrc = $this->getResponsiveImageUrl($image, $imageCfg, ResponsiveImageBuilder::$previewResponsiveImageResolution);
         $imgTag->set('src', $preloadSrc);
         // set fill height value
         $imgHeight = $this->api->getFormValue($this->unit, 'imgHeight', '0%');
         // use original aspect ratio as height if 0%
         $fillHeightPaddingBottom = $imgHeight == '0%' ? sprintf('%F', $origHeightRatio) . '%' : $imgHeight;
     } else {
         // show a blank image
         $imgTag->addClass('blankImgPlaceholder')->set('src', $this->getPlaceholderUrl());
         // set fill height value - use 50% if it is 0% (original image) because blank image has no size (it is a background)
         $blankHeight = $this->api->getFormValue($this->unit, 'imgHeight', '0%');
         // use 50% as height, because we don't have a original aspect ratio
         $fillHeightPaddingBottom = $blankHeight == '0%' ? '50%' : $blankHeight;
     }
     $fillHeight->set('style', 'padding-bottom: ' . $fillHeightPaddingBottom . ';');
     $wrapper->append($imgTag);
     $wrapper->append($fillHeight);
     return $wrapper;
 }
Ejemplo n.º 10
0
 /**
  * Creates the html code for a single unit and writes it to output buffer.
  * This is an empty implementation and should be overridden if you want
  * to output any html code.
  *
  * @param \Render\APIs\APIv1\RenderAPI $renderApi - reference to the module api
  * @param \Render\Unit $unit - an object which provides general unit specific
  *    data (e.g. unit id, form values, ... etc.)
  * @param \Render\ModuleInfo $moduleInfo - reference an object which provides
  *    the general module information (e.g. module id, asset url, manifest
  *    data, ... etc.)
  */
 public function render($renderApi, $unit, $moduleInfo)
 {
     if ($moduleInfo->isExtension()) {
         return;
     }
     $tag = new HtmlTagBuilder('div');
     $tag->set('id', $unit->getId());
     $tag->addClass($moduleInfo->getId());
     $tag->addClass('isModule');
     $tag->addClass($unit->getHtmlClass());
     // add style Set classes
     $children = $renderApi->getChildren($unit);
     $styleSetClasses = '';
     foreach ($children as $childUnit) {
         $styleSetClass = $renderApi->getFormValue($childUnit, 'cssStyleSets', false);
         if ($styleSetClass) {
             $styleSetClasses .= str_replace(",", " ", $styleSetClass) . " ";
         }
     }
     if ($styleSetClasses != '') {
         $tag->addClass($styleSetClasses);
     }
     // call hook
     $this->modifyWrapperTag($tag, $renderApi, $unit, $moduleInfo);
     echo $tag->getOpenString();
     $this->renderContent($renderApi, $unit, $moduleInfo);
     echo $tag->getCloseString();
 }
Ejemplo n.º 11
0
 /**
  * @param $variants
  * @return HtmlTagBuilder
  */
 private function buildVariantSelect($variants)
 {
     $variantSelect = new HtmlTagBuilder('select', array('name' => 'variant', 'class' => 'pd-addToCartVariants'));
     foreach ($variants as $variant) {
         $variantSelect->append(new HtmlTagBuilder('option', array('value' => $variant), array($variant)));
     }
     return $variantSelect;
 }
Ejemplo n.º 12
0
 /**
  * @param HtmlTagBuilder $confirmation
  * @param string|null    $emailConfirmationText
  *
  * @return string
  */
 protected function getEmailBody($confirmation, $emailConfirmationText = null)
 {
     if (empty($emailConfirmationText)) {
         return $confirmation->toString();
     } else {
         $emailBody = HtmlTagBuilder::div()->appendText($emailConfirmationText)->append($confirmation);
         return $emailBody->toString();
     }
 }
Ejemplo n.º 13
0
 /**
  * @param HeadAPI        $api
  * @param Unit           $unit
  * @param HtmlTagBuilder $wrapper
  */
 protected function showErrors($api, $unit, $wrapper)
 {
     $errors = $this->getUnitContext($api, $unit, 'errors', array());
     foreach ($errors as $errorMessage) {
         $wrapper->append(HtmlTagBuilder::div($errorMessage)->set('class', 'errorMessage'));
     }
 }