HtmlFormTest.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // HtmlFormTest.cs
  3. // - Unit tests for System.Web.UI.HtmlControls.HtmlForm
  4. //
  5. // Author:
  6. // Dick Porter <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  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:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  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.
  28. //
  29. using System;
  30. using System.IO;
  31. using System.Web.UI;
  32. using System.Web.UI.HtmlControls;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Web.UI.HtmlControls {
  35. public class FormPoker : HtmlForm {
  36. public FormPoker () {
  37. TrackViewState ();
  38. }
  39. public object SaveState ()
  40. {
  41. return SaveViewState ();
  42. }
  43. public void LoadState (object state)
  44. {
  45. LoadViewState (state);
  46. }
  47. #if NET_2_0
  48. public ControlCollection GetControlCollection ()
  49. {
  50. return CreateControlCollection();
  51. }
  52. #endif
  53. }
  54. class FUControl : UserControl {
  55. }
  56. [TestFixture]
  57. public class HtmlFormTest {
  58. [Test]
  59. public void DefaultProperties ()
  60. {
  61. HtmlForm form = new HtmlForm ();
  62. Assert.AreEqual (0, form.Attributes.Count, "Attributes.Count");
  63. Assert.AreEqual (String.Empty, form.Enctype, "Enctype");
  64. Assert.AreEqual ("post", form.Method, "Method");
  65. Assert.AreEqual (form.UniqueID, form.Name, "Name");
  66. Assert.AreEqual (String.Empty, form.Target, "Target");
  67. Assert.AreEqual ("form", form.TagName, "TagName");
  68. #if NET_2_0
  69. Assert.IsFalse (form.SubmitDisabledControls, "TagName");
  70. #endif
  71. }
  72. [Test]
  73. public void NullProperties ()
  74. {
  75. HtmlForm form = new HtmlForm ();
  76. form.Enctype = null;
  77. Assert.AreEqual (String.Empty, form.Enctype, "Enctype");
  78. form.Method = null;
  79. Assert.AreEqual ("post", form.Method, "Method");
  80. form.Name = null;
  81. Assert.AreEqual (form.UniqueID, form.Name, "Name");
  82. form.Target = null;
  83. Assert.AreEqual (String.Empty, form.Target, "Target");
  84. #if NET_2_0
  85. form.DefaultButton = null;
  86. Assert.AreEqual (String.Empty, form.DefaultButton, "DefaultButton");
  87. form.DefaultFocus = null;
  88. Assert.AreEqual (String.Empty, form.DefaultFocus, "DefaultFocus");
  89. #endif
  90. Assert.AreEqual (0, form.Attributes.Count, "Attributes.Count");
  91. }
  92. [Test]
  93. public void Attributes ()
  94. {
  95. HtmlForm form = new HtmlForm ();
  96. IAttributeAccessor a = (IAttributeAccessor)form;
  97. #if NET_2_0
  98. /* not stored in Attributes */
  99. form.DefaultButton = "defaultbutton";
  100. Assert.IsNull (a.GetAttribute ("defaultbutton"), "A1");
  101. /* not stored in Attributes */
  102. form.DefaultFocus = "defaultfocus";
  103. Assert.IsNull (a.GetAttribute ("defaultfocus"), "A2");
  104. #endif
  105. form.Enctype = "enctype";
  106. Assert.AreEqual ("enctype", a.GetAttribute ("enctype"), "A3");
  107. form.Method = "method";
  108. Assert.AreEqual ("method", a.GetAttribute ("method"), "A4");
  109. /* not stored in Attributes */
  110. form.Name = "name";
  111. Assert.AreEqual (form.UniqueID, form.Name, "A5");
  112. Assert.IsNull (form.Name, "A6");
  113. Assert.IsNull (form.UniqueID, "A7");
  114. Assert.IsNull (a.GetAttribute ("name"), "A8");
  115. form.ID = "hithere";
  116. Assert.AreEqual ("hithere", form.Name, "A9");
  117. #if NET_2_0
  118. form.SubmitDisabledControls = true;
  119. Assert.IsNull (a.GetAttribute ("submitdisabledcontrols"), "A10");
  120. #endif
  121. form.Target = "target";
  122. Assert.AreEqual ("target", a.GetAttribute ("target"), "A11");
  123. }
  124. [Test]
  125. public void ViewState ()
  126. {
  127. FormPoker form = new FormPoker();
  128. FormPoker copy = new FormPoker();
  129. #if NET_2_0
  130. form.DefaultButton = "defaultbutton";
  131. form.DefaultFocus = "defaultfocus";
  132. #endif
  133. object state = form.SaveState();
  134. copy.LoadState (state);
  135. #if NET_2_0
  136. Assert.AreEqual ("", copy.DefaultButton, "A1");
  137. Assert.AreEqual ("defaultfocus", form.DefaultFocus, "A2");
  138. #endif
  139. }
  140. [Test]
  141. public void Name_InsideNaming ()
  142. {
  143. Control ctrl = new FUControl ();
  144. ctrl.ID = "parent";
  145. FormPoker form = new FormPoker ();
  146. ctrl.Controls.Add (form);
  147. Assert.IsNull (form.ID, "ID");
  148. form.Name = "name";
  149. Assert.AreEqual (form.Name, form.UniqueID, "name and unique id");
  150. form.ID = "id";
  151. Assert.AreEqual ("id", form.ID, "ID-2");
  152. Assert.AreEqual (form.UniqueID, form.Name, "Name-ID");
  153. form.Name = "name";
  154. Assert.AreEqual (form.Name, form.UniqueID, "UniqueID-2");
  155. form.ID = null;
  156. Assert.IsNull (form.ID, "ID-3");
  157. Assert.IsNotNull (form.UniqueID, "UniqueID-3");
  158. Assert.IsNotNull (form.Name, "Name-2");
  159. }
  160. #if NET_2_0
  161. [Test]
  162. public void ControlCollection ()
  163. {
  164. FormPoker poker = new FormPoker();
  165. ControlCollection col = poker.GetControlCollection();
  166. Assert.AreEqual (col.GetType(), typeof (ControlCollection), "A1");
  167. Assert.IsFalse (col.IsReadOnly, "A2");
  168. Assert.AreEqual (0, col.Count, "A3");
  169. }
  170. #endif
  171. }
  172. }