echo '</ul>'; } echo PHP_EOL; $pass_total += $pass_group; $fail_total += $fail_group; echo $browser ? '<p class="group">' : " [1;33m"; printf('Group Results: %d passes, %d failures', $pass_group, $fail_group); echo $browser ? '</p>' : "[0m" . PHP_EOL; echo PHP_EOL; } output_h2('Hit Highlighter Conformance'); # Load the test data. $data = Yaml::parse($DATA . '/hit_highlighting.yml'); # Define the functions to be tested. $functions = array('plain_text' => 'highlight', 'with_links' => 'highlight'); $highlighter = Twitter_HitHighlighter::create(); # Perform testing. foreach ($data['tests'] as $group => $tests) { output_h3('Test Group - ' . ucfirst(str_replace('_', ' ', $group))); if (!array_key_exists($group, $functions)) { output_skip_test(); continue; } $function = $functions[$group]; $pass_group = 0; $fail_group = 0; if ($browser) { echo '<ul>', PHP_EOL; } foreach ($tests as $test) { echo $browser ? '<li>' : ' - ';
/** * @dataProvider addHitHighlightingProvider */ public function testAddHitHighlighting($description, $text, $hits, $expected) { $extracted = Twitter_HitHighlighter::create($text)->addHitHighlighting($hits); $this->assertSame($expected, $extracted, $description); }
echo $browser ? '<p>' : " [1;35m"; echo 'Skipping Test...'; echo $browser ? '</p>' : "[0m" . PHP_EOL; echo PHP_EOL; continue; } $function = $functions[$group]; $pass_group = 0; $fail_group = 0; if ($browser) { echo '<ul>', PHP_EOL; } foreach ($tests as $test) { echo $browser ? '<li>' : ' - '; echo $test['description'], ' ... '; $highlighted = Twitter_HitHighlighter::create($test['text'])->{$function}($test['hits']); if ($test['expected'] == $highlighted) { $pass_group++; echo $browser ? '<span class="pass">PASS</span>' : "[1;32mPASS[0m"; } else { $fail_group++; echo $browser ? '<span class="fail">FAIL</span>' : "[1;31mFAIL[0m"; if ($browser) { echo '<pre>'; echo 'Original: ' . htmlspecialchars($test['text'], ENT_QUOTES, 'UTF-8', false), PHP_EOL; echo 'Expected: ' . pretty_format($test['expected']), PHP_EOL; echo 'Actual: ' . pretty_format($highlighted); echo '</pre>'; } else { echo PHP_EOL, PHP_EOL; echo ' Original: ' . $test['text'], PHP_EOL;
\$hits = array(array(70, 77), array(101, 108)); \$html = Twitter_HitHighlighter::create(\$tweet) ->addHitHighlighting(\$hits); echo \$html; EOPHP; if ($browser) { echo '<h3>Source</h3>', PHP_EOL; echo '<pre class="source">'; highlight_string($code); echo '</pre>', PHP_EOL; } else { echo 'Source:', PHP_EOL, PHP_EOL; echo $code; echo PHP_EOL, PHP_EOL; } $html = Twitter_HitHighlighter::create($tweet)->addHitHighlighting(array(array(70, 77), array(101, 108))); if ($browser) { echo '<h3>Markup</h3>', PHP_EOL; echo '<pre class="markup"><code>'; echo htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false); echo '</code></pre>', PHP_EOL; } else { echo 'Markup:', PHP_EOL, PHP_EOL; echo wordwrap(htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false)); echo PHP_EOL, PHP_EOL; } if ($browser) { echo '<h3>Output</h3>', PHP_EOL; echo '<div class="output">'; echo $html; echo '</div>', PHP_EOL;
\$hits = array(array(70, 77), array(101, 108)); \$html = Twitter_HitHighlighter::create() ->highlight(\$tweet, \$hits); echo \$html; EOPHP; if ($browser) { echo '<h3>Source</h3>', PHP_EOL; echo '<pre class="source">'; highlight_string($code); echo '</pre>', PHP_EOL; } else { echo 'Source:', PHP_EOL, PHP_EOL; echo $code; echo PHP_EOL, PHP_EOL; } $html = Twitter_HitHighlighter::create()->highlight($tweet, array(array(70, 77), array(101, 108))); if ($browser) { echo '<h3>Markup</h3>', PHP_EOL; echo '<pre class="markup"><code>'; echo htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false); echo '</code></pre>', PHP_EOL; } else { echo 'Markup:', PHP_EOL, PHP_EOL; echo wordwrap(htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false)); echo PHP_EOL, PHP_EOL; } if ($browser) { echo '<h3>Output</h3>', PHP_EOL; echo '<div class="output">'; echo $html; echo '</div>', PHP_EOL;