summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-11-29 11:31:33 -0800
committerBrion Vibber <brion@pobox.com>2010-11-29 11:31:33 -0800
commitb7e0078d1078c045c2f609d948905e73eb184add (patch)
tree3daf61ea7ad15d5f3695a5b44cd3bc9cf4371c50 /tests
parent6c4e5a89c1dd15bd9b408dc3ef257fc16551ab0b (diff)
Start on some nickname-validation test cases: several of these fail right now because we had regressions in 0.8 or 0.9 where we lost normalization of uppercase and some other chars.
Diffstat (limited to 'tests')
-rw-r--r--tests/NicknameTest.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/NicknameTest.php b/tests/NicknameTest.php
new file mode 100644
index 000000000..95af94098
--- /dev/null
+++ b/tests/NicknameTest.php
@@ -0,0 +1,52 @@
+<?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('STATUSNET', true);
+define('LACONICA', true);
+
+require_once INSTALLDIR . '/lib/common.php';
+
+/**
+ * Test cases for nickname validity and normalization.
+ */
+class NicknameTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider provider
+ *
+ */
+ public function testBasic($input, $expected)
+ {
+ $matches = array();
+ // First problem: this is all manual, wtf!
+ if (preg_match('/^([' . NICKNAME_FMT . ']{1,64})$/', $input, $matches)) {
+ $norm = common_canonical_nickname($matches[1]);
+ $this->assertEquals($expected, $norm, "normalized input nickname: $input -> $norm");
+ } else {
+ $this->assertEquals($expected, false, "invalid input nickname: $input");
+ }
+ }
+
+ static public function provider()
+ {
+ return array(
+ array('evan', 'evan'),
+ array('Evan', 'evan'),
+ array('EVAN', 'evan'),
+ array('ev_an', 'evan'),
+ array('ev.an', 'evan'),
+ array('ev/an', false),
+ array('ev an', false),
+ array('ev-an', false),
+ array('évan', false), // so far...
+ array('Évan', false), // so far...
+ array('evan1', 'evan1'),
+ array('evan_1', 'evan1'),
+ );
+ }
+}