fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-06-16 04:58 pm

[dw-free] Usernames from non-LJ based sites are treated like they're from LJ-based sites

[commit: http://hg.dwscoalition.org/dw-free/rev/e229e455e9f2]

http://bugs.dwscoalition.org/show_bug.cgi?id=3738

Add a test to show the use of hyphens in subdomain.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/External/User.pm
  • t/external-user.t
--------------------------------------------------------------------------------
diff -r d74542fefe8e -r e229e455e9f2 cgi-bin/DW/External/User.pm
--- a/cgi-bin/DW/External/User.pm	Thu Jun 16 19:36:18 2011 +0800
+++ b/cgi-bin/DW/External/User.pm	Thu Jun 16 22:27:49 2011 +0800
@@ -53,7 +53,6 @@
     return $_[0]->{user};
 }
 
-
 # return our external site
 sub site {
     return $_[0]->{site};
diff -r d74542fefe8e -r e229e455e9f2 t/external-user.t
--- a/t/external-user.t	Thu Jun 16 19:36:18 2011 +0800
+++ b/t/external-user.t	Thu Jun 16 22:27:49 2011 +0800
@@ -1,7 +1,7 @@
 # -*-perl-*-
 
 use strict;
-use Test::More tests => 14;
+use Test::More tests => 19;
 
 use lib "$ENV{LJHOME}/cgi-bin";
 require 'ljlib.pl';
@@ -84,6 +84,7 @@
 
     is( $u->site->{hostname}, "twitter.com", "Site is twitter.com" );
     is( $u->user, "example-username", "Hyphens are ok" );
+    is( $u->site->journal_url( $u ), "http://twitter.com/example-username" );
 }
 
 note( "Username with hyphen (LJ-based site)" );
@@ -95,6 +96,20 @@
 
     is( $u->user, "example_username", "Canonicalize usernames from LJ-based sites" );
     is( $u->site->{hostname}, "www.livejournal.com", "Site is livejournal.com" );
+    is( $u->site->journal_url( $u ), "http://www.livejournal.com/users/example_username/", "hyphen is an underscore when not a subdomain" );
+}
+
+note( "Username with hyphen (subdomain)" );
+{
+    my $u = DW::External::User->new(
+        user => "example-username",
+        site => "tumblr.com"
+    );
+
+    is( $u->user, "example-username", "Leave the hyphen alone for display username" );
+    is( $u->site->{hostname}, "tumblr.com", "Site is tumblr.com" );
+    is( $u->site->journal_url( $u ), "http://example-username.tumblr.com", "Leave the hyphen alone when used as a subdomain, too" );
+
 }
 
 1;
--------------------------------------------------------------------------------