3 // - Unit tests for System.Web.UI.HtmlControls.HtmlTextArea
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Specialized;
35 using System.Web.UI.HtmlControls;
36 using MonoTests.stand_alone.WebHarness;
37 using NUnit.Framework;
39 namespace MonoTests.System.Web.UI.HtmlControls {
41 public class TestHtmlTextArea : HtmlTextArea {
43 public StateBag StateBag {
44 get { return base.ViewState; }
47 public string RenderAttributes ()
49 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
50 writer.Write ("<dummy");
51 base.RenderAttributes (writer);
53 return writer.InnerWriter.ToString ();
56 public string Render ()
58 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
60 return writer.InnerWriter.ToString ();
63 public void PublicAddParsedSubObject (object o)
65 base.AddParsedSubObject (o);
68 public bool LoadPost (string key, NameValueCollection nvc)
70 return base.LoadPostData (key, nvc);
75 base.RaisePostDataChangedEvent ();
81 public class HtmlTextAreaTest {
84 public void DefaultProperties ()
86 TestHtmlTextArea ta = new TestHtmlTextArea ();
87 Assert.AreEqual (0, ta.Attributes.Count, "Attributes.Count");
88 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count");
90 Assert.AreEqual (-1, ta.Cols, "Cols");
91 Assert.IsNull (ta.Name, "Name");
92 Assert.AreEqual (-1, ta.Rows, "Rows");
93 Assert.AreEqual (String.Empty, ta.Value, "Value");
95 Assert.AreEqual ("textarea", ta.TagName, "TagName");
96 Assert.AreEqual (0, ta.Attributes.Count, "Attributes.Count-2");
97 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count-2");
101 public void NullProperties ()
103 TestHtmlTextArea ta = new TestHtmlTextArea ();
105 Assert.AreEqual (-1, ta.Cols, "Cols");
107 Assert.IsNull (ta.Name, "Name");
109 Assert.AreEqual (-1, ta.Rows, "Rows");
111 Assert.AreEqual (String.Empty, ta.Value, "Value");
113 Assert.AreEqual (0, ta.Attributes.Count, "Attributes.Count");
114 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count");
118 public void CleanProperties ()
120 TestHtmlTextArea ta = new TestHtmlTextArea ();
122 Assert.AreEqual (1, ta.Cols, "Cols");
124 Assert.IsNull (ta.Name, "Name");
126 Assert.AreEqual (2, ta.Rows, "Rows");
128 Assert.AreEqual ("value", ta.Value, "Value");
129 Assert.AreEqual (3, ta.Attributes.Count, "3");
130 Assert.AreEqual (3, ta.StateBag.Count, "StateBag.Count=3");
133 Assert.AreEqual (-1, ta.Cols, "-Cols");
135 Assert.IsNull (ta.Name, "-Name");
137 Assert.AreEqual (-1, ta.Rows, "Rows");
139 Assert.AreEqual (String.Empty, ta.Value, "-Value");
140 Assert.AreEqual (0, ta.Attributes.Count, "0");
141 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count=0");
147 HtmlTextArea ta = new HtmlTextArea ();
148 Assert.IsNull (ta.ID, "ID");
150 Assert.IsNull (ta.Name, "Name");
153 Assert.AreEqual ("id", ta.ID, "ID-2");
154 Assert.AreEqual ("id", ta.Name, "Name-ID");
157 Assert.AreEqual ("id", ta.Name, "Name-ID-2");
160 Assert.IsNull (ta.ID, "ID-3");
161 Assert.IsNull (ta.Name, "Name-2");
167 TestHtmlTextArea ta = new TestHtmlTextArea ();
168 Assert.AreEqual (0, ta.Attributes.Count, "0");
169 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count=0");
172 Assert.AreEqual ("value", ta.Value, "Value");
173 Assert.AreEqual (1, ta.Attributes.Count, "1");
174 Assert.AreEqual (1, ta.StateBag.Count, "StateBag.Count=1");
176 // however it's not in attributes
177 Assert.IsNull (ta.Attributes["value"], "Attributes");
178 // but in InnerText and InnerHtml
179 Assert.AreEqual ("value", ta.InnerText, "InnerText");
180 Assert.AreEqual ("value", ta.InnerHtml, "InnerHtml");
181 // the later is kept in the attributes
182 Assert.IsNull (ta.Attributes["innertext"], "Attributes-InnerText");
183 Assert.AreEqual ("value", ta.Attributes["innerhtml"], "Attributes-InnerHtml");
187 public void RenderAttributes ()
189 TestHtmlTextArea ta = new TestHtmlTextArea ();
195 HtmlDiff.AssertAreEqual ("<dummy name cols=\"4\" rows=\"2\" />", ta.RenderAttributes (), "RenderAttributes failed #1");
198 HtmlDiff.AssertAreEqual ("<dummy name=\"go\" id=\"go\" cols=\"4\" rows=\"2\" />", ta.RenderAttributes (), "RenderAttributes failed #2");
202 [Category ("NotDotNet")] // Implementation details changes : Control name will diffrent.
203 public void RenderName1 ()
205 UserControl ctrl = new UserControl ();
207 Page page = new Page ();
209 page.EnableEventValidation = false;
211 TestHtmlTextArea ta = new TestHtmlTextArea ();
212 page.Controls.Add (ctrl);
213 ctrl.Controls.Add (ta);
217 string expected = "<dummy name=\"UC$go\" id=\"UC_go\" />";
219 string expected = "<dummy name=\"UC:go\" id=\"UC_go\" />";
221 Assert.AreEqual (expected, ta.RenderAttributes ());
225 public void Render ()
227 TestHtmlTextArea ta = new TestHtmlTextArea ();
233 HtmlDiff.AssertAreEqual ("<textarea name cols=\"4\" rows=\"2\">value</textarea>", ta.Render (),"Render #1");
236 HtmlDiff.AssertAreEqual ("<textarea name=\"go\" id=\"go\" cols=\"4\" rows=\"2\">value</textarea>", ta.Render (),"Render #2");
240 [ExpectedException (typeof (NullReferenceException))]
241 [NUnit.Framework.Category ("NotWorking")] // Mono throw HttpException
242 public void AddParsedSubObject_Null ()
244 TestHtmlTextArea ta = new TestHtmlTextArea ();
245 ta.PublicAddParsedSubObject (null);
249 [ExpectedException (typeof (HttpException))]
250 public void AddParsedSubObject_WrongType ()
252 TestHtmlTextArea ta = new TestHtmlTextArea ();
253 ta.PublicAddParsedSubObject (this);
257 public void AddParsedSubObject_LiteralControl ()
259 TestHtmlTextArea ta = new TestHtmlTextArea ();
260 ta.PublicAddParsedSubObject (new LiteralControl ());
264 public void AddParsedSubObject_DataBoundLiteralControl ()
266 TestHtmlTextArea ta = new TestHtmlTextArea ();
267 ta.PublicAddParsedSubObject (new DataBoundLiteralControl (1,1));
270 private bool serverChange;
271 private void ServerChange (object sender, EventArgs e)
277 public void IPostBackDataHandler_RaisePostBackEvent ()
279 TestHtmlTextArea ta = new TestHtmlTextArea ();
280 ta.ServerChange += new EventHandler (ServerChange);
281 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
282 serverChange = false;
283 pbdh.RaisePostDataChangedEvent ();
284 Assert.IsTrue (serverChange, "ServerChange");
288 [ExpectedException (typeof (NullReferenceException))]
289 public void IPostBackDataHandler_LoadPostData_NullCollection ()
291 TestHtmlTextArea ta = new TestHtmlTextArea ();
292 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
293 pbdh.LoadPostData ("id1", null);
297 [Category ("NotDotNet")] // MS throws a NullReferenceException here
298 public void IPostBackDataHandler_LoadPostData_IdNull ()
300 TestHtmlTextArea ta = new TestHtmlTextArea ();
302 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
303 NameValueCollection nvc = new NameValueCollection ();
304 nvc.Add ("id1", "mono");
305 Assert.IsFalse (pbdh.LoadPostData (null, new NameValueCollection ()));
306 Assert.AreEqual (String.Empty, ta.Value, "Value");
310 [Category ("NotDotNet")] // MS throws a NullReferenceException here
311 public void IPostBackDataHandler_LoadPostData_WrongId ()
313 TestHtmlTextArea ta = new TestHtmlTextArea ();
315 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
316 NameValueCollection nvc = new NameValueCollection ();
317 nvc.Add ("id1", "mono");
318 Assert.IsFalse (pbdh.LoadPostData ("id2", nvc), "LoadPostData");
319 Assert.AreEqual (String.Empty, ta.Value, "Value");
323 public void IPostBackDataHandler_LoadPostData ()
325 TestHtmlTextArea ta = new TestHtmlTextArea ();
327 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
328 NameValueCollection nvc = new NameValueCollection ();
329 nvc.Add ("id1", "mono");
330 Assert.IsTrue (pbdh.LoadPostData ("id1", nvc), "LoadPostData");
331 Assert.AreEqual ("mono", ta.Value, "Value");
335 public void RaisePostBackEvent ()
337 TestHtmlTextArea ta = new TestHtmlTextArea ();
338 ta.ServerChange += new EventHandler (ServerChange);
339 serverChange = false;
341 Assert.IsTrue (serverChange, "ServerClick");
345 [ExpectedException (typeof (NullReferenceException))]
346 public void LoadPostData_NullCollection ()
348 TestHtmlTextArea ta = new TestHtmlTextArea ();
349 ta.LoadPost ("id1", null);
353 [Category ("NotDotNet")] // MS throws a NullReferenceException here
354 public void LoadPostData_IdNull ()
356 TestHtmlTextArea ta = new TestHtmlTextArea ();
358 NameValueCollection nvc = new NameValueCollection ();
359 nvc.Add ("id1", "mono");
360 Assert.IsFalse (ta.LoadPost (null, nvc), "LoadPostData");
361 Assert.AreEqual (String.Empty, ta.Value, "Value");
365 [Category ("NotDotNet")] // MS throws a NullReferenceException here
366 public void LoadPostData_WrongId ()
368 TestHtmlTextArea ta = new TestHtmlTextArea ();
370 NameValueCollection nvc = new NameValueCollection ();
371 nvc.Add ("id1", "mono");
372 Assert.IsFalse (ta.LoadPost ("id2", nvc), "LoadPostData");
373 Assert.AreEqual (String.Empty, ta.Value, "Value");
377 public void LoadPostData ()
379 TestHtmlTextArea ta = new TestHtmlTextArea ();
381 NameValueCollection nvc = new NameValueCollection ();
382 nvc.Add ("id1", "mono");
383 Assert.IsTrue (ta.LoadPost ("id1", nvc), "LoadPostData");
384 Assert.AreEqual ("mono", ta.Value, "Value");