Initial commit: apps.supersam24.ru

This commit is contained in:
root committed 2026-10-22 00:04:27 +03:00
commit e955e1da36
6566 files changed
+1271095

No files matched your search

@@ -0,0 +1,31 @@
<?php
namespace Aptoma\Twig\Extension\MarkdownEngine;
use Aptoma\Twig\Extension\MarkdownExtensionTest;
require_once(__DIR__ . '/../MarkdownExtensionTest.php');
/**
* Class GitHubMarkdownEngineTest
*
* @author Lukas W <lukaswhl@gmail.com>
*/
class GitHubMarkdownEngineTest extends MarkdownExtensionTest
{
public function getParseMarkdownTests()
{
return array(
array('{{ "# Main Title"|markdown }}', '<h1>Main Title</h1>'),
array('{{ content|markdown }}', '<h1>Main Title</h1>', array('content' => '# Main Title')),
// Check if GFM is working
array('{{ "@aptoma"|markdown }}',
'<p><a href="https://github.com/aptoma" class="user-mention">@aptoma</a></p>'),
);
}
protected function getEngine()
{
return new GitHubMarkdownEngine();
}
}
@@ -0,0 +1,23 @@
<?php
namespace Aptoma\Twig\Extension\MarkdownEngine;
use Aptoma\Twig\Extension\MarkdownExtensionTest;
// Require parent class if not autoloaded
if (!class_exists('\Aptoma\Twig\Extension\MarkdownExtensionTest')) {
require_once(__DIR__ . '/../MarkdownExtensionTest.php');
}
/**
* Class PHPLeagueCommonMarkEngineTest
*
* @author Casey McLaughlin <caseyamcl@gmail.com>
*/
class PHPLeagueCommonMarkEngineTest extends MarkdownExtensionTest
{
protected function getEngine()
{
return new PHPLeagueCommonMarkEngine();
}
}
@@ -0,0 +1,32 @@
<?php
namespace Aptoma\Twig\Extension\MarkdownEngine;
use Aptoma\Twig\Extension\MarkdownExtensionTest;
// Require parent class if not autoloaded
if (!class_exists('\Aptoma\Twig\Extension\MarkdownExtensionTest')) {
require_once(__DIR__ . '/../MarkdownExtensionTest.php');
}
/**
* Class ParsedownEngineTest
*
* @author Sébastien Lourseau <https://github.com/SebLours>
*/
class ParsedownEngineTest extends MarkdownExtensionTest
{
public function getParseMarkdownTests()
{
return array(
array('{{ "# Main Title"|markdown }}', '<h1>Main Title</h1>'),
array('{{ content|markdown }}', '<h1>Main Title</h1>', array('content' => '# Main Title')),
array('{% markdown %}{{ content }}{% endmarkdown %}', '<h1>Main Title</h1>', array('content' => '# Main Title'))
);
}
protected function getEngine()
{
return new ParsedownEngine();
}
}
@@ -0,0 +1,41 @@
<?php
namespace Aptoma\Twig\Extension;
use Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine;
/**
* @author Gunnar Liun <gunnar@aptoma.com>
*/
class MarkdownExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getParseMarkdownTests
*/
public function testParseMarkdown($template, $expected, $context = array())
{
$this->assertEquals($expected, $this->getTemplate($template)->render($context));
}
public function getParseMarkdownTests()
{
return array(
array('{{ "# Main Title"|markdown }}', '<h1>Main Title</h1>' . PHP_EOL),
array('{{ content|markdown }}', '<h1>Main Title</h1>' . PHP_EOL, array('content' => '# Main Title'))
);
}
protected function getEngine()
{
return new MichelfMarkdownEngine();
}
protected function getTemplate($template)
{
$loader = new \Twig_Loader_Array(array('index' => $template));
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
$twig->addExtension(new MarkdownExtension($this->getEngine()));
return $twig->loadTemplate('index');
}
}
@@ -0,0 +1,109 @@
<?php
namespace Aptoma\Twig\TokenParser;
use Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine;
use Aptoma\Twig\Node\MarkdownNode;
/**
* @author Gunnar Lium <gunnar@aptoma.com>
*/
class MarkdownTokenParserTest extends \Twig_Test_NodeTestCase
{
public function testConstructor()
{
$body = new \Twig_Node(array(new \Twig_Node_Text("#Title\n\nparagraph\n", 1)));
$node = new MarkdownNode($body, 1);
$this->assertEquals($body, $node->getNode('body'));
}
/**
* Test that the generated code actually do what we expect
*
* The contents of this test is the same that we write in the compile method.
* This requires manual synchronization, which we should probably not rely on.
*/
public function testMarkdownPrepareBehavior()
{
$body = " #Title\n\n paragraph\n\n code";
$bodyPrepared = "#Title\n\nparagraph\n\n code";
ob_start();
echo $body;
$content = ob_get_clean();
preg_match("/^\s*/", $content, $matches);
$lines = explode("\n", $content);
$content = preg_replace('/^' . $matches[0]. '/', "", $lines);
$content = join("\n", $content);
// Assert prepared content looks right
$this->assertEquals($bodyPrepared, $content);
// Assert Markdown output
$expectedOutput = "<h1>Title</h1>\n\n<p>paragraph</p>\n\n<pre><code>code\n</code></pre>\n";
$this->assertEquals($expectedOutput, $this->getEngine()->transform($content));
}
/**
* Test that the generated code looks as expected
*
* @dataProvider getTests
*/
public function testCompile($node, $source, $environment = null)
{
parent::testCompile($node, $source, $environment);
}
protected function getEngine()
{
return new MichelfMarkdownEngine();
}
public function getTests()
{
$tests = array();
$body = new \Twig_Node(array(new \Twig_Node_Text("#Title\n\nparagraph\n", 1)));
$node = new MarkdownNode($body, 1);
$tests['simple text'] = array($node, <<<EOF
// line 1
ob_start();
echo "#Title
paragraph
";
\$content = ob_get_clean();
preg_match("/^\s*/", \$content, \$matches);
\$lines = explode("\\n", \$content);
\$content = preg_replace('/^' . \$matches[0]. '/', "", \$lines);
\$content = join("\\n", \$content);
echo \$this->env->getTokenParsers()->getTokenParser('markdown')->getEngine()->transform(\$content);
EOF
);
$body = new \Twig_Node(array(new \Twig_Node_Text(" #Title\n\n paragraph\n\n code\n", 1)));
$node = new MarkdownNode($body, 1);
$tests['text with leading indent'] = array($node, <<<EOF
// line 1
ob_start();
echo " #Title
paragraph
code
";
\$content = ob_get_clean();
preg_match("/^\s*/", \$content, \$matches);
\$lines = explode("\\n", \$content);
\$content = preg_replace('/^' . \$matches[0]. '/', "", \$lines);
\$content = join("\\n", \$content);
echo \$this->env->getTokenParsers()->getTokenParser('markdown')->getEngine()->transform(\$content);
EOF
);
return $tests;
}
}