Example #1
0
 /**
  * @expectedException EmulateBugException
  */
 public function testBrokenInclude()
 {
     get_php_code(__DIR__ . '/../templates/auxiliary/include-exception.jade');
 }
Example #2
0
function get_test_result($name, $verbose = false, $moreVerbose = false)
{
    $mergeSpace = IGNORE_INDENT && strpos($name, 'indent.') === false;
    $path = TEMPLATES_DIRECTORY . DIRECTORY_SEPARATOR . $name;
    $expectedHtml = @file_get_contents($path . '.html');
    if ($expectedHtml === false) {
        if ($verbose) {
            echo "! sample for test '{$name}' not found.\n";
        }
        return array(false, array($name, null, "! sample for test '{$name}' not found.\n"));
    }
    if ($verbose) {
        echo "* rendering test '{$name}'\n";
    }
    try {
        $new = get_php_code($path . '.jade');
    } catch (Exception $err) {
        if ($verbose) {
            echo "! FATAL: php exception: " . str_replace("\n", "\n\t", $err) . "\n";
        }
        return array(false, array($name, null, "! FATAL: php exception: " . str_replace("\n", "\n\t", $err) . "\n"));
    }
    if (is_null($new)) {
        return array(false, array($name, null, "! FATAL: " . $path . ".jade returns null\n"));
    }
    $actualHtml = get_generated_html($new);
    $from = array("'", "\r", "<!DOCTYPEhtml>");
    $to = array('"', '', '');
    if ($mergeSpace) {
        array_push($from, "\n", "\t", " ");
        array_push($to, '', '', '');
    }
    $expectedHtml = preg_replace_callback('`class\\s*=\\s*(["\'])([^"\']+)\\1`', 'orderWords', $expectedHtml);
    $actualHtml = preg_replace_callback('`class\\s*=\\s*(["\'])([^"\']+)\\1`', 'orderWords', $actualHtml);
    if ($mergeSpace) {
        $expectedHtml = preg_replace('`(?<=[\'"])\\s(?=>)|(?<=[a-zA-Z0-9:])\\s(?=(>|\\s[a-zA-Z0-9:]))`', '', $expectedHtml);
        $actualHtml = preg_replace('`(?<=[\'"])\\s(?=>)|(?<=[a-zA-Z0-9:])\\s(?=(>|\\s[a-zA-Z0-9:]))`', '', $actualHtml);
    }
    $minifiedExpectedHtml = str_replace($from, $to, trim($expectedHtml));
    $minifiedActualHtml = str_replace($from, $to, trim($actualHtml));
    $result = array($name, $minifiedExpectedHtml, $minifiedActualHtml);
    if (strcmp($minifiedExpectedHtml, $minifiedActualHtml)) {
        if ($verbose) {
            include_once __DIR__ . '/diff.php';
            $actualHtml = preg_replace('`(\\r\\n|\\r|\\n)([\\t ]*(\\r\\n|\\r|\\n))+`', "\n", $actualHtml);
            $expectedHtml = preg_replace('`(\\r\\n|\\r|\\n)([\\t ]*(\\r\\n|\\r|\\n))+`', "\n", $expectedHtml);
            echo Diff::toString(Diff::compare($expectedHtml, $actualHtml)) . "\n";
            /*
            echo "  Expected: $expectedHtml\n";
            echo "  Actual  : $actualHtml\n\n";
            */
        }
        if ($moreVerbose) {
            echo "  PHP     : " . compile_php($name);
        }
        return array(false, $result);
    }
    return array(true, $result);
}
Example #3
0
 public function testInclude()
 {
     $this->assertSame('<div class="alert alert-danger">Page not found.</div>', trim(get_php_code('include a/file/with/a.pug')));
     $this->assertSame('<div class="alert alert-danger">Page not found.</div>', trim(get_php_code('include a/file/with/an.extension')));
 }