2 // Tests for System.Web.UI.WebControls.EditCommandColumn.cs
5 // Peter Dennis Bartok (pbartok@novell.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Collections;
36 using System.Globalization;
40 using System.Web.UI.WebControls;
42 namespace MonoTests.System.Web.UI.WebControls
48 public class EditCommandColumnTest {
50 private class DataGridTest : DataGrid {
51 public ArrayList CreateColumns (PagedDataSource data_source, bool use_data_source) {
52 return CreateColumnSet (data_source, use_data_source);
55 public void CreateControls (bool use_data_source) {
56 CreateControlHierarchy (use_data_source);
61 [Category("NotWorking")]
62 public void Defaults ()
66 e = new EditCommandColumn();
68 Assert.AreEqual(ButtonColumnType.LinkButton, e.ButtonType, "D1");
69 Assert.AreEqual(string.Empty, e.CancelText, "D2");
70 Assert.AreEqual(string.Empty, e.EditText, "D3");
71 Assert.AreEqual(string.Empty, e.UpdateText, "D4");
73 // MONO BUG: CausesValidation and ValidationGroup have no definition
74 //Assert.AreEqual (true, e.CausesValidation, "CausesValidation");
75 //Assert.AreEqual (string.Empty, e.ValidationGroup, "ValidationGroup");
76 Assert.Fail("CausesValidation and ValidationGroup have no definition");
81 [Category ("NotWorking")]
82 public void Properties () {
85 e = new EditCommandColumn();
87 e.ButtonType = ButtonColumnType.PushButton;
88 Assert.AreEqual(ButtonColumnType.PushButton, e.ButtonType, "P1");
90 e.CancelText = "Cancel this!";
91 Assert.AreEqual("Cancel this!", e.CancelText, "D2");
93 e.EditText = "Edit me good";
94 Assert.AreEqual("Edit me good", e.EditText, "D3");
96 e.UpdateText = "Update? What update?";
97 Assert.AreEqual("Update? What update?", e.UpdateText, "D4");
99 // MONO BUG: CausesValidation and ValidationGroup have no definition
100 //e.CausesValidation = false;
101 //Assert.AreEqual (false, e.CausesValidation, "CausesValidation");
102 //e.ValidationGroup = "test";
103 //Assert.AreEqual ("test", e.ValidationGroup, "ValidationGroup");
104 Assert.Fail ("CausesValidation and ValidationGroup have no definition");
109 private string ControlMarkup(Control c) {
110 StringWriter sw = new StringWriter ();
111 HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
113 c.RenderControl (tw);
114 return sw.ToString ();
117 private void ShowControlsRecursive (Control c, int depth) {
118 StringWriter sw = new StringWriter ();
119 HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
121 c.RenderControl (tw);
122 Console.WriteLine (sw.ToString ());
124 Console.WriteLine (c);
126 foreach (Control child in c.Controls)
127 ShowControlsRecursive (child, depth + 5);
131 [Category ("NotDotNet")]
132 [Category ("NotWorking")]
133 public void InitializeCell () {
134 DataGridTest p = new DataGridTest ();
135 DataTable table = new DataTable ();
139 e = new EditCommandColumn();
140 e.ButtonType = ButtonColumnType.LinkButton;
141 e.CancelText = "Cancel";
143 e.UpdateText = "Update";
145 table.Columns.Add (new DataColumn ("one", typeof (string)));
146 table.Columns.Add (new DataColumn ("two", typeof (string)));
147 table.Columns.Add (new DataColumn ("three", typeof (string)));
148 table.Rows.Add (new object [] { "1", "2", "3" });
150 p.DataSource = new DataView (table);
153 e = new EditCommandColumn();
154 e.ButtonType = ButtonColumnType.PushButton;
155 e.CancelText = "Abbrechen";
156 e.EditText = "Bearbeiten";
157 e.UpdateText = "Refresh";
160 // This will trigger EditCommandColumn.InitializeCell, without any EditItem set, tests the EditText render
161 p.CreateControls (true);
164 Assert.AreEqual (2, p.Columns.Count, "I1");
165 markup = ControlMarkup(p.Controls[0]);
166 markup = markup.Replace("\t", "");
167 markup = markup.Replace ("\r", "");
168 markup = markup.Replace ("\n", "");
172 "<table border=\"0\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
173 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker$ctl02$ctl00\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
174 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
175 "</tr></table>", markup, "I2");
178 "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
179 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker:_ctl1:_ctl0\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
180 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
181 "</tr></table>", markup, "I2");
183 //ShowControlsRecursive (p.Controls [0], 1);
187 [Category ("NotDotNet")]
188 [Category("NotWorking")]
189 public void ThisIsADGTest () {
190 DataGridTest p = new DataGridTest ();
191 DataTable table = new DataTable ();
195 e = new EditCommandColumn();
196 e.ButtonType = ButtonColumnType.LinkButton;
197 e.CancelText = "Cancel";
199 e.UpdateText = "Update";
201 table.Columns.Add (new DataColumn ("one", typeof (string)));
202 table.Columns.Add (new DataColumn ("two", typeof (string)));
203 table.Columns.Add (new DataColumn ("three", typeof (string)));
204 table.Rows.Add (new object [] { "1", "2", "3" });
206 p.DataSource = new DataView (table);
209 e = new EditCommandColumn();
210 e.ButtonType = ButtonColumnType.PushButton;
211 e.CancelText = "Abbrechen";
212 e.EditText = "Bearbeiten";
213 e.UpdateText = "Refresh";
216 p.CreateControls (true);
217 // This is the test we want to run: setting the ID of the table created by
218 // the datagrid overrides the using the ID of the datagrid itself and uses
219 // the table ClientID instead.
221 p.Controls [0].ID = "tbl";
223 Assert.AreEqual (2, p.Columns.Count, "I1");
224 markup = ControlMarkup(p.Controls[0]);
225 markup = markup.Replace("\t", "");
226 markup = markup.Replace ("\r", "");
227 markup = markup.Replace ("\n", "");
231 "<table border=\"0\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
232 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker_tbl$ctl02$ctl00\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
233 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
234 "</tr></table>", markup, "I2");
237 "<table border=\"0\" id=\"sucker_tbl\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
238 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker:_ctl1:_ctl0\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
239 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
240 "</tr></table>", markup, "I2");
244 static void GetHierarchy (ControlCollection coll, int level, StringBuilder sb)
246 foreach (Control c in coll) {
247 sb.AppendFormat ("{0}{1}\n", new string (' ', 2 * level), c.GetType ());
248 GetHierarchy (c.Controls, level + 1, sb);
253 [Category ("NotDotNet")]
254 [Category("NotWorking")]
255 public void InitializeEditCell () {
256 DataGridTest p = new DataGridTest ();
257 DataTable table = new DataTable ();
261 e = new EditCommandColumn();
262 e.ButtonType = ButtonColumnType.LinkButton;
263 e.CancelText = "Cancel";
265 e.UpdateText = "Update";
267 table.Columns.Add (new DataColumn ("one", typeof (string)));
268 table.Columns.Add (new DataColumn ("two", typeof (string)));
269 table.Columns.Add (new DataColumn ("three", typeof (string)));
270 table.Rows.Add (new object [] { "1", "2", "3" });
272 p.DataSource = new DataView (table);
275 e = new EditCommandColumn();
276 e.ButtonType = ButtonColumnType.PushButton;
277 e.CancelText = "Abbrechen";
278 e.EditText = "Bearbeiten";
279 e.UpdateText = "Refresh";
282 // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
285 // This will trigger EditCommandColumn.InitializeCell
286 p.CreateControls (true);
289 StringBuilder sb = new StringBuilder ();
290 GetHierarchy (p.Controls, 0, sb);
291 string h = sb.ToString ();
292 int x = h.IndexOf (".TextBox");
293 // These are from the BoundColumns
294 Assert.IsTrue (x != -1, "textbox1");
295 x = h.IndexOf (".TextBox", x + 1);
296 Assert.IsTrue (x != -1, "textbox2");
297 x = h.IndexOf (".TextBox", x + 1);
298 Assert.IsTrue (x != -1, "textbox3");
299 x = h.IndexOf (".TextBox", x + 1);
300 Assert.IsTrue (x == -1, "textbox-end");
302 markup = ControlMarkup (p.Controls[0]);
303 markup = markup.Replace ("\t", "");
304 markup = markup.Replace ("\r", "");
305 markup = markup.Replace ("\n", "");
307 //Console.WriteLine("Markup:>{0}<", markup);
308 Assert.AreEqual (2, p.Columns.Count, "I1");
312 "<table border=\"0\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
313 "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name=\"sucker$ctl02$ctl00\" type=\"submit\" value=\"Refresh\" /> " +
314 "<input name=\"sucker$ctl02$ctl01\" type=\"submit\" value=\"Abbrechen\" /></td>" +
315 "<td><input name=\"sucker$ctl02$ctl02\" type=\"text\" value=\"1\" /></td>" +
316 "<td><input name=\"sucker$ctl02$ctl03\" type=\"text\" value=\"2\" /></td>" +
317 "<td><input name=\"sucker$ctl02$ctl04\" type=\"text\" value=\"3\" /></td>" +
318 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
319 "</tr></table>", markup, "I2");
322 "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
323 "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name=\"sucker:_ctl1:_ctl0\" type=\"submit\" value=\"Refresh\" /> " +
324 "<input name=\"sucker:_ctl1:_ctl1\" type=\"submit\" value=\"Abbrechen\" /></td>" +
325 "<td><input name=\"sucker:_ctl1:_ctl2\" type=\"text\" value=\"1\" /></td>" +
326 "<td><input name=\"sucker:_ctl1:_ctl3\" type=\"text\" value=\"2\" /></td>" +
327 "<td><input name=\"sucker:_ctl1:_ctl4\" type=\"text\" value=\"3\" /></td>" +
328 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
329 "</tr></table>", markup, "I2");
334 [Ignore("Unfinished")]
335 public void InitializeReadOnlyEditCell ()
337 DataGridTest p = new DataGridTest ();
338 DataTable table = new DataTable ();
342 e = new EditCommandColumn ();
343 e.ButtonType = ButtonColumnType.LinkButton;
344 e.CancelText = "Cancel";
346 e.UpdateText = "Update";
348 table.Columns.Add (new DataColumn ("one", typeof (string)));
349 table.Columns.Add (new DataColumn ("two", typeof (string)));
350 table.Columns.Add (new DataColumn ("three", typeof (string)));
351 table.Rows.Add (new object[] { "1", "2", "3" });
353 p.DataSource = new DataView (table);
356 e = new EditCommandColumn ();
357 e.ButtonType = ButtonColumnType.PushButton;
359 e.CancelText = "Abbrechen";
360 e.EditText = "Bearbeiten";
361 e.UpdateText = "Refresh";
364 // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
367 // This will trigger EditCommandColumn.InitializeCell
368 p.CreateControls (true);
371 markup = ControlMarkup (p.Controls[0]);
372 markup = markup.Replace ("\t", "");
373 markup = markup.Replace ("\r", "");
374 markup = markup.Replace ("\n", "");
376 Assert.AreEqual (2, p.Columns.Count, "I1");
378 "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
379 "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" /> " +
380 "<input name value=\"Abbrechen\" type=\"submit\" /></td>" +
381 "<td><input name=\"_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
382 "<td><input name=\"_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
383 "<td><input name=\"_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
384 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
385 "</tr></table>", markup, "I2");