public void EnabledInEnabledOptGroup() { var dom = CQ.CreateFragment(@"<select><optgroup><option>a</option></optgroup></select>"); var e = dom["option"].FirstElement(); Assert.IsFalse(e.Disabled); }
public void Disabled() { var dom = CQ.CreateFragment(@"<select><option disabled>a</option></select>"); var e = dom["option"].FirstElement(); Assert.IsTrue(e.Disabled); }
private Report CreateReportFromCqObj(string reportHtml) { var reportDom = CQ.CreateFragment(reportHtml)["td"]; try { var publicationDateTime = GetPublicationDateTime(reportDom[0].InnerText); if (publicationDateTime.TimeOfDay <= LastReportsCheckDateTime.TimeOfDay) { return(null); } return(new Report { PublicationDateTime = publicationDateTime, CompanyName = GetCompanyName(reportDom[2].InnerHTML), ReportLink = GetReportLink(reportDom[3].InnerHTML), ReportKind = GetReportKind(reportDom[3].InnerHTML) }); } catch (Exception ex) { Log.ErrorFormat("Exception is thrown from reason {0}", ex.Message); return(new Report()); } }
public void DisabledOtherValue() { var dom = CQ.CreateFragment(@"<input disabled='yes'>"); IDomElement e = dom["input"].FirstElement(); Assert.IsTrue(e.Disabled); }
public void CreateFromElements() { var dom1 = CQ.CreateFragment("<div id='doc1-div1'><div id='doc1-div2'>innertext</div></div>"); var dom2 = CQ.CreateFragment("<div id='doc2-div1'><div id='doc2-div2'>innertext</div></div>"); var el = dom1["#doc1-div2"][0]; dom2["#doc2-div1"].Append(el); // should be moved when done this way Assert.AreEqual(0, dom1["#doc1-div2"].Length); Assert.AreEqual(2, dom2["#doc2-div1"].Children().Length); // move it back dom1["#doc1-div1"].Append(dom2["#doc1-div2"]); Assert.AreEqual(1, dom1["#doc1-div2"].Length); Assert.AreEqual(1, dom2["#doc2-div1"].Children().Length); // This time it should be added to the target, and not removed from the source. var els = CQ.CreateFragment(dom1["#doc1-div2"]); dom2["#doc2-div1"].Append(els); Assert.AreEqual(1, dom1["#doc1-div2"].Length); Assert.AreEqual(2, dom2["#doc2-div1"].Children().Length); }
public void DisabledDefault() { var dom = CQ.CreateFragment(@"<input>"); IDomElement e = dom["input"].FirstElement(); Assert.IsFalse(e.Disabled); }
/// <summary> /// Includes a Javascript file inline. /// </summary> /// /// <param name="helper"> /// The current helper context. /// </param> /// <param name="script"> /// Full pathname of the server file. /// </param> /// <param name="attributes"> /// (optional) the attributes. /// </param> /// <param name="location"> /// (optional) The location of the script. This parameter can be used to move the script into the /// <head> tag of the document. /// </param> /// /// <returns> /// An HtmlString. /// </returns> public static IHtmlString Script <T>(this HtmlHelper <T> helper, string script, object attributes, ScriptLocations location) { string path = PathList.NormalizePath(PathList.NormalizeName(script)); var el = CQ.CreateFragment("<script />"); if (attributes != null) { el.AttrSet(attributes); } if (!el.HasAttr("type")) { el.Attr("type", "text/javascript"); } el.Attr("src", script + (script.EndsWith(".js", StringComparison.CurrentCultureIgnoreCase) ? "" : ".js") ); if (location == ScriptLocations.Head) { el.Attr("data-moveto", "head"); } return(new HtmlString(el.Render())); }
public static WikipediaAlbumParseResult Parse(string data) { WikipediaAlbumParseResult result = new WikipediaAlbumParseResult(); var dom = CQ.CreateFragment(data); var title = dom.Select("h1.firstHeading").Text(); if (string.IsNullOrEmpty(title)) { return(null); } result.PageTitle = title; var published = dom.Select(".published").Html(); published = Strip(published); try { result.ReleaseDates = ParseWikipediaReleaseDate(published); } catch { result.ReleaseDates = new ReleaseDate[] { }; } return(result); }
/// <summary> /// Returns a CQ object from a view's HTML output /// </summary> /// /// <typeparam name="T"> /// Controller type /// </typeparam> /// <param name="action"> /// The action to invoke on the view /// </param> /// /// <returns> /// A CQ object /// </returns> public static CQ RenderViewCQ <T>(string action) where T : Controller, new() { // Use "CreateFragment" when testing HTML output because we don't want CsQuery to do any // infilling of optional tags, etc. - we want to see what actually was produced. return(CQ.CreateFragment(TestConfig.Host.RenderView <T>(action))); }
public void Html_Create() { Assert.IsTrue(jQuery("<link rel='stylesheet'/>").Length > 0, "Creating a link"); Assert.AreEqual(jQuery("<script/>")[0].ParentNode, null, "Create a script"); Assert.IsTrue(jQuery("<input/>").Attr("type", "hidden").Length > 0, "Create an input and set the type."); var j = CQ.CreateFragment("<span>hi</span> there <!-- mon ami -->"); Assert.IsTrue(j.Length == 3, "Check node,textnode,comment creation (some browsers delete comments [but not csQuery])"); Assert.AreEqual(NodeType.COMMENT_NODE, j.Get(2).NodeType, "Third node is a comment"); Assert.IsTrue(!jQuery("<option>test</option>")[0].Selected, "Make sure that options are auto-selected #2050"); Assert.IsTrue(jQuery("<div></div>").Length > 0, "Create a div with closing tag."); Assert.IsTrue(jQuery("<table></table>").Length > 0, "Create a table with closing tag."); var li = "<li>very large html string</li>"; StringBuilder sb = new StringBuilder(); sb.Append("<ul>"); for (int i = 0; i < 50000; i += 1) { sb.Append(li); } sb.Append("</ul>"); var el = CQ.CreateFragment(sb.ToString())[0]; Assert.AreEqual(el.NodeName.ToUpper(), "UL"); Assert.AreEqual(el.FirstChild.NodeName.ToUpper(), "LI"); Assert.AreEqual(el.ChildNodes.Length, 50000); }
public void SingleSelect() { var dom = CQ.CreateFragment(@"<select><option value='1'><option>second<option value='3'>third</option></select>"); var el = (IHTMLSelectElement)dom["select"][0]; // default is 1st item selected Assert.AreEqual("1", el.Value); dom["option:eq(1)"].Prop("selected", true); Assert.AreEqual("second", el.Value); // should change to the last selected option dom["option:last-child"].Prop("selected", true); Assert.AreEqual("3", el.Value); // nothing should happen here dom["option:eq(2)"].Prop("selected", true); Assert.AreEqual("3", el.Value); // ... but this should result in only dom["option:eq(1)"][0].Selected = true; Assert.AreEqual("second", el.Value); el.SelectedIndex = 0; Assert.AreEqual("1", el.Value); // In a real browsers, you could set a non-multiple select to be nothing, but there's no way to // represent that state in HTML so ours still falls back on the first option. el.SelectedIndex = -1; Assert.AreEqual("1", el.Value); }
public void AttributeHandling() { string test1html = "<input type=\"text\" id=\"\" checked custom=\"sometext\">"; var dom = CQ.CreateFragment(test1html); Assert.AreEqual("<input type=\"text\" id checked custom=\"sometext\">", dom.Render(), "Missing & boolean attributes are parsed & render correctly"); // remove "quote all attributes" Assert.AreEqual("<input type=text id checked custom=sometext>", dom.Render(DomRenderingOptions.None), "Missing & boolean attributes are parsed & render correctly"); dom = CQ.CreateFragment("<div id='test' quotethis=\"must've\" class=\"one two\" data='\"hello\"' noquote=\"regulartext\">"); var expected = "<div class=\"one two\" id=test quotethis=\"must've\" data='\"hello\"' noquote=regulartext></div>"; Assert.AreEqual(expected, dom.Render(DomRenderingOptions.None), "Handle various quoting situations"); // go back to test 1 dom = CQ.CreateFragment(test1html); var jq = dom["input"]; var el = jq[0]; Assert.AreEqual("", el["id"], "Empty attribute is empty"); Assert.AreEqual("", el["checked"], "Boolean attribute is the same as empty"); Assert.AreEqual(null, el["missing"], "Missing attribute is null"); Assert.AreEqual("", jq.Attr("id"), "Empty attribute is empty"); Assert.AreEqual("checked", jq.Attr("checked"), "Boolean attribute is true"); Assert.AreEqual(true, jq.Prop("checked"), "Boolean attribute is true"); Assert.AreEqual(null, jq.Attr("selected"), "Boolean attribute is true"); // TODO - actually jquery would return "undefined" b/c selected doesn't apply to input. Need to do this mapping somewhere. Assert.AreEqual(false, jq.Prop("selected"), "Boolean attribute is true"); Assert.AreEqual(null, jq.Attr("missing"), "Missing attribute is null"); }
public void Closest() { Assert.AreEqual(jQuery("body").Closest("body").Get(), q("body"), "closest(body)"); Assert.AreEqual(jQuery("body").Closest("html").Get(), q("html"), "closest(html)"); Assert.AreEqual(jQuery("body").Closest("div").Length, 0, "closest(div)"); Assert.AreEqual(jQuery("#qunit-fixture").Closest("span,#html").Get(), q("html"), "closest(span,#html)"); Assert.AreEqual(jQuery("div:eq(1)").Closest("div:first").Length, 0, "closest(div:first)"); Assert.AreEqual(jQuery("div").Closest("body:first div:last").Get(), q("fx-tests"), "closest(body:first div:last)"); // Test .Closest() limited by the context var jq = jQuery("#nothiddendivchild"); var body = jQuery("body")[0]; //Assert.AreEqual(jq.Closest("html", body).Get(), [], "Context limited." ); //Assert.AreEqual(jq.Closest("body", body).Get(), [], "Context limited." ); //Assert.AreEqual(jq.Closest("#nothiddendiv", document.body).Get(), q("nothiddendiv"), "Context not reached." ); //Test that .Closest() returns unique'd set Assert.AreEqual(jQuery("#qunit-fixture p").Closest("#qunit-fixture").Length, 1, "Closest should return a unique set"); // Test on disconnected node Assert.AreEqual(jQuery("<div><p></p></div>").Find("p").Closest("table").Length, 0, "Make sure disconnected closest work."); // Bug #7369 Assert.AreEqual(CQ.CreateFragment("<div foo='bar'></div>").Closest("[foo]").Length, 1, "Disconnected nodes with attribute selector"); Assert.AreEqual(CQ.CreateFragment("<div>text</div>").Closest("[lang]").Length, 0, "Disconnected nodes with text and non-existent attribute selector"); }
public void Test2() { CQ fragment = CQ.CreateFragment("<p>some text</p>"); CQ html = CQ.CreateFromFile(@"index.html"); CQ modified_html = html.Select("#test").Append(fragment); modified_html.Save(@"index_modified.html"); }
public void RoundTrip() { var dom = CQ.CreateFragment("<div>™ Û‡⇘⇙</div>"); var output = dom.Render(OutputFormatters.HtmlEncodingFull); Assert.AreEqual("<div>™ Û‡⇘⇙</div>", output); }
public void FullHtmlEncoding() { var dom = CQ.CreateFragment("<div>" + spanish + "</div>"); Assert.AreEqual(spanish, dom.Text()); var output = dom.Render(OutputFormatters.HtmlEncodingFull); Assert.AreEqual("<div>Romney dice que Chávez expande la tiranía</div>", output); }
public void TableCell() { var dom = CQ.CreateFragment(@"<td>test</td>"); Assert.AreEqual("<td>test</td>", dom.Render()); dom = CQ.CreateFragment(@"<td>test</td>", "td"); Assert.AreEqual("test", dom.Render()); }
public void Issue56_withDataAttr() { var dom = CQ.CreateFragment(@"<div data-test=""display:block; width:10px;"">"); var div = dom["div[data-test='display:block;\\a width:10px;']"]; Assert.AreEqual(1, div.Length); }
public void Utf8Handling() { var dom = CQ.CreateFragment("<div>" + spanish + "</div>"); // the "render" method should turn UTF8 characters to HTML. Accessing the node value directly should not. Assert.AreEqual(spanish, dom["div"][0].ChildNodes[0].NodeValue); Assert.AreEqual(spanish, dom.Text()); Assert.AreEqual("<div>Romney dice que Chávez expande la tiranía</div>", dom.Render()); }
public void Eq() { var res = CQ.CreateFragment(@"<div class='header'> Billing Address </div>"); var k = res.Find("> label:visible:eq(0)"); Assert.AreEqual(0, k.Length); }
private CQ TestFragment() { return(CQ.CreateFragment(@"<div> <span> <input type=""text""> <div id=""el-id""></div> <div class=""el-class""></div> content </span> </div>")); }
public async Task TestXElement() { var someObject = new { SomeProperty = XElement.Parse("<div id=\"yo\">hello</div>") }; var properties = FF.PropertiesFor(someObject); var html = properties.Render(); var annotation = new FormFactory.Attributes.DisplayAttribute(); var actualCq = CQ.CreateFragment(html.ToString()); var input = actualCq.Find("#yo").Single(); Assert.AreEqual("hello", input.InnerText); }
public void HtmlCleanup() { var dom = CQ.CreateFragment(node); var expected = "<div class=\"a b c\" attr1='{\"somejson\": \"someval\"}'></div>"; Assert.AreEqual(expected, dom.Render(), "Basic cleanup - no duplicated class - missing end tag"); // TODO // test attribute rendering options // Doctype options }
public void FindEquivalentStyles() { var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>"); var nodewithoutselector = tableDomObject.FirstElement(); var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz); Assert.AreEqual(1, result.Count); }
public void Width() { var dom = CQ.CreateFragment("<div style='width: 120px'>"); Assert.AreEqual(120, dom.Css <int>("width")); dom.Width(150); Assert.AreEqual(150, dom.Css <int>("width")); Assert.AreEqual("150px", dom.Css("width")); dom.Width("150in"); Assert.AreEqual("150in", dom.Css("width")); }
public void Issue61_Closest() { var html = "<div id=outer><div id=div1><span></span></div><div id=div2><span></span></div></div>"; var doc = CQ.CreateFragment(html); var spans = doc["span"]; Assert.AreEqual(2, spans.Length); var closestDivs = spans.Closest("div"); Assert.AreEqual(2, closestDivs.Length); CollectionAssert.AreEqual(Arrays.String("div1", "div2"), closestDivs.Select(item => item.Id)); }
public void Table() { var dom = CQ.CreateFragment(@"<tr><td>test</td></tr>"); Assert.AreEqual("<tr><td>test</td></tr>", dom.Render()); dom = CQ.CreateFragment(@"<tr><td>test</td></tr>", "body"); Assert.AreEqual("test", dom.Render()); dom = CQ.CreateFragment("<tr><td>test</td></tr>", "tr"); Assert.AreEqual("<td>test</td>", dom.Render()); }
public void ComplicatedComments() { string html = @"<!-- Where would document.write() insert? Consider: data:text/xml,<script xmlns=""http://www.w3.org/1999/xhtml""><![CDATA[ document.write('<foo>Test</foo>'); ]]></script> -->"; html = "<header><div>" + html + "</div></header>"; var dom = CQ.CreateFragment(html); Assert.AreEqual(1, dom["div"].Contents().Where(item => item.NodeType == NodeType.COMMENT_NODE).Count()); Assert.AreEqual(2, dom["*"].Length); }
public void Issue56_withStyle() { var dom = CQ.CreateFragment(@"<div style=""display:block; width:10px;"">"); var div = dom["div[style='display:block;\\a width:10px;']"]; Assert.AreEqual(1, div.Length); div.Css("width", "20px"); div = dom["div[style='display: block; width: 20px;']"]; Assert.AreEqual(1, div.Length); }
public void NewLinesInTags() { string test = @"<table border =0 cellspacing= ""2"" cellpadding=""2"" width=""100%""><span" + (char)10 + "id=test></span></table>"; var dom = CQ.CreateFragment(test); var output = dom.Render(); Assert.AreEqual( @"<table border=""0"" cellspacing=""2"" cellpadding=""2"" width=""100%""><span id=""test""></span></table>", output); }