Source for file Data.php

Documentation is available at Data.php

  1. <?php
  2. /**
  3.  *  Magentron EmailImages Extension
  4.  *
  5.  *  @category   Magentron
  6.  *  @package    Magentron_EmailImages
  7.  *  @author     Jeroen Derks
  8.  *  @copyright  Copyright (c) 2011 Jeroen Derks http://www.magentron.com
  9.  *  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  10.  */
  11. class Magentron_EmailImages_Test_Helper_Data extends EcomDev_PHPUnit_Test_Case
  12. {
  13.     /**
  14.      *  Test isEnabled() for enabled
  15.      *
  16.      *  @test
  17.      *  @loadFixture
  18.      *  @doNotIndexAll
  19.      */
  20.     public function isEnabled()
  21.     {
  22.         $enabled Mage::helper('emailimages')->isEnabled();
  23.         $this->assertTrue($enabled);
  24.     }
  25.  
  26.     /**
  27.      *  Test isEnabled() for disabled
  28.      *
  29.      *  @test
  30.      *  @loadFixture
  31.      *  @doNotIndexAll
  32.      */
  33.     public function isEnabledFalse()
  34.     {
  35.         $enabled Mage::helper('emailimages')->isEnabled();
  36.         $this->assertFalse($enabled);
  37.     }
  38.  
  39.     /**
  40.      *  Test getCacheTime() for valid config value
  41.      *
  42.      *  @test
  43.      *  @loadFixture
  44.      *  @doNotIndexAll
  45.      */
  46.     public function getCacheTime()
  47.     {
  48.         $value Mage::helper('emailimages')->getCacheTime();
  49.         $this->assertEquals($this->expected('cache_time')->getValid()$value);
  50.     }
  51.     
  52.     /**
  53.      *  Test getCacheTime() for invalid config value
  54.      *
  55.      *  @test
  56.      *  @loadFixture
  57.      *  @doNotIndexAll
  58.      */
  59.     public function getCacheTimeInvalid()
  60.     {
  61.         $value Mage::helper('emailimages')->getCacheTime();
  62.         $this->assertEquals(Magentron_EmailImages_Helper_Data::DEFAULT_CACHE_TIME$value);
  63.     }
  64.  
  65.     /**
  66.      *  Test getRegularExpression() for valid config value
  67.      *
  68.      *  @test
  69.      *  @loadFixture
  70.      *  @doNotIndexAll
  71.      */
  72.     public function getRegularExpression()
  73.     {
  74.         $value Mage::helper('emailimages')->getRegularExpression();
  75.         $this->assertEquals($this->expected('regexp')->value$value);
  76.     }
  77.     
  78.     /**
  79.      *  Test getRegularExpression() for invalid config value
  80.      *
  81.      *  @test
  82.      *  @loadFixture
  83.      *  @doNotIndexAll
  84.      */
  85.     public function getRegularExpressionInvalid()
  86.     {
  87.         $value Mage::helper('emailimages')->getRegularExpressionIndex();
  88.         $this->assertEquals(Magentron_EmailImages_Helper_Data::DEFAULT_REGEXP_INDEX$value);
  89.     }
  90.     
  91.     /**
  92.      *  Test getRegularExpressionIndex() for valid config value
  93.      *
  94.      *  @test
  95.      *  @loadFixture
  96.      *  @doNotIndexAll
  97.      */
  98.     public function getRegularExpressionIndex()
  99.     {
  100.         $value Mage::helper('emailimages')->getRegularExpressionIndex();
  101.         $this->assertEquals($this->expected('regexp')->index$value);
  102.     }
  103.  
  104.     /**
  105.      *  Test getRegularExpressionIndex() for invalid config value
  106.      *
  107.      *  @test
  108.      *  @loadFixture
  109.      *  @doNotIndexAll
  110.      */
  111.     public function getRegularExpressionIndexInvalid()
  112.     {
  113.         $value Mage::helper('emailimages')->getRegularExpressionIndex();
  114.         $this->assertEquals(Magentron_EmailImages_Helper_Data::DEFAULT_REGEXP_INDEX$value);
  115.     }
  116.     
  117.     /**
  118.      *  Test addImages()
  119.      *
  120.      *  @test
  121.      *  @loadFixture
  122.      *  @doNotIndexAll
  123.      */
  124.     public function addImages()
  125.     {
  126.         foreach array('HTML''Html''html''text'as $type )
  127.         {
  128.             foreach array(null'test-''test-'as $context )
  129.             {
  130.                 if $context )
  131.                 {
  132.                     $context .= $type '-' md5($context $type);
  133.                 }
  134.  
  135.                 $mail new Zend_Mail();
  136.                 $mail->setFromMage::getStoreConfig('trans_email/ident_general/email'))
  137.                         ->addTo(Mage::getStoreConfig('trans_email/ident_support/email'))
  138.                         ->setSubject('Test subject');
  139.  
  140.                 switch $type )
  141.                 {
  142.                     case 'HTML':
  143.                         $mail->setBodyHtml('<html><body>This is HTML with images.</body></html>');
  144.                         break;
  145.                         
  146.                     case 'Html':
  147.                         $mail->setBodyHtml('<html><body><img src="http://does.not.exits/does-not-exist.jpg" /></body></html>');
  148.                         break;
  149.                     
  150.                     case 'html':
  151.                         $mail->setBodyHtml('<html><body><img src="' Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN'frontend/default/default/images/logo.gif" /></body></html>');
  152.                         break;
  153.                         
  154.                     case 'text':
  155.                         $mail->setBodyText('This is a test email.');
  156.                         break;
  157.                 }
  158.  
  159.                 Mage::helper('emailimages')->addImages($mail$context);
  160.                 
  161.                 switch $type )
  162.                 {
  163.                     case 'html':
  164.                         if Mage::getStoreConfig('system/emailimages/enable') )
  165.                             $this->assertEquals(1$mail->getPartCount()'HTML email should have 1 attachment');
  166.                         else
  167.                             $this->assertEquals(0$mail->getPartCount()'HTML email should have no attachment if EmailImages has been disabled');
  168.                         break;
  169.         
  170.                     case 'HTML':
  171.                     case 'Html':
  172.                     case 'text':
  173.                         $this->assertEquals(0$mail->getPartCount()ucfirst($type' email should have no attachments');
  174.                         break;
  175.                 }
  176.             }
  177.         }
  178.     }
  179.     
  180.     /**
  181.      *  Test addImages() with cache turned on
  182.      *
  183.      *  @test
  184.      *  @loadFixture
  185.      *  @doNotIndexAll
  186.      */
  187.     public function addImagesCache()
  188.     {
  189.         $this->_overrideCacheCanUse();
  190.  
  191.         $this->addImages();
  192.     }
  193.     
  194.     /**
  195.      *  Test addImages() with the EmailImages extension disabled
  196.      *
  197.      *  @test
  198.      *  @loadFixture
  199.      *  @doNotIndexAll
  200.      */
  201.     public function addImagesDisabled()
  202.     {
  203.         $this->_overrideCacheCanUse();
  204.  
  205.         Mage::helper('emailimages')->addImages(new Zend_Mail());
  206.     }
  207.     
  208.     /**
  209.      *  Test addImages() with exception thrown
  210.      *
  211.      *  @test
  212.      *  @loadFixture
  213.      *  @doNotIndexAll
  214.      */
  215.     public function addImagesException()
  216.     {
  217.         $this->_overrideCacheCanUse();
  218.  
  219.         Mage::helper('emailimages')->addImages(new Zend_Mail()'test');
  220.     }
  221.     
  222.     /**
  223.      *  Test cleanCache()
  224.      *
  225.      *  @test
  226.      *  @doNotIndexAll
  227.      */
  228.     public function cleanCache()
  229.     {
  230.         Mage::helper('emailimages')->cleanCache();
  231.     }
  232.  
  233.     /**
  234.      *  Mage_Core_Model_Cache function canUse() replacement function.
  235.      *
  236.      *  @param  string  $typeCode 
  237.      *  @return boolean 
  238.      *
  239.      *  @see    addImagesCache(), addImagesDisabled(), addImagesException(),
  240.      *           ;Mage_Core::_Model_Cache()
  241.      */
  242.     public function Mage_Core_Model_Cache_canUse">Mage_Core_Model_Cache_canUse$typeCode )
  243.     {
  244.         if Mage::getStoreConfig('system/emailimages/enable') )
  245.         {
  246.             if Mage::getStoreConfig('test/emailimages/use_cache') )
  247.             {
  248.                 if Magentron_EmailImages_Helper_Data::CACHE_TYPE == $typeCode )
  249.                 {
  250.                     return true;
  251.                 }
  252.             }
  253.             elseif Mage::getStoreConfig('test/emailimages/throw_exception') )
  254.             {
  255.                 // when the extension has been enabled, we want to test an exception
  256.                 throw new Exception('dummy exception to get 100% code coverage on addImages()');
  257.             }
  258.         }
  259.         else
  260.         {
  261.             // when the extension has been disabled, getType() should not be called     
  262.             $this->fail('canUse() should not be called when the EmailImages extension has been disabled');
  263.         }
  264.                 
  265.         return false;
  266.     }
  267.  
  268.     /**
  269.      *  Run addImages() with ;Mage_Core::_Model_Cache() overriden.
  270.      */
  271.     protected function _overrideCacheCanUse()
  272.     {
  273.         $mock $this->getModelMock('core/cache'array('canUse'));
  274.  
  275.         $mock->expects($this->any())
  276.                 ->method('canUse')
  277.                 ->will($this->returnCallback(array($this'Mage_Core_Model_Cache_canUse')));
  278.  
  279.         $this->replaceByMock('model''core/cache'$mock);
  280.     }
  281. }

Documentation generated on Fri, 09 Oct 2015 03:37:08 +0200 by phpDocumentor 1.4.4