2 // HtmlInputControlTest.cs
3 // - Unit tests for System.Web.UI.HtmlControls.HtmlInputControl
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.
33 using System.Web.UI.HtmlControls;
34 using MonoTests.stand_alone.WebHarness;
35 using NUnit.Framework;
37 namespace MonoTests.System.Web.UI.HtmlControls {
39 public class TestHtmlInputControl : HtmlInputControl {
42 public TestHtmlInputControl ()
47 public TestHtmlInputControl (string type)
52 public string RenderAttributes ()
54 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
55 writer.Write ("<dummy");
56 base.RenderAttributes (writer);
58 return writer.InnerWriter.ToString ();
61 public override string Name {
68 public bool NameCalled {
69 get { return name_called; }
70 set { name_called = value; }
74 public class UControl : UserControl {
78 public class HtmlInputControlTest {
80 private const int defaultAttributesCount = 1;
83 public void DefaultProperties ()
85 TestHtmlInputControl ic = new TestHtmlInputControl ();
86 Assert.AreEqual (defaultAttributesCount, ic.Attributes.Count, "Attributes.Count");
87 Assert.IsNull (ic.Name, "Name");
88 Assert.AreEqual ("mono", ic.Type, "Type");
89 Assert.AreEqual (String.Empty, ic.Value, "Value");
91 Assert.AreEqual ("input", ic.TagName, "TagName");
92 Assert.AreEqual (defaultAttributesCount, ic.Attributes.Count, "Attributes.Count-2");
96 public void NullProperties ()
98 TestHtmlInputControl ic = new TestHtmlInputControl ();
100 Assert.IsNull (ic.Name, "Name");
102 Assert.AreEqual (String.Empty, ic.Value, "Value");
104 Assert.AreEqual (defaultAttributesCount, ic.Attributes.Count, "Attributes.Count");
108 public void CleanProperties ()
110 TestHtmlInputControl ic = new TestHtmlInputControl ();
112 Assert.IsNull (ic.Name, "Name");
113 Assert.AreEqual (defaultAttributesCount, ic.Attributes.Count, "always null");
116 Assert.AreEqual ("value", ic.Value, "Value");
117 Assert.AreEqual (defaultAttributesCount + 1, ic.Attributes.Count, "1");
120 Assert.IsNull (ic.Name, "-Name");
122 Assert.AreEqual (String.Empty, ic.Value, "-Value");
123 Assert.AreEqual (defaultAttributesCount, ic.Attributes.Count, "0");
129 TestHtmlInputControl ic = new TestHtmlInputControl ();
130 Assert.IsNull (ic.UniqueID, "UniqueID");
131 Assert.IsNull (ic.ID, "ID");
133 Assert.IsNull (ic.Name, "Name");
136 Assert.AreEqual ("id", ic.ID, "ID-2");
137 Assert.AreEqual ("id", ic.UniqueID, "UniqueID");
138 Assert.AreEqual ("id", ic.Name, "Name-ID");
141 Assert.AreEqual ("id", ic.Name, "Name-ID-2");
142 Assert.AreEqual ("id", ic.UniqueID, "UniqueID-2");
145 Assert.IsNull (ic.ID, "ID-3");
146 Assert.IsNull (ic.UniqueID, "UniqueID-3");
147 Assert.IsNull (ic.Name, "Name-2");
151 public void Name_InsideNaming ()
153 Control ctrl = new UControl ();
155 TestHtmlInputControl ic = new TestHtmlInputControl ();
156 ctrl.Controls.Add (ic);
157 Assert.IsNull (ic.ID, "ID");
158 Assert.AreEqual (false, ic.NameCalled);
160 Assert.AreEqual (ic.Name, ic.UniqueID, "name and unique id");
161 Assert.AreEqual (true, ic.NameCalled, "name called");
164 Assert.AreEqual ("id", ic.ID, "ID-2");
165 Assert.AreEqual (ic.UniqueID, ic.Name, "Name-ID");
168 Assert.AreEqual (ic.Name, ic.UniqueID, "UniqueID-2");
171 Assert.IsNull (ic.ID, "ID-3");
172 Assert.IsNotNull (ic.UniqueID, "UniqueID-3");
173 Assert.IsNotNull (ic.Name, "Name-2");
177 public void IDversusValue ()
179 TestHtmlInputControl ic = new TestHtmlInputControl ();
180 Assert.AreEqual (String.Empty, ic.Value, "Value before");
182 Assert.AreEqual ("id1", ic.ID, "ID");
183 Assert.AreEqual (String.Empty, ic.Value, "Value after");
184 // HtmlInputRadioButton has a different behaviour
188 public void RenderAttributes ()
190 TestHtmlInputControl ic = new TestHtmlInputControl ("test");
194 HtmlDiff.AssertAreEqual ("<dummy name type=\"test\" value=\"value\" />", ic.RenderAttributes (), "RenderAttributes failed #1");
197 HtmlDiff.AssertAreEqual ("<dummy name=\"toto\" id=\"toto\" type=\"test\" value=\"value\" />", ic.RenderAttributes (), "RenderAttributes failed #2");
201 public void Constructor_Null ()
203 TestHtmlInputControl ic = new TestHtmlInputControl (null);
204 Assert.AreEqual (String.Empty, ic.Type, "Type");
208 public void Password ()
210 TestHtmlInputControl ic = new TestHtmlInputControl ("password");
214 // logic to hide password isn't in HtmlInputControl
215 HtmlDiff.AssertAreEqual ("<dummy name type=\"password\" value=\"s3kr3t\" />", ic.RenderAttributes (), "Password failed");