You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2014/07/22 13:44:46 UTC

[1/2] git commit: WICKET-5650 Make is possible to position the choice label before/after/around the choice

Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x d38050896 -> 5d47267e9


WICKET-5650 Make is possible to position the choice label before/after/around the choice


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f9668b5e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f9668b5e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f9668b5e

Branch: refs/heads/wicket-6.x
Commit: f9668b5ea6d4dfc196409dff588a06dd5b9ea571
Parents: d380508
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jul 21 17:26:14 2014 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Jul 22 14:37:16 2014 +0300

----------------------------------------------------------------------
 .../wicket/markup/html/form/AbstractChoice.java |  27 ++++
 .../html/form/CheckBoxMultipleChoice.java       |  65 ++++++++--
 .../wicket/markup/html/form/RadioChoice.java    | 124 +++++++++++++------
 .../markup/html/form/RadioChoiceTest.java       |  64 ++++++++++
 4 files changed, 234 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/f9668b5e/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
index b094a54..f0de7df 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
@@ -50,6 +50,32 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 {
 	private static final long serialVersionUID = 1L;
 
+	/**
+	 * An enumeration of possible positions of the label for a choice
+	 */
+	public static enum LabelPosition
+	{
+		/**
+		 * will render the label before the choice
+		 */
+		BEFORE,
+
+		/**
+		 * will render the label after the choice
+		 */
+		AFTER,
+
+		/**
+		 * render the label around and the text will be before the the choice
+		 */
+		WRAP_BEFORE,
+
+		/**
+		 * render the label around and the text will be after the the choice
+		 */
+		WRAP_AFTER
+	}
+
 	/** The list of objects. */
 	private IModel<? extends List<? extends E>> choices;
 
@@ -262,6 +288,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 	 * Set the choice renderer to be used.
 	 * 
 	 * @param renderer
+	 *              The IChoiceRenderer used for rendering the data objects
 	 * @return this for chaining
 	 */
 	public final AbstractChoice<T, E> setChoiceRenderer(IChoiceRenderer<? super E> renderer)

http://git-wip-us.apache.org/repos/asf/wicket/blob/f9668b5e/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
index c8ff1f6..31a1d88 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
@@ -25,6 +25,7 @@ import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.util.convert.IConverter;
+import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.string.AppendingStringBuffer;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.value.IValueMap;
@@ -69,6 +70,8 @@ public class CheckBoxMultipleChoice<T> extends ListMultipleChoice<T>
 	private String prefix = "";
 	private String suffix = "<br/>\n";
 
+	private LabelPosition labelPosition = LabelPosition.AFTER;
+
 	/**
 	 * Constructor
 	 * 
@@ -308,6 +311,20 @@ public class CheckBoxMultipleChoice<T> extends ListMultipleChoice<T>
 	}
 
 	/**
+	 * Sets the preferred position of the &lt;label&gt; for each choice
+	 *
+	 * @param labelPosition
+	 *              The preferred position for the label
+	 * @return {@code this} instance, for chaining
+	 */
+	public CheckBoxMultipleChoice<T> setLabelPosition(LabelPosition labelPosition)
+	{
+		Args.notNull(labelPosition, "labelPosition");
+		this.labelPosition = labelPosition;
+		return this;
+	}
+
+	/**
 	 * @see org.apache.wicket.markup.html.form.ListMultipleChoice#onComponentTag(org.apache.wicket.markup.ComponentTag)
 	 */
 	@Override
@@ -393,6 +410,31 @@ public class CheckBoxMultipleChoice<T> extends ListMultipleChoice<T>
 			String id = getChoiceRenderer().getIdValue(choice, index);
 			final String idAttr = getCheckBoxMarkupId(id);
 
+			// Add label for checkbox
+			String display = label;
+			if (localizeDisplayValues())
+			{
+				display = getLocalizer().getString(label, this, label);
+			}
+
+			final CharSequence escaped = (getEscapeModelStrings() ? Strings.escapeMarkup(display)
+					: display);
+
+			switch (labelPosition)
+			{
+				case BEFORE:
+					buffer.append("<label for=\"");
+					buffer.append(idAttr);
+					buffer.append("\">").append(escaped).append("</label>");
+					break;
+				case WRAP_AFTER:
+					buffer.append("<label>");
+				case WRAP_BEFORE:
+					buffer.append("<label>");
+					buffer.append(escaped).append(' ');
+					break;
+			}
+
 			// Add checkbox element
 			buffer.append("<input name=\"");
 			buffer.append(getInputName());
@@ -442,20 +484,21 @@ public class CheckBoxMultipleChoice<T> extends ListMultipleChoice<T>
 
 			buffer.append("/>");
 
-			// Add label for checkbox
-			String display = label;
-			if (localizeDisplayValues())
+			switch (labelPosition)
 			{
-				display = getLocalizer().getString(label, this, label);
+				case WRAP_BEFORE:
+					buffer.append("</label>");
+					break;
+				case WRAP_AFTER:
+					buffer.append(' ').append(escaped).append("</label>");
+					break;
+				case AFTER:
+					buffer.append("<label for=\"");
+					buffer.append(idAttr);
+					buffer.append("\">").append(escaped).append("</label>");
+					break;
 			}
 
-			final CharSequence escaped = (getEscapeModelStrings() ? Strings.escapeMarkup(display)
-				: display);
-
-			buffer.append("<label for=\"");
-			buffer.append(idAttr);
-			buffer.append("\">").append(escaped).append("</label>");
-
 			// Append option suffix
 			buffer.append(getSuffix(index, choice));
 		}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f9668b5e/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
