/**
  * make this its own set of tests
  */
 public function testCountSplit()
 {
     $css = "\n\t\t.selector-1 { display:none }\n\t\t.selector-2,.selector-3 { display:none }\n\t\t.selector-4 { display:none }\n\t\t.selector-4 { display:block }\n\t\t.selector-5 { display:none }\n\t\t";
     $splitter = new Splitter();
     self::assertEquals('.selector-2,.selector-3 { display:none }', $splitter->split($css, 2, 2));
     self::assertEquals('.selector-4 { display:none }.selector-4 { display:block }', $splitter->split($css, 3, 2));
 }
 /**
  * Chop up any local CSS files that are too big and add an IE conditional
  *
  * @param string $strBuffer
  * @param string $strTemplate
  *
  * @return string $strBuffer
  */
 public function run($strBuffer, $strTemplate)
 {
     $ua = \Environment::get('agent');
     if (stripos($strTemplate, 'fe_') !== false && $ua->browser == 'ie') {
         $objDOM = new \DOMDocument();
         $objDOM->loadHTML($strBuffer);
         $objCSSLinks = $objDOM->getElementsByTagName('link');
         foreach ($objCSSLinks as $link) {
             //Local files only
             if (strpos($link->getAttribute('href'), 'assets/css/') !== false) {
                 //Replace ASSETS_URL
                 $strFile = str_replace(TL_ASSETS_URL, '', $link->getAttribute('href'));
                 $objFile = new \File($strFile);
                 $strContent = $objFile->getContent();
                 //Split up into chunklets
                 $splitter = new Splitter();
                 $count = $splitter->countSelectors($strContent) - 4095;
                 if ($count > 0) {
                     $part = 2;
                     for ($i = $count; $i > 0; $i -= 4095) {
                         $strFilename = 'assets/css/' . $objFile->filename . '-ie9-' . $part . '.css';
                         if (!file_exists(TL_ROOT . '/' . $strFilename)) {
                             //Write content
                             $strChunkContent = $splitter->split($strContent, $part);
                             $objNewFile = new \File($strFilename);
                             $objNewFile->write($strChunkContent);
                             $objNewFile->close();
                         }
                         //Add IE Conditional
                         foreach ($objDOM->getElementsByTagName('head') as $head) {
                             $strComment = '[if lte IE 9]><link rel="stylesheet" href="';
                             $strComment .= TL_ASSETS_URL . $strFilename . '"><![endif]';
                             $objChildNode = new \DOMComment($strComment);
                             $head->appendChild($objChildNode);
                         }
                         $part++;
                     }
                 }
             }
         }
         $strBuffer = $objDOM->saveHTML();
     }
     return $strBuffer;
 }