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;
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 base.RenderAttributes (writer);
51 return writer.InnerWriter.ToString ();
54 public string Render ()
56 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
58 return writer.InnerWriter.ToString ();
61 public void PublicAddParsedSubObject (object o)
63 base.AddParsedSubObject (o);
66 public bool LoadPost (string key, NameValueCollection nvc)
68 return base.LoadPostData (key, nvc);
73 base.RaisePostDataChangedEvent ();
79 public class HtmlTextAreaTest {
82 public void DefaultProperties ()
84 TestHtmlTextArea ta = new TestHtmlTextArea ();
85 Assert.AreEqual (0, ta.Attributes.Count, "Attributes.Count");
86 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count");
88 Assert.AreEqual (-1, ta.Cols, "Cols");
89 Assert.IsNull (ta.Name, "Name");
90 Assert.AreEqual (-1, ta.Rows, "Rows");
91 Assert.AreEqual (String.Empty, ta.Value, "Value");
93 Assert.AreEqual ("textarea", ta.TagName, "TagName");
94 Assert.AreEqual (0, ta.Attributes.Count, "Attributes.Count-2");
95 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count-2");
99 public void NullProperties ()
101 TestHtmlTextArea ta = new TestHtmlTextArea ();
103 Assert.AreEqual (-1, ta.Cols, "Cols");
105 Assert.IsNull (ta.Name, "Name");
107 Assert.AreEqual (-1, ta.Rows, "Rows");
109 Assert.AreEqual (String.Empty, ta.Value, "Value");
111 Assert.AreEqual (0, ta.Attributes.Count, "Attributes.Count");
112 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count");
116 public void CleanProperties ()
118 TestHtmlTextArea ta = new TestHtmlTextArea ();
120 Assert.AreEqual (1, ta.Cols, "Cols");
122 Assert.IsNull (ta.Name, "Name");
124 Assert.AreEqual (2, ta.Rows, "Rows");
126 Assert.AreEqual ("value", ta.Value, "Value");
127 Assert.AreEqual (3, ta.Attributes.Count, "3");
128 Assert.AreEqual (3, ta.StateBag.Count, "StateBag.Count=3");
131 Assert.AreEqual (-1, ta.Cols, "-Cols");
133 Assert.IsNull (ta.Name, "-Name");
135 Assert.AreEqual (-1, ta.Rows, "Rows");
137 Assert.AreEqual (String.Empty, ta.Value, "-Value");
138 Assert.AreEqual (0, ta.Attributes.Count, "0");
139 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count=0");
145 HtmlTextArea ta = new HtmlTextArea ();
146 Assert.IsNull (ta.ID, "ID");
148 Assert.IsNull (ta.Name, "Name");
151 Assert.AreEqual ("id", ta.ID, "ID-2");
152 Assert.AreEqual ("id", ta.Name, "Name-ID");
155 Assert.AreEqual ("id", ta.Name, "Name-ID-2");
158 Assert.IsNull (ta.ID, "ID-3");
159 Assert.IsNull (ta.Name, "Name-2");
165 TestHtmlTextArea ta = new TestHtmlTextArea ();
166 Assert.AreEqual (0, ta.Attributes.Count, "0");
167 Assert.AreEqual (0, ta.StateBag.Count, "StateBag.Count=0");
170 Assert.AreEqual ("value", ta.Value, "Value");
171 Assert.AreEqual (1, ta.Attributes.Count, "1");
172 Assert.AreEqual (1, ta.StateBag.Count, "StateBag.Count=1");
174 // however it's not in attributes
175 Assert.IsNull (ta.Attributes["value"], "Attributes");
176 // but in InnerText and InnerHtml
177 Assert.AreEqual ("value", ta.InnerText, "InnerText");
178 Assert.AreEqual ("value", ta.InnerHtml, "InnerHtml");
179 // the later is kept in the attributes
180 Assert.IsNull (ta.Attributes["innertext"], "Attributes-InnerText");
181 Assert.AreEqual ("value", ta.Attributes["innerhtml"], "Attributes-InnerHtml");
185 public void RenderAttributes ()
187 TestHtmlTextArea ta = new TestHtmlTextArea ();
193 Assert.AreEqual (" name cols=\"4\" rows=\"2\"", ta.RenderAttributes ());
196 Assert.AreEqual (" name=\"go\" id=\"go\" cols=\"4\" rows=\"2\"", ta.RenderAttributes ());
200 public void RenderName1 ()
202 UserControl ctrl = new UserControl ();
204 Page page = new Page ();
205 TestHtmlTextArea ta = new TestHtmlTextArea ();
206 page.Controls.Add (ctrl);
207 ctrl.Controls.Add (ta);
210 Assert.AreEqual (" name=\"UC:go\" id=\"UC_go\"", ta.RenderAttributes ());
214 public void Render ()
216 TestHtmlTextArea ta = new TestHtmlTextArea ();
222 Assert.AreEqual ("<textarea name cols=\"4\" rows=\"2\">value</textarea>", ta.Render ());
225 Assert.AreEqual ("<textarea name=\"go\" id=\"go\" cols=\"4\" rows=\"2\">value</textarea>", ta.Render ());
229 [ExpectedException (typeof (NullReferenceException))]
230 [NUnit.Framework.Category ("NotWorking")] // Mono throw HttpException
231 public void AddParsedSubObject_Null ()
233 TestHtmlTextArea ta = new TestHtmlTextArea ();
234 ta.PublicAddParsedSubObject (null);
238 [ExpectedException (typeof (HttpException))]
239 public void AddParsedSubObject_WrongType ()
241 TestHtmlTextArea ta = new TestHtmlTextArea ();
242 ta.PublicAddParsedSubObject (this);
246 public void AddParsedSubObject_LiteralControl ()
248 TestHtmlTextArea ta = new TestHtmlTextArea ();
249 ta.PublicAddParsedSubObject (new LiteralControl ());
253 public void AddParsedSubObject_DataBoundLiteralControl ()
255 TestHtmlTextArea ta = new TestHtmlTextArea ();
256 ta.PublicAddParsedSubObject (new DataBoundLiteralControl (1,1));
259 private bool serverChange;
260 private void ServerChange (object sender, EventArgs e)
266 public void IPostBackDataHandler_RaisePostBackEvent ()
268 TestHtmlTextArea ta = new TestHtmlTextArea ();
269 ta.ServerChange += new EventHandler (ServerChange);
270 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
271 serverChange = false;
272 pbdh.RaisePostDataChangedEvent ();
273 Assert.IsTrue (serverChange, "ServerChange");
277 [ExpectedException (typeof (NullReferenceException))]
278 public void IPostBackDataHandler_LoadPostData_NullCollection ()
280 TestHtmlTextArea ta = new TestHtmlTextArea ();
281 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
282 pbdh.LoadPostData ("id1", null);
286 [Category ("NotDotNet")] // MS throws a NullReferenceException here
287 public void IPostBackDataHandler_LoadPostData_IdNull ()
289 TestHtmlTextArea ta = new TestHtmlTextArea ();
291 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
292 NameValueCollection nvc = new NameValueCollection ();
293 nvc.Add ("id1", "mono");
294 Assert.IsFalse (pbdh.LoadPostData (null, new NameValueCollection ()));
295 Assert.AreEqual (String.Empty, ta.Value, "Value");
299 [Category ("NotDotNet")] // MS throws a NullReferenceException here
300 public void IPostBackDataHandler_LoadPostData_WrongId ()
302 TestHtmlTextArea ta = new TestHtmlTextArea ();
304 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
305 NameValueCollection nvc = new NameValueCollection ();
306 nvc.Add ("id1", "mono");
307 Assert.IsFalse (pbdh.LoadPostData ("id2", nvc), "LoadPostData");
308 Assert.AreEqual (String.Empty, ta.Value, "Value");
312 public void IPostBackDataHandler_LoadPostData ()
314 TestHtmlTextArea ta = new TestHtmlTextArea ();
316 IPostBackDataHandler pbdh = (ta as IPostBackDataHandler);
317 NameValueCollection nvc = new NameValueCollection ();
318 nvc.Add ("id1", "mono");
319 Assert.IsTrue (pbdh.LoadPostData ("id1", nvc), "LoadPostData");
320 Assert.AreEqual ("mono", ta.Value, "Value");
324 public void RaisePostBackEvent ()
326 TestHtmlTextArea ta = new TestHtmlTextArea ();
327 ta.ServerChange += new EventHandler (ServerChange);
328 serverChange = false;
330 Assert.IsTrue (serverChange, "ServerClick");
334 [ExpectedException (typeof (NullReferenceException))]
335 public void LoadPostData_NullCollection ()
337 TestHtmlTextArea ta = new TestHtmlTextArea ();
338 ta.LoadPost ("id1", null);
342 [Category ("NotDotNet")] // MS throws a NullReferenceException here
343 public void LoadPostData_IdNull ()
345 TestHtmlTextArea ta = new TestHtmlTextArea ();
347 NameValueCollection nvc = new NameValueCollection ();
348 nvc.Add ("id1", "mono");
349 Assert.IsFalse (ta.LoadPost (null, nvc), "LoadPostData");
350 Assert.AreEqual (String.Empty, ta.Value, "Value");
354 [Category ("NotDotNet")] // MS throws a NullReferenceException here
355 public void LoadPostData_WrongId ()
357 TestHtmlTextArea ta = new TestHtmlTextArea ();
359 NameValueCollection nvc = new NameValueCollection ();
360 nvc.Add ("id1", "mono");
361 Assert.IsFalse (ta.LoadPost ("id2", nvc), "LoadPostData");
362 Assert.AreEqual (String.Empty, ta.Value, "Value");
366 public void LoadPostData ()
368 TestHtmlTextArea ta = new TestHtmlTextArea ();
370 NameValueCollection nvc = new NameValueCollection ();
371 nvc.Add ("id1", "mono");
372 Assert.IsTrue (ta.LoadPost ("id1", nvc), "LoadPostData");
373 Assert.AreEqual ("mono", ta.Value, "Value");