123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?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__) . '/..'));
- define('GNUSOCIAL', true);
- define('STATUSNET', true);
- require_once INSTALLDIR . '/lib/common.php';
- class NicknameTest extends PHPUnit_Framework_TestCase
- {
-
- public function testBasic($input, $expected, $expectedException=null)
- {
- $exception = null;
- $normalized = false;
- try {
- $normalized = Nickname::normalize($input);
- } catch (NicknameException $e) {
- $exception = $e;
- }
- if ($expected === false) {
- if ($expectedException) {
- if ($exception) {
- $stuff = get_class($exception) . ': ' . $exception->getMessage();
- } else {
- $stuff = var_export($exception, true);
- }
- $this->assertTrue($exception && $exception instanceof $expectedException,
- "invalid input '$input' expected to fail with $expectedException, " .
- "got $stuff");
- } else {
- $this->assertTrue($normalized == false,
- "invalid input '$input' expected to fail");
- }
- } else {
- $msg = "normalized input nickname '$input' expected to normalize to '$expected', got ";
- if ($exception) {
- $msg .= get_class($exception) . ': ' . $exception->getMessage();
- } else {
- $msg .= "'$normalized'";
- }
- $this->assertEquals($expected, $normalized, $msg);
- }
- }
-
- public function testAtReply($input, $expected, $expectedException=null)
- {
- if ($expected == false) {
-
- } else {
- $text = "@{$input} awesome! :)";
- $matches = common_find_mentions_raw($text);
- $this->assertEquals(1, count($matches));
- $this->assertEquals($expected, Nickname::normalize($matches[0][0]));
- }
- }
- static public function provider()
- {
- return array(
- array('evan', 'evan'),
-
- array('Evan', 'evan'),
- array('EVAN', 'evan'),
- array('ev_an', 'evan'),
- array('E__V_an', 'evan'),
- array('evan1', 'evan1'),
- array('evan_1', 'evan1'),
- array('0x20', '0x20'),
- array('1234', '1234'),
- array('12__34', '1234'),
-
- array('^#@&^#@', false, 'NicknameInvalidException'),
- array('ev.an', false, 'NicknameInvalidException'),
- array('ev/an', false, 'NicknameInvalidException'),
- array('ev an', false, 'NicknameInvalidException'),
- array('ev-an', false, 'NicknameInvalidException'),
-
-
-
-
- array('évan', false, 'NicknameInvalidException'),
- array('Évan', false, 'NicknameInvalidException'),
-
- array('', false, 'NicknameEmptyException'),
- array('___', false, 'NicknameEmptyException'),
- array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'),
- array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'),
- array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'),
- );
- }
- }
|