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('Validation Conformance'); # Load the test data. $data = Yaml::parse($DATA . '/validate.yml'); # Define the functions to be tested. $functions = array('tweets' => 'isValidTweetText', 'usernames' => 'isValidUsername', 'lists' => 'isValidList', 'hashtags' => 'isValidHashtag', 'urls' => 'isValidURL', 'urls_without_protocol' => 'isValidURL', 'lengths' => 'getTweetLength'); $validator = Twitter_Validation::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 getTweetLengthProvider */ public function testGetLength($description, $text, $expected) { $validated = Twitter_Validation::create($text)->getLength(); $this->assertSame($expected, $validated, $description); }
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>' : ' - '; echo isset($test['description']) ? $test['description'] : '???', ' ... '; $validator = Twitter_Validation::create($test['text']); if ($group === 'urls_without_protocol') { $validated = $validator->{$function}(true, false); } else { $validated = $validator->{$function}(); } if ($test['expected'] == $validated) { $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;