Performs "validation" on tweets. Originally written by {@link http://github.com/mikenz Mike Cochrane}, this is based on code by {@link http://github.com/mzsanford Matt Sanford} and heavily modified by {@link http://github.com/ngnpope Nick Pope}.
저자: Nick Pope (nick@nickpope.me.uk)
상속: extends Twitter_Regex
        echo '</ul>';
    }
    echo PHP_EOL;
    $pass_total += $pass_group;
    $fail_total += $fail_group;
    echo $browser ? '<p class="group">' : "   ";
    printf('Group Results: %d passes, %d failures', $pass_group, $fail_group);
    echo $browser ? '</p>' : "" . 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);
 }
예제 #3
0
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>' : "PASS";
        } else {
            $fail_group++;
            echo $browser ? '<span class="fail">FAIL</span>' : "FAIL";
            if ($browser) {
                echo '<pre>';
                echo 'Original: ' . htmlspecialchars($test['text'], ENT_QUOTES, 'UTF-8', false), PHP_EOL;
                echo 'Expected: ' . pretty_format($test['expected']), PHP_EOL;