3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4 print "This script must be run from the command line\n";
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true); // compatibility
12 require_once INSTALLDIR . '/lib/common.php';
15 * Test cases for nickname validity and normalization.
17 class NicknameTest extends PHPUnit_Framework_TestCase
20 * Basic test using Nickname::normalize()
22 * @dataProvider provider
24 public function testBasic($input, $expected, $expectedException=null)
29 $normalized = Nickname::normalize($input);
30 } catch (NicknameException $e) {
34 if ($expected === false) {
35 if ($expectedException) {
37 $stuff = get_class($exception) . ': ' . $exception->getMessage();
39 $stuff = var_export($exception, true);
41 $this->assertTrue($exception && $exception instanceof $expectedException,
42 "invalid input '$input' expected to fail with $expectedException, " .
45 $this->assertTrue($normalized == false,
46 "invalid input '$input' expected to fail");
49 $msg = "normalized input nickname '$input' expected to normalize to '$expected', got ";
51 $msg .= get_class($exception) . ': ' . $exception->getMessage();
53 $msg .= "'$normalized'";
55 $this->assertEquals($expected, $normalized, $msg);
60 * Test on the regex matching used in common_find_mentions
61 * (testing on the full notice rendering is difficult as it needs
62 * to be able to pull from global state)
64 * @dataProvider provider
66 public function testAtReply($input, $expected, $expectedException=null)
68 if ($expected == false) {
71 $text = "@{$input} awesome! :)";
72 $matches = common_find_mentions_raw($text);
73 $this->assertEquals(1, count($matches));
74 $this->assertEquals($expected, Nickname::normalize($matches[0][0]));
78 static public function provider()
81 array('evan', 'evan'),
83 // Case and underscore variants
84 array('Evan', 'evan'),
85 array('EVAN', 'evan'),
86 array('ev_an', 'evan'),
87 array('E__V_an', 'evan'),
88 array('evan1', 'evan1'),
89 array('evan_1', 'evan1'),
90 array('0x20', '0x20'),
91 array('1234', '1234'), // should this be allowed though? :)
92 array('12__34', '1234'),
94 // Some (currently) invalid chars...
95 array('^#@&^#@', false, 'NicknameInvalidException'), // all invalid :D
96 array('ev.an', false, 'NicknameInvalidException'),
97 array('ev/an', false, 'NicknameInvalidException'),
98 array('ev an', false, 'NicknameInvalidException'),
99 array('ev-an', false, 'NicknameInvalidException'),
101 // Non-ASCII letters; currently not allowed, in future
102 // we'll add them at least with conversion to ASCII.
103 // Not much use until we have storage of display names,
105 array('évan', false, 'NicknameInvalidException'), // so far...
106 array('Évan', false, 'NicknameInvalidException'), // so far...
109 array('', false, 'NicknameEmptyException'),
110 array('___', false, 'NicknameEmptyException'),
111 array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars
112 array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'), // the _ is too long...
113 array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long