You are here

class ScssUnitTest in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/tests/test_inc.php \ScssUnitTest

Hierarchy

Expanded class hierarchy of ScssUnitTest

File

phpsass/tests/test_inc.php, line 40

View source
class ScssUnitTest {
  protected $sass;
  public function __construct() {
    require_once dirname(__FILE__) . '/../sass/SassParser.php';
    $this->sass = new SassParser(array(
      'extensions' => array(
        'compass' => array(),
      ),
      'style' => SassRenderer::STYLE_EXPANDED,
      'syntax' => SassFile::SCSS,
    ));
  }
  public function assertScss($scss, $css) {
    $out = '<table class="testunit">';
    $out .= '<tr>';
    $out .= '<th>source Scss</th>';
    $out .= '<th>Result</th>';
    $out .= '<th>Output css</th>';
    $out .= '<th>expected css</th>';
    $out .= '</tr>';
    if (!is_array($scss)) {
      $scss = array(
        $scss,
      );
      $css = array(
        $css,
      );
    }
    for ($i = 0, $k = count($scss); $i < $k; $i++) {
      $css[$i] = trim($css[$i]);
      try {
        $result = $this->sass
          ->toCss($scss[$i], false);
        $result = trim($result);
      } catch (Exception $e) {
        $result = $e
          ->getMessage();
      }
      $css[$i] = str_replace(array(
        "\r\n",
        "\n\r",
        "\r",
      ), "\n", $css[$i]);
      $pass = $css[$i] == $result;
      $out .= '<tr>';
      $out .= '<td><pre>' . htmlspecialchars($scss[$i]) . '</pre></td>';
      $out .= '<td style="background-color:' . ($pass ? '#CFC' : '#FCC') . ';">' . ($pass ? '<h5>Pass!</h5>' : '<h5>Failed!</h5>') . '</td>';
      $out .= '<td style="background-color:' . ($pass ? '#CFC' : '#FCC') . ';">' . '<pre>' . htmlspecialchars($result) . '</pre></td>';
      $out .= '<td><pre>' . htmlspecialchars($css[$i]) . '</pre></td>';
      $out .= '</tr>';
    }
    $out .= '</table>';
    echo $out;
  }
  public function run() {
    $methods = get_class_methods($this);
    foreach ($methods as $method) {
      if (substr($method, 0, 4) == "test") {
        echo '<h3>' . $method . '</h3>';
        $this
          ->{$method}();
      }
    }
  }

}

Members