index 73720a2..1218065 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
@@ -24,6 +24,7 @@ import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.wicket.util.convert.IConverter;
+import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.string.AppendingStringBuffer;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.value.IValueMap;
@@ -70,6 +71,8 @@ public class RadioChoice<T> extends AbstractSingleSelectChoice<T> implements IOn
 	private String prefix = "";
 	private String suffix = "<br />\n";
 
+	private LabelPosition labelPosition = LabelPosition.AFTER;
+
 	/**
 	 * Constructor
 	 * 
@@ -362,6 +365,20 @@ public class RadioChoice<T> extends AbstractSingleSelectChoice<T> implements IOn
 	}
 
 	/**
+	 * Sets the preferred position of the &lt;label&gt; for each choice
+	 *
+	 * @param labelPosition
+	 *              The preferred position for the label
+	 * @return {@code this} instance, for chaining
+	 */
+	public RadioChoice<T> setLabelPosition(LabelPosition labelPosition)
+	{
+		Args.notNull(labelPosition, "labelPosition");
+		this.labelPosition = labelPosition;
+		return this;
+	}
+
+	/**
 	 * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
 	 */
 	@Override
@@ -437,6 +454,60 @@ public class RadioChoice<T> extends AbstractSingleSelectChoice<T> implements IOn
 
 			boolean enabled = isEnabledInHierarchy() && !isDisabled(choice, index, selected);
 
+			// Add label for radio button
+			String display = label;
+			if (localizeDisplayValues())
+			{
+				display = getLocalizer().getString(label, this, label);
+			}
+
+			CharSequence escaped = display;
+			if (getEscapeModelStrings())
+			{
+				escaped = Strings.escapeMarkup(display);
+			}
+
+			// Allows user to add attributes to the <label..> tag
+			IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
+			StringBuilder extraLabelAttributes = new StringBuilder();
+			if (labelAttrs != null)
+			{
+				for (Map.Entry<String, Object> attr : labelAttrs.entrySet())
+				{
+					extraLabelAttributes.append(' ')
+							.append(attr.getKey())
+							.append("=\"")
+							.append(attr.getValue())
+							.append('"');
+				}
+			}
+
+			switch (labelPosition)
+			{
+				case BEFORE:
+
+					buffer.append("<label for=\"")
+							.append(idAttr)
+							.append('"')
+							.append(extraLabelAttributes)
+							.append('>')
+							.append(escaped)
+							.append("</label>");
+					break;
+				case WRAP_BEFORE:
+					buffer.append("<label")
+							.append(extraLabelAttributes)
+							.append('>')
+							.append(escaped)
+							.append(' ');
+					break;
+				case WRAP_AFTER:
+					buffer.append("<label")
+							.append(extraLabelAttributes)
+							.append('>');
+					break;
+			}
+
 			// Add radio tag
 			buffer.append("<input name=\"")
 				.append(getInputName())
