Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
IntegrationTestCase.php
001 <?php
002
003 /*
004 * This file is part of Twig.
005 *
006 * (c) 2010 Fabien Potencier
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 /**
013 * Integration test helper
014 *
015 * @author Fabien Potencier <fabien@symfony.com>
016 * @author Karma Dordrak <drak@zikula.org>
017 */
018 abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
019 {
020 abstract protected function getExtensions();
021 abstract protected function getFixturesDir();
022
023 /**
024 * @dataProvider getTests
025 */
026 public function testIntegration($file, $message, $condition, $templates, $exception, $outputs)
027 {
028 $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
029 }
030
031 public function getTests()
032 {
033 $fixturesDir = realpath($this->getFixturesDir());
034 $tests = array();
035
036 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
037 if (!preg_match('/\.test$/', $file)) {
038 continue;
039 }
040
041 $test = file_get_contents($file->getRealpath());
042
043 if (preg_match('/
044 --TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) {
045 $message = $match[1];
046 $condition = $match[2];
047 $templates = $this->parseTemplates($match[3]);
048 $exception = $match[5];
049 $outputs = array(array(null, $match[4], null, ''));
050 } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
051 $message = $match[1];
052 $condition = $match[2];
053 $templates = $this->parseTemplates($match[3]);
054 $exception = false;
055 preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER);
056 } else {
057 throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file)));
058 }
059
060 $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs);
061 }
062
063 return $tests;
064 }
065
066 protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs)
067 {
068 if ($condition) {
069 eval('$ret = '.$condition.';');
070 if (!$ret) {
071 $this->markTestSkipped($condition);
072 }
073 }
074
075 $loader = new Twig_Loader_Array($templates);
076
077 foreach ($outputs as $match) {
078 $config = array_merge(array(
079 'cache' => false,
080 'strict_variables' => true,
081 ), $match[2] ? eval($match[2].';') : array());
082 $twig = new Twig_Environment($loader, $config);
083 $twig->addGlobal('global', 'global');
084 foreach ($this->getExtensions() as $extension) {
085 $twig->addExtension($extension);
086 }
087
088 try {
089 $template = $twig->loadTemplate('index.twig');
090 } catch (Exception $e) {
091 if (false !== $exception) {
092 $this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
093
094 return;
095 }
096
097 if ($e instanceof Twig_Error_Syntax) {
098 $e->setTemplateFile($file);
099
100 throw $e;
101 }
102
103 throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e);
104 }
105
106 try {
107 $output = trim($template->render(eval($match[1].';')), "\n ");
108 } catch (Exception $e) {
109 if (false !== $exception) {
110 $this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
111
112 return;
113 }
114
115 if ($e instanceof Twig_Error_Syntax) {
116 $e->setTemplateFile($file);
117 } else {
118 $e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e);
119 }
120
121 $output = trim(sprintf('%s: %s', get_class($e), $e->getMessage()));
122 }
123
124 if (false !== $exception) {
125 list($class, ) = explode(':', $exception);
126 $this->assertThat(NULL, new PHPUnit_Framework_Constraint_Exception($class));
127 }
128
129 $expected = trim($match[3], "\n ");
130
131 if ($expected != $output) {
132 echo 'Compiled template that failed:';
133
134 foreach (array_keys($templates) as $name) {
135 echo "Template: $name\n";
136 $source = $loader->getSource($name);
137 echo $twig->compile($twig->parse($twig->tokenize($source, $name)));
138 }
139 }
140 $this->assertEquals($expected, $output, $message.' (in '.$file.')');
141 }
142 }
143
144 protected static function parseTemplates($test)
145 {
146 $templates = array();
147 preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER);
148 foreach ($matches as $match) {
149 $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2];
150 }
151
152 return $templates;
153 }
154 }
155