source: branches/work_311/output/URLLinkTest.cpp @ 537

Revision 537, 5.8 KB checked in by jls17, 5 years ago (diff)
  • replaced the CWebUtil::Link call in LetterFilterControl?.cpp with a call to the DirectURLLink class
Line 
1#include "ARInsideTest.h"
2#include "URLLink.h"
3
4#include "FileNaming.h"
5#include "IFileStructure.h"
6#include "ImageTag.h"
7#include "WebUtil.h"
8
9#include "../test/fakes/FakeARServerObject.h"
10
11using namespace testing;
12using namespace OUTPUT;
13
14const int rootLevel = 1; // we use rootLevel 1 in most cases
15
16class URLLinkTests : public Test
17{
18public:
19        // TODO: replace the following with a fake implementation!!
20        OUTPUT::FileNaming::ObjectNameFileNamingStrategy defaultFileNaming;
21       
22        void SetUp() 
23        {
24                SetFileNamingStrategy(&defaultFileNaming);
25                CWebUtil::webpageFileExtension = "htm";
26        }
27
28        void TearDown()
29        {
30                CWebUtil::webpageFileExtension = "";
31        }
32};
33
34TEST_F(URLLinkTests, BasicMainSelfLink)
35{
36        CPageParams page(PAGE_MAINHOME);
37        ImageTag image(ImageTag::NoImage, rootLevel);
38
39        stringstream strm;
40        strm << URLLink("LinkCaption", page, image, rootLevel, false, URLLink::TARGET_MODE_SELF);
41        string result = strm.str();
42
43        ASSERT_STREQ("<a href=\"../index.htm\">LinkCaption</a>", result.c_str());
44}
45
46TEST_F(URLLinkTests, MainLinkWithImageAndTarget)
47{
48        CPageParams page(PAGE_MAINHOME);
49        ImageTag image(ImageTag::Server, rootLevel);
50
51        stringstream strm;
52        strm << URLLink("<Main Page>", page, image, rootLevel, true, URLLink::TARGET_MODE_PARENT);
53        string result = strm.str();
54
55        ASSERT_STREQ("<img src=\"../img/server.gif\" width=\"16\" height=\"16\" alt=\"server.gif\" /><a href=\"../index.htm\" target=\"_parent\">&lt;Main Page&gt;</a>", result.c_str());
56}
57
58TEST_F(URLLinkTests, MainLinkWithImageShort)
59{
60        stringstream strm;
61        strm << URLLink("<Main Page>", PAGE_MAINHOME, ImageTag::Server, rootLevel);
62        string result = strm.str();
63
64        ASSERT_STREQ("<img src=\"../img/server.gif\" width=\"16\" height=\"16\" alt=\"server.gif\" /><a href=\"../index.htm\">&lt;Main Page&gt;</a>", result.c_str());
65}
66
67TEST_F(URLLinkTests, ObjectLinkWithImage)
68{
69        CFakeServerObject fakeWorkflow("TheTestObj");
70
71        stringstream strm;
72        strm << URLLink(fakeWorkflow, rootLevel);
73        string result = strm.str();
74
75        ASSERT_STREQ("<img src=\"../img/active_link.gif\" width=\"16\" height=\"16\" alt=\"active_link.gif\" /><a href=\"../active_link/TheTestObj.htm\">TheTestObj</a>", result.c_str());
76}
77
78TEST_F(URLLinkTests, ObjectFilterLinkWithImage)
79{
80        CFakeServerObject fakeWorkflow("TheTestObj", AR_STRUCT_ITEM_XML_FILTER);
81
82        stringstream strm;
83        strm << URLLink(fakeWorkflow, rootLevel);
84        string result = strm.str();
85
86        ASSERT_STREQ("<img src=\"../img/filter.gif\" width=\"16\" height=\"16\" alt=\"filter.gif\" /><a href=\"../filter/TheTestObj.htm\">TheTestObj</a>", result.c_str());
87}
88
89TEST_F(URLLinkTests, ObjectEscalationLinkWithoutImage)
90{
91        CFakeServerObject fakeWorkflow("TheTestObj", AR_STRUCT_ITEM_XML_ESCALATION);
92
93        stringstream strm;
94        strm << URLLink(fakeWorkflow, rootLevel, false);
95        string result = strm.str();
96
97        ASSERT_STREQ("<a href=\"../escalation/TheTestObj.htm\">TheTestObj</a>", result.c_str());
98}
99
100TEST_F(URLLinkTests, ObjectOverlayLink)
101{
102        CFakeServerObject fakeWorkflow("SampleMenu", AR_STRUCT_ITEM_XML_CHAR_MENU, AR_OVERLAY_OBJECT);
103       
104        stringstream strm;
105        strm << URLLink(fakeWorkflow, rootLevel);
106        string result = strm.str();
107
108        ASSERT_STREQ("<img src=\"../img/overlay.gif\" style=\"background:url(../img/menu.gif)\" width=\"16\" height=\"16\" alt=\"menu.gif\" /><a href=\"../menu/SampleMenu.htm\">SampleMenu</a>", result.c_str());
109}
110
111TEST_F(URLLinkTests, SpecificCaptionForObject)
112{
113        // This construct is normally used for fields to show a different link name than
114        // the fields name. But currently we can't test with a field, because of the
115        // CARSchema dependency of the CARField class. So we'll test with an escalation
116        // instead.
117        CFakeServerObject fakeWorkflow("TheTestObj", AR_STRUCT_ITEM_XML_ESCALATION);
118       
119        stringstream strm;
120        strm << URLLink("RealTestObj", fakeWorkflow, rootLevel, false);
121        string result = strm.str();
122
123        ASSERT_STREQ("<a href=\"../escalation/TheTestObj.htm\">RealTestObj</a>", result.c_str());
124}
125
126TEST_F(URLLinkTests, NoSpecificCaptionForObject)
127{
128        CFakeServerObject fakeWorkflow("TheTestObj", AR_STRUCT_ITEM_XML_ESCALATION);
129       
130        stringstream strm;
131        strm << URLLink("", fakeWorkflow, rootLevel, false);
132        string result = strm.str();
133
134        ASSERT_STREQ("<a href=\"../escalation/TheTestObj.htm\">TheTestObj</a>", result.c_str());
135}
136
137TEST_F(URLLinkTests, CheckedObject)
138{
139        CFakeServerObject fakeWorkflow("TheTestObj", AR_STRUCT_ITEM_XML_ESCALATION);
140
141        stringstream strm;
142        strm << CheckedURLLink(fakeWorkflow, "<p>Object is missing</p>", rootLevel);
143        string result = strm.str();
144
145        ASSERT_STREQ("<img src=\"../img/escalation.gif\" width=\"16\" height=\"16\" alt=\"escalation.gif\" /><a href=\"../escalation/TheTestObj.htm\">TheTestObj</a>", result.c_str());
146}
147
148TEST_F(URLLinkTests, CheckedObjectMissing)
149{
150        const char* AlternateHTMLIfObjectDoesNotExist = "<p>Object is missing</p>";
151        CFakeServerObject noneExistingWorkflow;
152
153        stringstream strm;
154        strm << CheckedURLLink(noneExistingWorkflow, AlternateHTMLIfObjectDoesNotExist, rootLevel);
155        string result = strm.str();
156
157        ASSERT_STREQ(AlternateHTMLIfObjectDoesNotExist, result.c_str());
158}
159
160TEST_F(URLLinkTests, TopLinkCreation)
161{
162        stringstream strm;
163        strm << DirectURLLink::CreateTop;
164        string result = strm.str();
165
166        ASSERT_STREQ("<a id=\"top\"></a>", result.c_str());
167}
168
169TEST_F(URLLinkTests, LinkToTop)
170{
171        stringstream strm;
172        strm << DirectURLLink(DirectURLLink::LinkToTop, rootLevel);
173        string result = strm.str();
174
175        ASSERT_STREQ("<img src=\"../img/up.gif\" width=\"14\" height=\"10\" alt=\"up.gif\" /><a href=\"#top\">Top</a>", result.c_str());
176}
177
178TEST_F(URLLinkTests, LinkToJavascriptVoid)
179{
180        stringstream strm;
181        strm << DirectURLLink(DirectURLLink::JavascriptVoid, "JSLink", rootLevel);
182        string result = strm.str();
183
184        ASSERT_STREQ("<a href=\"javascript:void(0)\">JSLink</a>", result.c_str());
185}
Note: See TracBrowser for help on using the repository browser.