@@ -506,44 +577,27 @@ public class RadioChoice<T> extends AbstractSingleSelectChoice<T> implements IOn
 
 			buffer.append("/>");
 
-			// Add label for radio button
-			String display = label;
-			if (localizeDisplayValues())
-			{
-				display = getLocalizer().getString(label, this, label);
-			}
-
-			CharSequence escaped = display;
-			if (getEscapeModelStrings())
-			{
-				escaped = Strings.escapeMarkup(display);
-			}
-
-			buffer.append("<label for=\"")
-				.append(idAttr)
-				.append('"');
-
-			// Allows user to add attributes to the <label..> tag
+			switch (labelPosition)
 			{
-				IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
-				if (labelAttrs != null)
-				{
-					for (Map.Entry<String, Object> attr : labelAttrs.entrySet())
-					{
-						buffer.append(' ')
-								.append(attr.getKey())
-								.append("=\"")
-								.append(attr.getValue())
-								.append('"');
-					}
-				}
+				case AFTER:
+					buffer.append("<label for=\"")
+							.append(idAttr)
+							.append('"')
+							.append(extraLabelAttributes)
+							.append('>')
+							.append(escaped)
+							.append("</label>");
+					break;
+				case WRAP_BEFORE:
+					buffer.append("</label>");
+					break;
+				case WRAP_AFTER:
+					buffer.append(' ')
+							.append(escaped)
+							.append("</label>");
+					break;
 			}
 
-			buffer
-				.append('>')
-				.append(escaped)
-				.append("</label>");
-
 			// Append option suffix
 			buffer.append(getSuffix(index, choice));
 		}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f9668b5e/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
new file mode 100644
index 0000000..496a389
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.html.form;
+
+import java.util.Arrays;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Test;
+
+public class RadioChoiceTest extends WicketTestCase
+{
+	@Test
+	public void defaultLabelPositionIsAfter() throws Exception
+	{
+		RadioChoice<Integer> radioChoice = new RadioChoice<Integer>("id", Arrays.asList(1));
+		tester.startComponentInPage(radioChoice);
+
+		tester.assertResultPage("<span wicket:id=\"id\"><input name=\"id\" type=\"radio\" value=\"0\" id=\"id1-0\"/><label for=\"id1-0\">1</label><br />\n</span>");
+	}
+
+	@Test
+	public void labelPositionBefore() throws Exception
+	{
+		RadioChoice<Integer> radioChoice = new RadioChoice<Integer>("id", Arrays.asList(1));
+		radioChoice.setLabelPosition(AbstractChoice.LabelPosition.BEFORE);
+		tester.startComponentInPage(radioChoice);
+
+		tester.assertResultPage("<span wicket:id=\"id\"><label for=\"id1-0\">1</label><input name=\"id\" type=\"radio\" value=\"0\" id=\"id1-0\"/><br />\n</span>");
+	}
+
+	@Test
+	public void labelPositionWrapBefore() throws Exception
+	{
+		RadioChoice<Integer> radioChoice = new RadioChoice<Integer>("id", Arrays.asList(1));
+		radioChoice.setLabelPosition(AbstractChoice.LabelPosition.WRAP_BEFORE);
+		tester.startComponentInPage(radioChoice);
+
+		tester.assertResultPage("<span wicket:id=\"id\"><label>1 <input name=\"id\" type=\"radio\" value=\"0\" id=\"id1-0\"/></label><br />\n</span>");
+	}
+
+	@Test
+	public void labelPositionWrapAfter() throws Exception
+	{
+		RadioChoice<Integer> radioChoice = new RadioChoice<Integer>("id", Arrays.asList(1));
+		radioChoice.setLabelPosition(AbstractChoice.LabelPosition.WRAP_AFTER);
+		tester.startComponentInPage(radioChoice);
+
+		tester.assertResultPage("<span wicket:id=\"id\"><label><input name=\"id\" type=\"radio\" value=\"0\" id=\"id1-0\"/> 1</label><br />\n</span>");
+	}
+}


