OSDN Git Service

Merge pull request #44 from upsilon/csharp7
[opentween/open-tween.git] / OpenTween.Tests / TweetDetailsViewTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
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)
10 // any later version.
11 //
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
15 // for more details.
16 //
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.
21
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Text;
26 using System.Threading.Tasks;
27 using OpenTween.Models;
28 using Xunit;
29
30 namespace OpenTween
31 {
32     public class TweetDetailsViewTest
33     {
34         [Fact]
35         public void FormatQuoteTweetHtml_PostClassTest()
36         {
37             var post = new PostClass
38             {
39                 StatusId = 12345L,
40                 Nickname = "upsilon",
41                 ScreenName = "kim_upsilon",
42                 Text = "<a href=\"https://twitter.com/twitterapi\">@twitterapi</a> hogehoge",
43                 CreatedAt = new DateTime(2015, 3, 30, 3, 30, 0),
44             };
45
46             // PostClass.Text はリンクを除去するのみでエスケープは行わない
47             // (TweetFormatter によって既にエスケープされた文字列が格納されているため)
48
49             var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
50                 "<blockquote class=\"quote-tweet\">" +
51                 "<p>@twitterapi hogehoge</p> &mdash; upsilon (@kim_upsilon) " + DateTime.Parse("2015/03/30 3:30:00") +
52                 "</blockquote></a>";
53             Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(post, isReply: false));
54         }
55
56         [Fact]
57         public void FormatQuoteTweetHtml_HtmlTest()
58         {
59             var statusId = 12345L; // リンク先のステータスID
60             var html = "<marquee>hogehoge</marquee>"; // HTMLをそのまま出力する (エスケープしない)
61
62             var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
63                 "<blockquote class=\"quote-tweet\"><marquee>hogehoge</marquee></blockquote>" +
64                 "</a>";
65             Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(statusId, html, isReply: false));
66         }
67
68         [Fact]
69         public void FormatQuoteTweetHtml_ReplyHtmlTest()
70         {
71             // blockquote の class に reply が付与される
72             var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
73                 "<blockquote class=\"quote-tweet reply\">hogehoge</blockquote>" +
74                 "</a>";
75             Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(12345L, "hogehoge", isReply: true));
76         }
77
78         [Fact]
79         public void StripLinkTagHtml_Test()
80         {
81             var html = "<a href=\"https://twitter.com/twitterapi\">@twitterapi</a>";
82
83             var expected = "@twitterapi";
84             Assert.Equal(expected, TweetDetailsView.StripLinkTagHtml(html));
85         }
86     }
87 }