Esempio n. 1
0
 /**
  * test the Pug alias
  */
 public function testPugAlias()
 {
     $jade = new Jade();
     $pug = new Pug();
     $this->assertSame($jade->getOption('stream'), 'jade.stream');
     $this->assertSame($pug->getOption('stream'), 'pug.stream');
     $this->assertSame($pug->render('p Hello'), '<p>Hello</p>');
     $this->assertSame($pug->getExtension(), '.pug');
     $this->assertTrue(in_array('.pug', $pug->getExtensions()));
     $jade = new Jade(array('extension' => '.foo'));
     $this->assertSame($jade->getExtension(), '.foo');
     $this->assertFalse(in_array('.pug', $jade->getExtensions()));
     $this->assertTrue(in_array('.foo', $jade->getExtensions()));
     $jade->setOption('extension', array('.jade', '.pug'));
     $this->assertSame($jade->getExtension(), '.jade');
     $this->assertFalse(in_array('.foo', $jade->getExtensions()));
     $this->assertTrue(in_array('.jade', $jade->getExtensions()));
     $this->assertTrue(in_array('.pug', $jade->getExtensions()));
     $jade->setOption('extension', array());
     $this->assertSame($jade->getExtension(), '');
     $this->assertFalse(in_array('', $jade->getExtensions()));
     $this->assertFalse(in_array('.foo', $jade->getExtensions()));
     $this->assertFalse(in_array('.jade', $jade->getExtensions()));
     $this->assertFalse(in_array('.pug', $jade->getExtensions()));
     $jade->setOption('extension', '.pug');
     $this->assertSame($jade->getExtension(), '.pug');
     $this->assertFalse(in_array('', $jade->getExtensions()));
     $this->assertFalse(in_array('.foo', $jade->getExtensions()));
     $this->assertFalse(in_array('.jade', $jade->getExtensions()));
     $this->assertTrue(in_array('.pug', $jade->getExtensions()));
 }
Esempio n. 2
0
    public function testFilterAutoload()
    {
        $jade = new Jade();
        $this->assertFalse($jade->hasFilter('foo-bar'));
        spl_autoload_register(function ($name) {
            $name = explode('\\', $name);
            $file = __DIR__ . '/../lib/' . end($name) . 'Filter.php';
            if (file_exists($file)) {
                include_once $file;
            }
        });
        $jade->setOption('filterAutoLoad', false);
        $this->assertFalse($jade->hasFilter('foo-bar'));
        $this->assertSame($jade->getFilter('foo-bar'), null);
        $jade->setOption('filterAutoLoad', true);
        $this->assertTrue($jade->hasFilter('foo-bar'));
        $this->assertSame($jade->getFilter('foo-bar'), 'Jade\\Filter\\FooBar');
        $actual = $jade->render('
div
    p
        :foo-bar
            I\'m so small :(
');
        $expected = '<div><p>I\'M SO TALL :)</p></div>';
        $this->assertSame(preg_replace('`\\s`', '', $expected), preg_replace('`\\s`', '', $actual), 'Autoloaded filter');
    }
Esempio n. 3
0
 public function testBadCustomKeywordOptionType()
 {
     $jade = new Jade();
     $jade->setOption('customKeywords', new BadOptionType());
     $jade->addKeyword('foo', function () {
         return 'foo';
     });
     $this->assertSame('foo', $jade->render('foo'));
 }
Esempio n. 4
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionCode 3
  */
 public function testSetInvalidOption()
 {
     $jade = new Jade();
     $jade->setOption('i-do-not-exists', 'wrong');
 }
Esempio n. 5
0
    /**
     * allowMixinOverride setting test
     */
    public function testRestrictedScope()
    {
        $template = '
mixin foo()
  if isset($bar)
    h1=bar
  else
    h1 Not found
  block

- bar="Hello"

+foo
  if isset($bar)
    h2=bar
  else
    h2 Not found
';
        $jade = new Jade(array('restrictedScope' => true));
        $actual = $jade->render($template);
        $expected = '<h1>Not found</h1><h2>Not found</h2>';
        $this->assertSame(static::rawHtml($actual), static::rawHtml($expected), 'Restricted scope enabled');
        $jade->setOption('restrictedScope', false);
        $actual = $jade->render($template);
        $expected = '<h1>Hello</h1><h2>Hello</h2>';
        $this->assertSame(static::rawHtml($actual), static::rawHtml($expected), 'Restricted scope disabled');
    }