[2/2] git commit: WICKET-5651 Add TagTester#getChild(String tagName) method

Posted by mg...@apache.org.
WICKET-5651 Add TagTester#getChild(String tagName) method


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5d47267e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5d47267e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5d47267e

Branch: refs/heads/wicket-6.x
Commit: 5d47267e94ba2eae0d188132774cc2dc61b03f68
Parents: f9668b5
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Jul 22 14:41:38 2014 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Jul 22 14:41:38 2014 +0300

----------------------------------------------------------------------
 .../apache/wicket/util/tester/TagTester.java    | 127 +++++++++++++++++--
 .../wicket/util/tester/TagTesterTest.java       |  24 ++++
 2 files changed, 141 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/5d47267e/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java
index e5a27af..827aabb 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java
@@ -24,6 +24,7 @@ import java.util.regex.Pattern;
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.markup.parser.XmlPullParser;
 import org.apache.wicket.markup.parser.XmlTag;
+import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.value.IValueMap;
 
@@ -235,19 +236,16 @@ public class TagTester
 
 	/**
 	 * Checks if the tag has a child with the given <code>tagName</code>.
-	 * 
+	 *
 	 * @param tagName
 	 *            the tag name to search for
 	 * @return <code>true</code> if this tag has a child with the given <code>tagName</code>.
 	 */
 	public boolean hasChildTag(String tagName)
 	{
-		boolean hasChild = false;
+		Args.notEmpty(tagName, "tagName");
 
-		if (Strings.isEmpty(tagName))
-		{
-			throw new IllegalArgumentException("You need to provide a not empty/not null argument.");
-		}
+		boolean hasChild = false;
 
 		if (openTag.isOpen())
 		{
@@ -263,7 +261,7 @@ public class TagTester
 					XmlPullParser p = new XmlPullParser();
 					p.parse(markup);
 
-					XmlTag tag = null;
+					XmlTag tag;
 					while ((tag = p.nextTag()) != null)
 					{
 						if (tagName.equalsIgnoreCase(tag.getName()))
@@ -276,16 +274,40 @@ public class TagTester
 			}
 			catch (Exception e)
 			{
-				// NOTE: IllegalStateException(Throwable) only exists since Java 1.5
 				throw new WicketRuntimeException(e);
 			}
-
 		}
 
 		return hasChild;
 	}
 
 	/**
+	 * Checks if the tag has a child with the given <code>tagName</code>.
+	 *
+	 * @param tagName
+	 *            the tag name to search for
+	 * @return <code>true</code> if this tag has a child with the given <code>tagName</code>.
+	 */
+	public TagTester getChild(String tagName)
+	{
+		Args.notNull(tagName, "tagName");
+
+		TagTester childTagTester = null;
+
+		if (openTag.isOpen())
+		{
+			// Get the content of the tag
+			int startPos = openTag.getPos() + openTag.getLength();
+			int endPos = closeTag.getPos();
+			String markup = parser.getInput(startPos, endPos).toString();
+
+			childTagTester = createTagByAttribute(markup, tagName);
+		}
+
+		return childTagTester;
+	}
+
+	/**
 	 * Gets a child tag for testing. If this tag contains child tags, you can get one of them as a
 	 * {@link TagTester} instance.
 	 * 
@@ -343,6 +365,92 @@ public class TagTester
 	}
 
 	/**
+	 * Static factory method for creating a <code>TagTester</code> based on a tag name. Please note
+	 * that it will return the first tag which matches the criteria.
+	 *
+	 * @param markup
+	 *            the markup to look for the tag to create the <code>TagTester</code> from
+	 *            the value which the attribute must have
+	 * @return the <code>TagTester</code> which matches the tag by name in the markup
+	 */
+	public static TagTester createTagByAttribute(String markup, String tagName)
+	{
+		TagTester tester = null;
+
+		if (Strings.isEmpty(markup) == false && Strings.isEmpty(tagName) == false)
+		{
+			try
+			{
+				// remove the CDATA and
+				// the id attribute of the component because it is often the same as the element's id
+				markup = AJAX_COMPONENT_CDATA_OPEN.matcher(markup).replaceAll("<component>");
+				markup = AJAX_COMPONENT_CDATA_CLOSE.matcher(markup).replaceAll("</component>");
+
+				XmlPullParser parser = new XmlPullParser();
+				parser.parse(markup);
+
+				XmlTag elm;
+				XmlTag openTag = null;
+				XmlTag closeTag = null;
+				int level = 0;
+				while ((elm = parser.nextTag()) != null && closeTag == null)
+				{
+					XmlTag xmlTag = elm;
+
+					String xmlTagName = xmlTag.getName();
+					if (openTag == null && xmlTagName.equalsIgnoreCase(tagName))
+					{
+						if (xmlTag.isOpen())
+						{
+							openTag = xmlTag;
+						}
+						else if (xmlTag.isOpenClose())
+						{
+							openTag = xmlTag;
+							closeTag = xmlTag;
+						}
+					}
+					else if (openTag != null)
+					{
+						String openTagName = openTag.getName();
+						if (xmlTag.isOpen() && xmlTagName.equals(openTagName))
+						{
+							level++;
+						}
+
+						if (xmlTag.isClose())
+						{
+							if (xmlTagName.equals(openTagName))
+							{
+								if (level == 0)
+								{
+									closeTag = xmlTag;
+									closeTag.setOpenTag(openTag);
+								}
+								else
+								{
+									level--;
+								}
+							}
+						}
+					}
+				}
+
+				if (openTag != null && closeTag != null)
+				{
+					tester = new TagTester(parser, openTag, closeTag);
+				}
+			}
+			catch (Exception e)
+			{
+				throw new WicketRuntimeException(e);
+			}
+		}
+
+		return tester;
+	}
+
+	/**
 	 * Static factory method for creating a <code>TagTester</code> based on a tag found by an
 	 * attribute with a specific value. Please note that it will return the first tag which matches
 	 * the criteria. It's therefore good for attributes such as "id" or "wicket:id", but only if
@@ -435,7 +543,6 @@ public class TagTester
 			}
 			catch (Exception e)
 			{
-				// NOTE: IllegalStateException(Throwable) only exists since Java 1.5
 				throw new WicketRuntimeException(e);
 			}
 		}

http://git-wip-us.apache.org/repos/asf/wicket/blob/5d47267e/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java
index 5674436..8041601 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java
@@ -16,6 +16,11 @@
  */
 package org.apache.wicket.util.tester;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -250,6 +255,25 @@ public class TagTesterTest extends Assert
 		assertFalse(tester.hasChildTag("p"));
 	}
 
+	@Test
+	public void getChildByTagName()
+	{
+		TagTester tester = TagTester.createTagByAttribute(
+			"<div id=\"id\">" +
+				"<div class=\"radio\">" +
+					"<label>" +
+						"<input name=\"id\" type=\"radio\" value=\"0\" id=\"id1-0\"/> One" +
+					"</label>" +
+				"</div>" +
+			"</div>", "id", "id");
+		assertThat(tester.getChild("DIV"), is(notNullValue())); // case-insensitive
+		TagTester divClassRadioTagTester = tester.getChild("div");
+		assertThat(divClassRadioTagTester, is(notNullValue()));
+		TagTester labelTagTester = divClassRadioTagTester.getChild("label");
+		String labelMarkup = labelTagTester.getValue();
+		assertThat(labelMarkup, endsWith(" One"));
+	}
+
 	/**
 	 * Test getMarkup returns the open-tag + content + close-tag
 	 */