HashTagDetectionTests.php 3.67 KB
Newer Older
Brenda Wallace's avatar
Brenda Wallace committed
1 2 3 4 5 6 7 8
<?php

if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit();
}

define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
Evan Prodromou's avatar
Evan Prodromou committed
9
define('STATUSNET', true);
10
define('LACONICA', true);
Brenda Wallace's avatar
Brenda Wallace committed
11 12 13

require_once INSTALLDIR . '/lib/common.php';

14
class HashTagDetectionTests extends PHPUnit_Framework_TestCase
Brenda Wallace's avatar
Brenda Wallace committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
{
    /**
     * @dataProvider provider
     *
     */
    public function testProduction($content, $expected)
    {
        $rendered = common_render_text($content);
        $this->assertEquals($expected, $rendered);
    }

    static public function provider()
    {
        return array(
                     array('hello',
                           'hello'),
Craig Andrews's avatar
Craig Andrews committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44
                     array('#hello people',
                           '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span> people'),
                     array('"#hello" people',
                           '&quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
                     array('say "#hello" people',
                           'say &quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
                     array('say (#hello) people',
                           'say (#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>) people'),
                     array('say [#hello] people',
                           'say [#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>] people'),
                     array('say {#hello} people',
                           'say {#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>} people'),
                     array('say \'#hello\' people',
                           'say \'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>\' people'),
Brion Vibber's avatar
Brion Vibber committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

                     // Unicode legit letters
                     array('#éclair yummy',
                           '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('éclair'))) . '" rel="tag">éclair</a></span> yummy'),
                     array('#维基百科 zh.wikipedia!',
                           '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span> zh.wikipedia!'),
                     array('#Россия russia',
                           '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('Россия'))) . '" rel="tag">Россия</a></span> russia'),

                     // Unicode punctuators -- the ideographic "," separates the tag, just as "," does
                     array('#维基百科,zh.wikipedia!',
                           '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
                     array('#维基百科,zh.wikipedia!',
                           '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),

Brenda Wallace's avatar
Brenda Wallace committed
60 61 62 63
                     );
    }
}