]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/NicknameTest.php
Start on some nickname-validation test cases: several of these fail right now because...
[quix0rs-gnu-social.git] / tests / NicknameTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
10 define('LACONICA', true);
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 /**
15  * Test cases for nickname validity and normalization.
16  */
17 class NicknameTest extends PHPUnit_Framework_TestCase
18 {
19     /**
20      * @dataProvider provider
21      *
22      */
23     public function testBasic($input, $expected)
24     {
25         $matches = array();
26         // First problem: this is all manual, wtf!
27         if (preg_match('/^([' . NICKNAME_FMT . ']{1,64})$/', $input, $matches)) {
28             $norm = common_canonical_nickname($matches[1]);
29             $this->assertEquals($expected, $norm, "normalized input nickname: $input -> $norm");
30         } else {
31             $this->assertEquals($expected, false, "invalid input nickname: $input");
32         }
33     }
34
35     static public function provider()
36     {
37         return array(
38                      array('evan', 'evan'),
39                      array('Evan', 'evan'),
40                      array('EVAN', 'evan'),
41                      array('ev_an', 'evan'),
42                      array('ev.an', 'evan'),
43                      array('ev/an', false),
44                      array('ev an', false),
45                      array('ev-an', false),
46                      array('évan', false), // so far...
47                      array('Évan', false), // so far...
48                      array('evan1', 'evan1'),
49                      array('evan_1', 'evan1'),
50                      );
51     }
52 }