1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
23 using System.Collections.Generic;
24 using System.Globalization;
27 using System.Threading.Tasks;
28 using OpenTween.Models;
33 public class TweetDetailsViewTest
36 public void FormatQuoteTweetHtml_PostClassTest()
38 var post = new PostClass
42 ScreenName = "kim_upsilon",
43 Text = "<a href=\"https://twitter.com/twitterapi\">@twitterapi</a> hogehoge",
44 CreatedAt = new DateTimeUtc(2015, 3, 30, 3, 30, 0),
47 // PostClass.Text はリンクを除去するのみでエスケープは行わない
48 // (TweetFormatter によって既にエスケープされた文字列が格納されているため)
50 var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
51 "<blockquote class=\"quote-tweet\">" +
52 "<p>@twitterapi hogehoge</p> — upsilon (@kim_upsilon) " + DateTimeUtc.Parse("2015/03/30 3:30:00", DateTimeFormatInfo.InvariantInfo).ToLocalTimeString() +
54 Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(post, isReply: false));
58 public void FormatQuoteTweetHtml_HtmlTest()
60 var statusId = 12345L; // リンク先のステータスID
61 var html = "<marquee>hogehoge</marquee>"; // HTMLをそのまま出力する (エスケープしない)
63 var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
64 "<blockquote class=\"quote-tweet\"><marquee>hogehoge</marquee></blockquote>" +
66 Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(statusId, html, isReply: false));
70 public void FormatQuoteTweetHtml_ReplyHtmlTest()
72 // blockquote の class に reply が付与される
73 var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
74 "<blockquote class=\"quote-tweet reply\">hogehoge</blockquote>" +
76 Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(12345L, "hogehoge", isReply: true));
80 public void StripLinkTagHtml_Test()
82 var html = "<a href=\"https://twitter.com/twitterapi\">@twitterapi</a>";
84 var expected = "@twitterapi";
85 Assert.Equal(expected, TweetDetailsView.StripLinkTagHtml(html));