protected function _toHtml() { try { $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail(); if (!$email) { return ''; } $helper = new Expressly_Expressly_Helper_Client(); $merchant = $helper->getMerchant(); $event = new BannerEvent($merchant, $email); try { $helper->getDispatcher()->dispatch(BannerSubscriber::BANNER_REQUEST, $event); if (!$event->isSuccessful()) { throw new GenericException(Expressly_Expressly_Helper_Client::errorFormatter($event)); } } catch (GenericException $e) { $helper->getLogger()->error($e); return ''; } return BannerHelper::toHtml($event); } catch (Exception $ignore) { // never break the shop return ''; } }
public function testSuccessful() { $imageUrl = 'http://buyexpressly.com/assets/img/expressly-logo-sm-gray.png'; $migrationUrl = 'http://buyexpressly.com/expressly/api/50602095-c390-4a8f-bc88-728d725b1410'; $bannerEvent = $this->getMockBuilder('Expressly\\Event\\BannerEvent')->setConstructorArgs(array(new Merchant(), '*****@*****.**'))->getMock(); $bannerEvent->method('getContent')->willReturn(array('bannerImageUrl' => $imageUrl, 'migrationLink' => $migrationUrl)); $this->assertEquals(BannerHelper::toHtml($bannerEvent), sprintf('<div class="expressly-banner" style="padding:10px;text-align:center;"><a href="%s"><img style="display:inline;" src="%s"/></a></div>', $migrationUrl, $imageUrl)); }