Wed Feb 24 15:47:16 CET 2010 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / CheckBoxListTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.CheckBoxList.cs 
3 //
4 // Author:
5 //      Jackson Harper (jackson@ximian.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.Drawing;
39 using System.Collections;
40 using MonoTests.SystemWeb.Framework;
41 using MonoTests.stand_alone.WebHarness;
42 using System.Collections.Specialized;
43
44 namespace MonoTests.System.Web.UI.WebControls {
45
46         public class CheckBoxListPoker : CheckBoxList {
47
48                 public Style CreateStyle ()
49                 {
50                         return CreateControlStyle ();
51                 }
52
53                 public Control FindControlPoke (string name, int offset)
54                 {
55                         return FindControl (name, offset);
56                 }
57
58                 public string Render ()
59                 {
60                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
61                         base.Render (writer);
62                         return writer.InnerWriter.ToString ();
63                 }
64
65                 
66 #if NET_2_0
67                 public new bool HasFooter
68                 {
69                         get
70                         {
71                                 return base.HasFooter;
72                         }
73                 }
74
75                 public new bool HasHeader
76                 {
77                         get
78                         {
79                                 return base.HasHeader;
80                         }
81                 }
82
83                 public new bool HasSeparators
84                 {
85                         get
86                         {
87                                 return base.HasSeparators;
88                         }
89                 }
90
91                 public new int RepeatedItemCount
92                 {
93                         get
94                         {
95                                 return base.RepeatedItemCount;
96                         }
97                 }
98
99                 public new void RaisePostDataChangedEvent ()
100                 {
101                         base.RaisePostDataChangedEvent ();
102                 }
103
104                 protected override Style GetItemStyle (ListItemType itemType, int repeatIndex)
105                 {
106                         Style s = new Style();
107                         s.BackColor = Color.Red;
108                         s.BorderStyle = BorderStyle.Solid;
109                         WebTest.CurrentTest.UserData = "GetItemStyle";
110                         return s;
111                 }
112
113                 public Style DoGetItemStyle (ListItemType itemType, int repeatIndex)
114                 {
115                         return base.GetItemStyle (itemType, repeatIndex);
116                 }
117
118                 public new string RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo)
119                 {
120                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
121                         base.RenderItem(itemType,repeatIndex,repeatInfo,writer);
122                         return writer.InnerWriter.ToString ();
123                 }
124 #endif
125         }
126
127         [TestFixture]
128         public class CheckBoxListTest
129         {
130                 [TestFixtureSetUp]
131                 public void SetUp ()
132                 {
133                         Type t = GetType ();
134                         WebTest.CopyResource (t, "CheckBoxList_Bug377703_1.aspx", "CheckBoxList_Bug377703_1.aspx");
135                         WebTest.CopyResource (t, "CheckBoxList_Bug377703_2.aspx", "CheckBoxList_Bug377703_2.aspx");
136                         WebTest.CopyResource (t, "CheckBoxList_Bug578770.aspx", "CheckBoxList_Bug578770.aspx");
137                 }
138                 
139                 [Test]
140                 public void Defaults ()
141                 {
142                         CheckBoxListPoker c = new CheckBoxListPoker ();
143
144                         Assert.AreEqual (c.CellPadding, -1, "A1");
145                         Assert.AreEqual (c.CellSpacing, -1, "A2");
146                         Assert.AreEqual (c.RepeatColumns, 0, "A3");
147                         Assert.AreEqual (c.RepeatDirection,
148                                         RepeatDirection.Vertical, "A4");
149                         Assert.AreEqual (c.RepeatLayout,
150                                         RepeatLayout.Table, "A5");
151                         Assert.AreEqual (c.TextAlign, TextAlign.Right, "A6");
152 #if NET_2_0
153                         Assert.AreEqual (false, c.HasFooter, "HasFooter");
154                         Assert.AreEqual (false, c.HasHeader, "HasHeader");
155                         Assert.AreEqual (false, c.HasSeparators, "HasSeparators");
156                         Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount");
157                         Assert.AreEqual (null, c.DoGetItemStyle (ListItemType.Item, 0), "GetItemStyle");
158 #endif
159                 }
160
161 #if NET_2_0
162                 [Test]
163                 public void CheckBoxList_Bug377708_1 ()
164                 {
165                         WebTest t = new WebTest ("CheckBoxList_Bug377703_1.aspx");
166                         t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377708_1_OnInit);
167                         string origHtmlFirst = @"<table id=""cbxl1"" border=""0"">
168         <tr>
169                 <td><input id=""cbxl1_0"" type=""checkbox"" name=""cbxl1$0"" /><label for=""cbxl1_0"">x</label></td>
170
171         </tr><tr>
172                 <td><input id=""cbxl1_1"" type=""checkbox"" name=""cbxl1$1"" /><label for=""cbxl1_1"">y</label></td>
173         </tr><tr>
174                 <td><input id=""cbxl1_2"" type=""checkbox"" name=""cbxl1$2"" /><label for=""cbxl1_2"">z</label></td>
175         </tr>
176 </table>";
177                         string origHtmlSecond = @"<table id=""cbxl1"" border=""0"">
178         <tr>
179                 <td><input id=""cbxl1_0"" type=""checkbox"" name=""cbxl1$0"" checked=""checked"" /><label for=""cbxl1_0"">x</label></td>
180
181         </tr><tr>
182                 <td><input id=""cbxl1_1"" type=""checkbox"" name=""cbxl1$1"" /><label for=""cbxl1_1"">y</label></td>
183         </tr><tr>
184                 <td><input id=""cbxl1_2"" type=""checkbox"" name=""cbxl1$2"" /><label for=""cbxl1_2"">z</label></td>
185         </tr>
186 </table>";
187                         string html = t.Run ();
188                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
189
190                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
191
192                         FormRequest fr = new FormRequest (t.Response, "form1");
193                         fr.Controls.Add ("cbxl1$0");
194                         fr.Controls ["cbxl1$0"].Value = "on";
195
196                         fr.Controls.Add ("ctl01");
197                         fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
198
199                         t.Request = fr;
200                         html = t.Run ();
201
202                         fr = new FormRequest (t.Response, "form1");
203                         fr.Controls.Add ("cbxl1$0");
204                         fr.Controls ["cbxl1$0"].Value = "on";
205
206                         fr.Controls.Add ("ctl01");
207                         fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
208
209                         t.Request = fr;
210                         html = t.Run ();
211
212                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
213                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
214                 }
215
216                 public static void CheckBoxList_Bug377708_1_OnInit (Page p)
217                 {
218                         CheckBoxList cbxl1 = p.FindControl ("cbxl1") as CheckBoxList;
219                         
220                         cbxl1.DataSource = new[] {
221                                 new { ID = "x", Text = "X" },
222                                 new { ID = "y", Text = "Y" },
223                                 new { ID = "z", Text = "Z" },
224                         };
225                         cbxl1.DataValueField = "ID";
226                         cbxl1.DataTextField = "ID";
227                         cbxl1.DataBind();
228                 }
229
230                 [Test]
231                 public void CheckBoxList_Bug377708_2 ()
232                 {
233                         WebTest t = new WebTest ("CheckBoxList_Bug377703_2.aspx");
234                         t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377708_2_OnInit);
235                         string origHtmlFirst = @"<table id=""cbxl2"" border=""0"">
236         <tr>
237                 <td><input id=""cbxl2_0"" type=""checkbox"" name=""cbxl2$0"" /><label for=""cbxl2_0"">x</label></td>
238
239         </tr><tr>
240                 <td><input id=""cbxl2_1"" type=""checkbox"" name=""cbxl2$1"" /><label for=""cbxl2_1"">y</label></td>
241         </tr><tr>
242                 <td><input id=""cbxl2_2"" type=""checkbox"" name=""cbxl2$2"" /><label for=""cbxl2_2"">z</label></td>
243         </tr>
244 </table>";
245                         string origHtmlSecond = @"<table id=""cbxl2"" disabled=""disabled"" border=""0"">
246         <tr>
247                 <td><span disabled=""disabled""><input id=""cbxl2_0"" type=""checkbox"" name=""cbxl2$0"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_0"">x</label></span></td>
248
249         </tr><tr>
250                 <td><span disabled=""disabled""><input id=""cbxl2_1"" type=""checkbox"" name=""cbxl2$1"" disabled=""disabled"" /><label for=""cbxl2_1"">y</label></span></td>
251         </tr><tr>
252                 <td><span disabled=""disabled""><input id=""cbxl2_2"" type=""checkbox"" name=""cbxl2$2"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_2"">z</label></span></td>
253         </tr>
254 </table>";
255                         string origHtmlThird = @"<table id=""cbxl2"" disabled=""disabled"" border=""0"">
256         <tr>
257                 <td><span disabled=""disabled""><input id=""cbxl2_0"" type=""checkbox"" name=""cbxl2$0"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_0"">x</label></span></td>
258
259         </tr><tr>
260                 <td><span disabled=""disabled""><input id=""cbxl2_1"" type=""checkbox"" name=""cbxl2$1"" disabled=""disabled"" /><label for=""cbxl2_1"">y</label></span></td>
261         </tr><tr>
262                 <td><span disabled=""disabled""><input id=""cbxl2_2"" type=""checkbox"" name=""cbxl2$2"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_2"">z</label></span></td>
263         </tr>
264 </table>";
265                         string html = t.Run ();
266                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
267
268                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
269
270                         FormRequest fr = new FormRequest (t.Response, "form1");
271                         fr.Controls.Add ("cbxl2$0");
272                         fr.Controls ["cbxl2$0"].Value = "on";
273
274                         fr.Controls.Add ("cbxl2$2");
275                         fr.Controls ["cbxl2$2"].Value = "on";
276                         
277                         fr.Controls.Add ("ctl01");
278                         fr.Controls ["ctl01"].Value = "Click to toggle enable status above";
279
280                         t.Request = fr;
281                         html = t.Run ();
282
283                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
284
285                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
286                         
287                         fr = new FormRequest (t.Response, "form1");
288                         fr.Controls.Add ("ctl02");
289                         fr.Controls ["ctl02"].Value = "Click to refresh page";
290
291                         t.Request = fr;
292                         html = t.Run ();
293
294                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
295                         HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
296                 }
297
298                 public static void CheckBoxList_Bug377708_2_OnInit (Page p)
299                 {
300                         CheckBoxList cbxl2 = p.FindControl ("cbxl2") as CheckBoxList;
301                         
302                         cbxl2.DataSource = new[] {
303                                 new { ID = "x", Text = "X" },
304                                 new { ID = "y", Text = "Y" },
305                                 new { ID = "z", Text = "Z" },
306                         };
307                         cbxl2.DataValueField = "ID";
308                         cbxl2.DataTextField = "ID";
309                         cbxl2.DataBind();
310                 }
311
312                 [Test]
313                 public void CheckBoxList_Bug578770 ()
314                 {
315                         WebTest t = new WebTest ("CheckBoxList_Bug578770.aspx");
316                         t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug578770_OnInit);
317                         string origHtml = @"<table id=""test"" border=""0"">
318
319         <tr>
320                 <td><span disabled=""disabled""><input id=""test_0"" type=""checkbox"" name=""test$0"" disabled=""disabled"" /><label for=""test_0"">Sun</label></span></td>
321         </tr><tr>
322                 <td><input id=""test_1"" type=""checkbox"" name=""test$1"" /><label for=""test_1"">Mon</label></td>
323         </tr><tr>
324                 <td><input id=""test_2"" type=""checkbox"" name=""test$2"" /><label for=""test_2"">Tue</label></td>
325         </tr><tr>
326
327                 <td><input id=""test_3"" type=""checkbox"" name=""test$3"" /><label for=""test_3"">Wed</label></td>
328         </tr><tr>
329                 <td><input id=""test_4"" type=""checkbox"" name=""test$4"" /><label for=""test_4"">Thu</label></td>
330         </tr><tr>
331                 <td><input id=""test_5"" type=""checkbox"" name=""test$5"" /><label for=""test_5"">Fri</label></td>
332         </tr><tr>
333                 <td><input id=""test_6"" type=""checkbox"" name=""test$6"" /><label for=""test_6"">Sat</label></td>
334
335         </tr>
336 </table>";
337                         string html = t.Run ();
338                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
339
340                         HtmlDiff.AssertAreEqual (origHtml, listHtml, "#A1");
341                 }
342
343                 public static void CheckBoxList_Bug578770_OnInit (Page p)
344                 {
345                         CheckBoxList test = p.FindControl ("test") as CheckBoxList;
346                         string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
347                         test.DataSource = weekDays;
348                         test.DataBind();
349                         test.Items[0].Enabled = false;
350                 }
351                 
352                 [Test]
353                 public void RaisePostDataChangedEvent ()
354                 {
355                         CheckBoxListPoker c = new CheckBoxListPoker ();
356                         c.SelectedIndexChanged += new EventHandler (c_SelectedIndexChanged);
357                         Assert.AreEqual (false, eventSelectedIndexChanged, "RaisePostDataChangedEvent#1");
358                         c.RaisePostDataChangedEvent ();
359                         Assert.AreEqual (true, eventSelectedIndexChanged, "RaisePostDataChangedEvent#2");
360                 }
361
362                 bool eventSelectedIndexChanged;
363                 void c_SelectedIndexChanged (object sender, EventArgs e)
364                 {
365                         eventSelectedIndexChanged = true;
366                 }
367
368                 [Test]
369                 [Category("NunitWeb")]
370                 public void GetItemStyle ()
371                 {
372                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (GetItemStyle_Load));
373                         string html = t.Run ();
374                         string ctrl = HtmlDiff.GetControlFromPageHtml (html);
375                         if (ctrl == string.Empty)
376                                 Assert.Fail ("CheckBoxList not created fail");
377                         Assert.AreEqual ("GetItemStyle", (string) t.UserData, "GetItemStyle not done");
378                         if ( ctrl.IndexOf("<td style=\"background-color:Red;border-style:Solid;\">") == -1)
379                                 Assert.Fail ("CheckBoxList style not rendered");
380                 }
381
382                 public static void GetItemStyle_Load (Page p)
383                 {
384                         CheckBoxListPoker c = new CheckBoxListPoker ();
385                         ListItem l1 = new ListItem ("item1", "value1");
386                         ListItem l2 = new ListItem ("item2", "value2");
387
388                         c.Items.Add (l1);
389                         c.Items.Add (l2);
390                         p.Form.Controls.Add(new LiteralControl(HtmlDiff.BEGIN_TAG));
391                         p.Form.Controls.Add (c);
392                         p.Form.Controls.Add(new LiteralControl(HtmlDiff.END_TAG));
393                 }
394
395                 [Test]
396                 public void RenderItem ()
397                 {
398                         CheckBoxListPoker c = new CheckBoxListPoker ();
399                         ListItem l1 = new ListItem ("item1", "value1");
400                         ListItem l2 = new ListItem ("item2", "value2");
401
402                         c.Items.Add (l1);
403                         c.Items.Add (l2);
404                         string html = c.RenderItem (ListItemType.Item, 0, null);
405                         HtmlDiff.AssertAreEqual ("<input id=\"0\" type=\"checkbox\" name=\"0\" /><label for=\"0\">item1</label>", html, "RenderItem#1");
406                         html = c.RenderItem (ListItemType.Item, 1, null);
407                         HtmlDiff.AssertAreEqual ("<input id=\"1\" type=\"checkbox\" name=\"1\" /><label for=\"1\">item2</label>", html, "RenderItem#2");
408                 }
409
410                 [Test]
411                 public void RepeatedItemCount ()
412                 {
413                         CheckBoxListPoker c = new CheckBoxListPoker ();
414                         ListItem l1 = new ListItem ("item1", "value1");
415                         ListItem l2 = new ListItem ("item2", "value2");
416                         Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount#1");
417                         c.Items.Add (l1);
418                         c.Items.Add (l2);
419                         Assert.AreEqual (2, c.RepeatedItemCount, "RepeatedItemCount#2");
420                 }
421
422 #endif
423
424
425                 [Test]
426                 public void CleanProperties ()
427                 {
428                         CheckBoxList c = new CheckBoxList ();
429
430                         c.CellPadding = Int32.MaxValue;
431                         Assert.AreEqual (c.CellPadding, Int32.MaxValue, "A1");
432
433                         c.CellSpacing = Int32.MaxValue;
434                         Assert.AreEqual (c.CellSpacing, Int32.MaxValue, "A2");
435
436                         c.RepeatColumns = Int32.MaxValue;
437                         Assert.AreEqual (c.RepeatColumns, Int32.MaxValue, "A3");
438
439                         foreach (RepeatDirection d in
440                                         Enum.GetValues (typeof (RepeatDirection))) {
441                                 c.RepeatDirection = d;
442                                 Assert.AreEqual (c.RepeatDirection, d, "A4-" + d);
443                         }
444
445                         foreach (RepeatLayout l in
446                                         Enum.GetValues (typeof (RepeatLayout))) {
447                                 c.RepeatLayout = l;
448                                 Assert.AreEqual (c.RepeatLayout, l, "A5-" + l);
449                         }
450                 }
451
452                 [Test]
453                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
454                 public void CellPaddingTooLow ()
455                 {
456                         CheckBoxList c = new CheckBoxList ();
457                         c.CellPadding = -2;
458                 }
459
460                 [Test]
461                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
462                 public void CellSpacingTooLow ()
463                 {
464                         CheckBoxList c = new CheckBoxList ();
465                         c.CellSpacing = -2;
466                 }
467
468                 [Test]
469                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
470                 public void RepeatColumsTooLow ()
471                 {
472                         CheckBoxList c = new CheckBoxList ();
473                         c.RepeatColumns = -1;
474                 }
475
476                 [Test]
477                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
478                 public void RepeatDirection_Invalid ()
479                 {
480                         CheckBoxList c = new CheckBoxList ();
481                         c.RepeatDirection = (RepeatDirection) Int32.MaxValue;
482                 }
483
484                 [Test]
485                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
486                 public void RepeatLayout_Invalid ()
487                 {
488                         CheckBoxList c = new CheckBoxList ();
489                         c.RepeatLayout = (RepeatLayout) Int32.MaxValue;
490                 }
491
492                 [Test]
493                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
494                 public void TextAlign_Invalid ()
495                 {
496                         CheckBoxList c = new CheckBoxList ();
497                         c.TextAlign = (TextAlign) Int32.MaxValue;
498                 }
499
500                 [Test]
501                 public void ChildCheckBoxControl ()
502                 {
503                         CheckBoxList c = new CheckBoxList ();
504                         Assert.AreEqual (c.Controls.Count, 1, "A1");
505                         Assert.AreEqual (c.Controls [0].GetType (), typeof (CheckBox), "A2");
506                 }
507
508                 [Test]
509                 public void CreateStyle ()
510                 {
511                         CheckBoxListPoker c = new CheckBoxListPoker ();
512                         Assert.AreEqual (c.CreateStyle ().GetType (), typeof (TableStyle), "A1");
513                 }
514
515                 [Test]
516                 public void RepeatInfoProperties ()
517                 {
518                         IRepeatInfoUser ri = new CheckBoxList ();
519
520                         Assert.IsFalse (ri.HasFooter, "A1");
521                         Assert.IsFalse (ri.HasHeader, "A2");
522                         Assert.IsFalse (ri.HasSeparators, "A3");
523                         Assert.AreEqual (ri.RepeatedItemCount, 0, "A4");
524                 }
525
526                 [Test]
527                 public void RepeatInfoCount ()
528                 {
529                         CheckBoxList c = new CheckBoxList ();
530                         IRepeatInfoUser ri = (IRepeatInfoUser) c;
531
532                         Assert.AreEqual (ri.RepeatedItemCount, 0, "A1");
533
534                         c.Items.Add ("one");
535                         c.Items.Add ("two");
536                         c.Items.Add ("three");
537                         Assert.AreEqual (ri.RepeatedItemCount, 3, "A2");
538                 }
539
540                 [Test]
541                 public void RepeatInfoStyle ()
542                 {
543                         IRepeatInfoUser ri = new CheckBoxList ();
544
545                         foreach (ListItemType t in Enum.GetValues (typeof (ListItemType))) {
546                                 Assert.AreEqual (ri.GetItemStyle (t, 0), null, "A1-" + t);
547                                 Assert.AreEqual (ri.GetItemStyle (t, 1), null, "A2-" + t);
548                                 Assert.AreEqual (ri.GetItemStyle (t, 2), null, "A3-" + t);
549                                 Assert.AreEqual (ri.GetItemStyle (t, 3), null, "A4-" + t);
550                         }
551                 }
552
553                 [Test]
554                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
555                 public void RepeatInfoRenderOutOfRange ()
556                 {
557                         StringWriter sw = new StringWriter ();
558                         HtmlTextWriter tw = new HtmlTextWriter (sw);
559                         IRepeatInfoUser ri = new CheckBoxList ();
560
561                         ri.RenderItem (ListItemType.Item, -1, new RepeatInfo (), tw); 
562                 }
563
564                 [Test]
565                 public void RepeatInfoRenderItem ()
566                 {
567                         StringWriter sw = new StringWriter ();
568                         HtmlTextWriter tw = new HtmlTextWriter (sw);
569                         CheckBoxList c = new CheckBoxList ();
570                         IRepeatInfoUser ri = (IRepeatInfoUser) c;
571                         RepeatInfo r = new RepeatInfo ();
572
573                         c.Items.Add ("one");
574                         c.Items.Add ("two");
575
576                         ri.RenderItem (ListItemType.Item, 0, r, tw); 
577                         Assert.AreEqual ("<input id=\"0\" type=\"checkbox\" name=\"0\" />" +
578                                         "<label for=\"0\">one</label>", sw.ToString (), "A1");
579                 }
580
581                 [Test]
582                 public void FindControl ()
583                 {
584                         CheckBoxListPoker p = new CheckBoxListPoker ();
585
586                         p.ID = "id";
587                         p.Items.Add ("one");
588                         p.Items.Add ("two");
589                         p.Items.Add ("three");
590
591                         // Everything seems to return this.
592                         Assert.AreEqual (p.FindControlPoke (String.Empty, 0), p, "A1");
593                         Assert.AreEqual (p.FindControlPoke ("id", 0), p, "A2");
594                         Assert.AreEqual (p.FindControlPoke ("id_0", 0), p, "A3");
595                         Assert.AreEqual (p.FindControlPoke ("id_1", 0), p, "A4");
596                         Assert.AreEqual (p.FindControlPoke ("id_2", 0), p, "A5");
597                         Assert.AreEqual (p.FindControlPoke ("id_3", 0), p, "A6");
598                         Assert.AreEqual (p.FindControlPoke ("0", 0), p, "A7");
599
600                         Assert.AreEqual (p.FindControlPoke (String.Empty, 10), p, "A1");
601                         Assert.AreEqual (p.FindControlPoke ("id", 10), p, "A2");
602                         Assert.AreEqual (p.FindControlPoke ("id_0", 10), p, "A3");
603                         Assert.AreEqual (p.FindControlPoke ("id_1", 10), p, "A4");
604                         Assert.AreEqual (p.FindControlPoke ("id_2", 10), p, "A5");
605                         Assert.AreEqual (p.FindControlPoke ("id_3", 10), p, "A6");
606                         Assert.AreEqual (p.FindControlPoke ("0", 10), p, "A7");
607                 }
608
609                 private void Render (CheckBoxList list, string expected, string test)
610                 {
611                         StringWriter sw = new StringWriter ();
612                         HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
613                         sw.NewLine = "\n";
614
615                         list.RenderControl (tw);
616                         HtmlDiff.AssertAreEqual (expected, sw.ToString (), test);
617                 }
618
619                 [Test]
620                 public void RenderEmpty ()
621                 {
622                         CheckBoxList c = new CheckBoxList ();
623
624 #if NET_2_0
625                         Render (c, "", "A1");
626 #else
627                         Render (c, "<table border=\"0\">\n\n</table>", "A1");
628 #endif
629                         c.CellPadding = 1;
630 #if NET_2_0
631                         Render (c, "", "A2");
632 #else
633                         Render (c, "<table border=\"0\" cellpadding=\"1\">\n\n</table>", "A2");
634 #endif
635
636                         c = new CheckBoxList ();
637                         c.CellPadding = 1;
638 #if NET_2_0
639                         Render (c, "", "A3");
640 #else
641                         Render (c, "<table border=\"0\" cellpadding=\"1\">\n\n</table>", "A3");
642 #endif
643
644                         c = new CheckBoxList ();
645                         c.TextAlign = TextAlign.Left;
646 #if NET_2_0
647                         Render (c, "", "A4");
648 #else
649                         Render (c, "<table border=\"0\">\n\n</table>", "A4");
650 #endif
651                 }
652
653                 [Test]
654 #if NET_2_0
655                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
656 #endif
657                 public void Render ()
658                 {
659                         CheckBoxList c;
660                         c = new CheckBoxList ();
661                         c.Items.Add ("foo");
662                         Render (c, "<table border=\"0\">\n\t<tr>\n\t\t<td><input id=\"0\" " +
663                                         "name=\"0\" type=\"checkbox\" />" +
664                                         "<label for=\"0\">foo</label>" +
665                                         "</td>\n\t</tr>\n</table>", "A5");
666
667                         c = new CheckBoxList ();
668                         c.Items.Add ("foo");
669                         Render (c, "<table border=\"0\">\n\t<tr>\n\t\t<td><input id=\"0\" " +
670                                         "name=\"0\" type=\"checkbox\" />" +
671                                         "<label for=\"0\">foo</label>" +
672                                         "</td>\n\t</tr>\n</table>", "A6");
673                 }
674
675                 // bug 51648
676                 [Test]
677 #if NET_2_0
678                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
679 #endif
680                 public void TestTabIndex ()
681                 {
682                         CheckBoxList c = new CheckBoxList ();
683                         c.TabIndex = 5;
684                         c.Items.Add ("Item1");
685                         string exp = @"<table border=""0"">
686         <tr>
687                 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" /><label for=""0"">Item1</label></td>
688         </tr>
689 </table>";
690                         Render (c, exp, "B1");
691                 }
692
693                 // bug 48802
694                 [Test]
695 #if NET_2_0
696                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
697 #endif
698                 public void TestDisabled ()
699                 {
700                         CheckBoxList c = new CheckBoxList ();
701                         c.Enabled = false;
702                         c.Items.Add ("Item1");
703                         string exp = @"<table border=""0"" disabled=""disabled"">
704         <tr>
705                 <td><span disabled=""disabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" /><label for=""0"">Item1</label></span></td>
706         </tr>
707 </table>";
708                         Render (c, exp, "C1");
709                 }       
710 #if NET_2_0
711         class TestCheckBoxList : CheckBoxList
712         {
713             public new virtual void VerifyMultiSelect()
714             {
715                 base.VerifyMultiSelect();
716             }
717         }
718         [Test]
719         public void VerifyMultiSelectTest()
720         {
721             TestCheckBoxList list = new TestCheckBoxList();
722             list.VerifyMultiSelect();
723         }
724         [TestFixtureTearDown]
725                 public void teardown ()
726                 {
727                         WebTest.Unload ();
728                 }
729 #endif
730         }
731 }
732
733