[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/lib/exe/ -> css_at_import_less.test.php (source)

   1  <?php
   2  
   3  require_once  DOKU_INC.'lib/exe/css.php';
   4  
   5  class css_at_import_less_test extends DokuWikiTest {
   6  
   7      protected $file = '';
   8      protected $import = '';
   9  
  10      public function setUpFiles($subdir = '') {
  11  
  12          $dir = TMP_DIR . $subdir;
  13          if (!is_dir($dir)) {
  14              mkdir($dir, 0777, true);
  15          }
  16          if (!is_dir($dir)) {
  17              $this->markTestSkipped('Could not create directory.');
  18          }
  19  
  20          $this->file = tempnam($dir, 'css');
  21  
  22          $import = '';
  23          do {
  24              if ($import) unlink($import);
  25              $import = tempnam($dir, 'less');
  26              $ok = rename($import, $import.'.less');
  27          } while (!$ok);
  28  
  29          $this->import = $import.'.less';
  30      }
  31  
  32      private function csstest($input, $expected_css, $expected_less) {
  33          $location = "http://test.com/";
  34          io_saveFile($this->file, $input);
  35          $css = css_loadfile($this->file, $location);
  36          $less = css_parseless($css);
  37          $this->assertEquals($expected_css, $css);
  38          $this->assertEquals($expected_less, $less);
  39      }
  40  
  41      /**
  42       * makes proper relative path to be used in CSS @import
  43       * @param string $path
  44       * @return string
  45       */
  46      private function importPath($path) {
  47          if (isWindows()) {
  48              return preg_replace('#(^.*[\\\\])#','', $path);
  49          }
  50          return preg_replace('#(^.*[/])#','', $path);
  51      }
  52  
  53      public function test_basic() {
  54          $this->setUpFiles();
  55  
  56          $import = $this->importPath($this->import);
  57          $in_css = '@import "'.$import.'";';
  58          $in_less = '@foo: "bar";
  59  content: @foo;';
  60  
  61          $expected_css = '@import "/'.$import.'";';
  62          $expected_less = 'content: "bar";';
  63  
  64          io_saveFile($this->import, $in_less);
  65          $this->csstest($in_css, $expected_css, $expected_less);
  66      }
  67  
  68      public function test_subdirectory() {
  69          $this->setUpFiles('/foo/bar');
  70  
  71          $import = $this->importPath($this->import);
  72          $in_css = '@import "'.$import.'";';
  73          $in_less = '@foo: "bar";
  74  content: @foo;';
  75  
  76          $expected_css = isWindows() ? '@import "\\foo\\bar/'.$import.'";' : '@import "/foo/bar/'.$import.'";';
  77          $expected_less = 'content: "bar";';
  78  
  79          io_saveFile($this->import, $in_less);
  80          $this->csstest($in_css, $expected_css, $expected_less);
  81      }
  82  
  83      public function tearDown() {
  84          unlink($this->file);
  85          unlink($this->import);
  86          unset($this->file, $this->import);
  87      }
  88  }
  89  
  90  //Setup VIM: ex: et ts=4 sw=4 :