Exemplo n.º 1
0
        public void RenderLink_LinkWithMixedPropertiesAndParameters()
        {
            //Arrange
            var expected  = "<a href='/somewhere.aspx?temp=fred#anOther' target='_blank' class='myclass' title='mytitle' >hello world</a>";
            var scContext = Substitute.For <ISitecoreContext>();
            var html      = new GlassHtml(scContext);
            var link      = new Fields.Link();

            link.Text   = "hello world";
            link.Url    = "/somewhere.aspx";
            link.Anchor = "aAnchor";
            link.Class  = "myclass";
            link.Query  = "temp=fred";
            link.Target = "_blank";
            link.Title  = "mytitle";

            var model      = new { Link = link };
            var parameters = new NameValueCollection {
                { "anchor", "anOther" }
            };

            //Act
            var result = html.RenderLink(model, x => x.Link, parameters);

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void RenderLink_RendersAValidaLink()
        {

            //Assign
            GlassHtml html = new GlassHtml("master");

            FieldTypes.Link link = new FieldTypes.Link();
            link.Class = "classy";
            link.Anchor = "landSighted";
            link.Target = "xMarksTheSpot";
            link.Text = "Click here";
            link.Title = "You should click here";
            link.Url = "/yourpage";

            NameValueCollection attrs = new NameValueCollection();
            attrs.Add("style", "got some");

            //Act
            var result = html.RenderLink(link, attrs);

            //Assert
            Assert.AreEqual("<a href='/yourpage#landSighted' title='You should click here' target='xMarksTheSpot' class='classy' style='got some' class='classy' target='xMarksTheSpot' title='You should click here' >Click here</a>", result);


        }
Exemplo n.º 3
0
        public void RenderLink_WithMultiParametersRepeated_ReturnsAllParamters()
        {
            //Arrange
            var expected =
                "<a href='/somewhere.aspx?temp=fred&amp;temp=fred2&amp;temp=fred3&amp;temp1=jane' class='myclass' >my other content</a>";
            var scContext = Substitute.For <ISitecoreContext>();
            var html      = new GlassHtml(scContext);
            var link      = new Fields.Link();

            link.Text  = "hello world";
            link.Url   = "/somewhere.aspx";
            link.Query = "temp=fred&temp=fred2&temp=fred3&temp1=jane";

            var model      = new { Link = link };
            var parameters = new NameValueCollection {
                { "class", "myclass" }
            };
            var content = "my other content";

            //Act
            var result = html.RenderLink(model, x => x.Link, parameters, contents: content);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 4
0
        public void RenderLink_LinkHasHashBang()
        {
            //Arrange
            var expected  = "<a href='http://www.seek.com.au/jobs/in-australia/#dateRange=999&workType=0&industry=&occupation=&graduateSearch=false&salaryFrom=0&salaryTo=999999&salaryType=annual&advertiserID=&advertiserGroup=&keywords=sitecore+developer&page=1&displaySuburb=&seoSuburb=&isAreaUnspecified=false&location=&area=&nation=3000&sortMode=KeywordRelevance&searchFrom=filters&searchType=' >hello world</a>";
            var scContext = Substitute.For <ISitecoreContext>();
            var html      = new GlassHtml(scContext);
            var link      = new Fields.Link();

            link.Text = "hello world";
            link.Url  = "http://www.seek.com.au/jobs/in-australia/#dateRange=999&workType=0&industry=&occupation=&graduateSearch=false&salaryFrom=0&salaryTo=999999&salaryType=annual&advertiserID=&advertiserGroup=&keywords=sitecore+developer&page=1&displaySuburb=&seoSuburb=&isAreaUnspecified=false&location=&area=&nation=3000&sortMode=KeywordRelevance&searchFrom=filters&searchType=";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 5
0
        public void RenderLink_LinkWithNoAttributes()
        {
            //Arrange
            var expected  = "<a href='/somewhere.aspx' >hello world</a>";
            var scContext = Substitute.For <ISitecoreContext>();
            var html      = new GlassHtml(scContext);
            var link      = new Fields.Link();

            link.Text = "hello world";
            link.Url  = "/somewhere.aspx";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 6
0
        public void RenderLink_LinkHasQuestionMarkAndAnchorAtEnd()
        {
            //Arrange
            var expected  = "<a href='http://www.seek.com.au/jobs/in-australia/?dateRange=test&amp;value1=test2#anchor' >hello world</a>";
            var scContext = Substitute.For <ISitecoreContext>();
            var html      = new GlassHtml(scContext);
            var link      = new Fields.Link();

            link.Text = "hello world";
            link.Url  = "http://www.seek.com.au/jobs/in-australia/?dateRange=test&value1=test2#anchor";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 7
0
        public void RenderLink_LinkWithClassAndQuery()
        {
            //Arrange
            var expected  = "<a href='/somewhere.aspx?temp=fred' class='myclass' >hello world</a>";
            var scContext = Substitute.For <ISitecoreContext>();
            var html      = new GlassHtml(scContext);
            var link      = new Fields.Link();

            link.Text  = "hello world";
            link.Url   = "/somewhere.aspx";
            link.Query = "temp=fred";

            var model      = new { Link = link };
            var parameters = new NameValueCollection {
                { "class", "myclass" }
            };

            //Act
            var result = html.RenderLink(model, x => x.Link, parameters);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 8
0
        public void RenderLink_RendersAValidaLink()
        {
            //Assign
            GlassHtml html = new GlassHtml("master");

            FieldTypes.Link link = new FieldTypes.Link();
            link.Class  = "classy";
            link.Anchor = "landSighted";
            link.Target = "xMarksTheSpot";
            link.Text   = "Click here";
            link.Title  = "You should click here";
            link.Url    = "/yourpage";

            NameValueCollection attrs = new NameValueCollection();

            attrs.Add("style", "got some");

            //Act
            var result = html.RenderLink(link, attrs);

            //Assert
            Assert.AreEqual("<a href='/yourpage#landSighted' title='You should click here' target='xMarksTheSpot' class='classy' style='got some' class='classy' target='xMarksTheSpot' title='You should click here' >Click here</a>", result);
        }
Exemplo n.º 9
0
        public void RenderLink_LinkWithMixedPropertiesAndParameters()
        {
            //Arrange
            var expected = "<a href='/somewhere.aspx?temp=fred#anOther' class='myclass' target='_blank' title='mytitle' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "/somewhere.aspx";
            link.Anchor = "aAnchor";
            link.Class = "myclass";
            link.Query = "temp=fred";
            link.Target = "_blank";
            link.Title = "mytitle";

            var model = new { Link = link };
            var parameters = new NameValueCollection {{"anchor", "anOther"}};

            //Act
            var result = html.RenderLink(model, x => x.Link, parameters);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 10
0
        public void RenderLink_LinkWithNoAttributes()
        {
            //Arrange
            var expected = "<a href='/somewhere.aspx' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "/somewhere.aspx";

            var model = new {Link = link};

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 11
0
        public void RenderLink_LinkContainsAnchor_Issue155()
        {
            //Assign
            string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target";

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
            var service = new SitecoreContext(db);

            var html = new GlassHtml(service);


            string fieldValue = "<link text='text' linktype='anchor' anchor='footer' title='' class='' />";
            string expected = "<a href='#footer' >text</a>";

            var item = db.GetItem(targetPath);
            var field = item.Fields["StringField"];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            var model = service.GetItem<IStubLinkClass>(targetPath);

            var doc = new XmlDocument();
            doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

            var siteContext = new SiteContextStub(
                new SiteInfo(
                    doc.FirstChild
                    )
                );

            siteContext.SetDisplayMode(DisplayMode.Normal);

            Sitecore.Context.Site = siteContext;

            StringBuilder sb = new StringBuilder();
            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 12
0
        public void RenderLink_LinkHasQuestionMarkAndAnchorAtEnd()
        {
            //Arrange
            var expected = "<a href='http://www.seek.com.au/jobs/in-australia/?dateRange=test&amp;value1=test2#anchor' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "http://www.seek.com.au/jobs/in-australia/?dateRange=test&value1=test2#anchor";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 13
0
        public void RenderLink_LinkHasHashBang()
        {
            //Arrange
            var expected = "<a href='http://www.seek.com.au/jobs/in-australia/#dateRange=999&amp;workType=0&amp;industry=&amp;occupation=&amp;graduateSearch=false&amp;salaryFrom=0&amp;salaryTo=999999&amp;salaryType=annual&amp;advertiserID=&amp;advertiserGroup=&amp;keywords=sitecore+developer&amp;page=1&amp;displaySuburb=&amp;seoSuburb=&amp;isAreaUnspecified=false&amp;location=&amp;area=&amp;nation=3000&amp;sortMode=KeywordRelevance&amp;searchFrom=filters&amp;searchType=' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "http://www.seek.com.au/jobs/in-australia/#dateRange=999&workType=0&industry=&occupation=&graduateSearch=false&salaryFrom=0&salaryTo=999999&salaryType=annual&advertiserID=&advertiserGroup=&keywords=sitecore+developer&page=1&displaySuburb=&seoSuburb=&isAreaUnspecified=false&location=&area=&nation=3000&sortMode=KeywordRelevance&searchFrom=filters&searchType=";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 14
0
        public void RenderLink_LinkWithAllSetProperties()
        {
            //Arrange
            var expected = "<a href='/somewhere.aspx?temp=fred#aAnchor' target='_blank' class='myclass' title='mytitle' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "/somewhere.aspx";
            link.Anchor = "aAnchor";
            link.Class = "myclass";
            link.Query = "temp=fred";
            link.Target = "_blank";
            link.Title = "mytitle";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert

            AssertHtml.AreHtmlElementsEqual(expected, result, "a");
        }
Exemplo n.º 15
0
        public void RenderLink_HtmlTitleAlreadyEncoded_DoesNotDoubleEncode()
        {
            //Arrange
            //This test checks that a value already encoded does not get accidentally double HTML encoded.
            var expected = "<a href='/somewhere.aspx' title='hello &amp; world' >hello &amp; world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello &amp; world";
            link.Url = "/somewhere.aspx";
            link.Title = "hello &amp; world";
            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            AssertHtml.AreHtmlElementsEqual(expected, result, "a");
        }
Exemplo n.º 16
0
        public void RenderLink_LinkHasHash()
        {
            //Arrange
            var expected = "<a href='http://www.seek.com.au/jobs/in-australia/#dateRange' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "http://www.seek.com.au/jobs/in-australia/#dateRange";

            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            AssertHtml.AreHtmlElementsEqual(expected, result, "a");
        }
Exemplo n.º 17
0
 /// <summary>
 /// Render HTML for a link
 /// </summary>
 /// <param name="field">The link field to user</param>
 /// <param name="attributes">Any additional link attributes</param>
 /// <param name="isEditable">Make the link editable</param>
 /// <param name="contents">Content to override the default decription or item name</param>
 /// <returns></returns>
 public virtual HtmlString RenderLink(Expression <Func <TK, object> > field, object attributes = null,
                                      bool isEditable = false, string contents = null)
 {
     return(new HtmlString(GlassHtml.RenderLink(Model, field, attributes, isEditable, contents)));
 }
Exemplo n.º 18
0
        public void RenderLink_HtmlEncodesTitle()
        {
            //Arrange
            var expected = "<a href='/somewhere.aspx' title='hello &amp; world' >hello &amp; world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello & world";
            link.Url = "/somewhere.aspx";
            link.Title = "hello & world";
            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            AssertHtml.AreHtmlElementsEqual(expected, result, "a");
        }
Exemplo n.º 19
0
        public void RenderLink_WithMultiParametersRepeated_ReturnsAllParamters()
        {
            //Arrange
            var expected =
                "<a href='/somewhere.aspx?temp=fred&amp;temp=fred2&amp;temp=fred3&amp;temp1=jane' class='myclass' >my other content</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "/somewhere.aspx";
            link.Query = "temp=fred&temp=fred2&temp=fred3&temp1=jane";

            var model = new { Link = link };
            var parameters = new NameValueCollection { { "class", "myclass" } };
            var content = "my other content";

            //Act
            var result = html.RenderLink(model, x => x.Link, parameters, contents: content);

            //Assert
            AssertHtml.AreHtmlElementsEqual(expected, result, "a");
        }
Exemplo n.º 20
0
        public void RenderLink_LinkWithCustomContent()
        {
            //Arrange
            var expected = "<a href='/somewhere.aspx?temp=fred' class='myclass' >my other content</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "/somewhere.aspx";
            link.Query = "temp=fred";

            var model = new { Link = link };
            var parameters = new NameValueCollection { { "class", "myclass" } };
            var content = "my other content";

            //Act
            var result = html.RenderLink(model, x => x.Link, parameters, contents: content);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Render HTML for a link
 /// </summary>
 /// <typeparam name="T">The model type</typeparam>
 /// <param name="model">The model</param>
 /// <param name="field">The link field to user</param>
 /// <param name="attributes">Any additional link attributes</param>
 /// <param name="isEditable">Make the link editable</param>
 /// <param name="contents">Content to override the default decription or item name</param>
 /// <returns></returns>
 public virtual string RenderLink(Expression <Func <T, object> > field, NameValueCollection attributes = null, bool isEditable = false, string contents = null)
 {
     return(GlassHtml.RenderLink(this.Model, field, attributes, isEditable, contents));
 }
Exemplo n.º 22
0
        public void RenderLink_ContainsSpecialCharacters()
        {
            //Arrange
            var expected = "<a href='http://na2.se.voxco.com/se/?st=6M9NIk9SWq9dkYTuJI2wewuV3b3bWrDQMwgCt2aBnWDGTaoxLYNESg%3D%3D' title='hello &amp; world' >hello &amp; world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello & world";
            link.Url = "http://na2.se.voxco.com/se/?st=6M9NIk9SWq9dkYTuJI2wewuV3b3bWrDQMwgCt2aBnWDGTaoxLYNESg%3D%3D";
            link.Title = "hello & world";
            var model = new { Link = link };

            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            AssertHtml.AreHtmlElementsEqual(expected, result, "a");
        }
Exemplo n.º 23
0
 /// <summary>
 /// Render HTML for a link
 /// </summary>
 /// <typeparam name="T">The model type</typeparam>
 /// <param name="model">The model</param>
 /// <param name="field">The link field to user</param>
 /// <param name="attributes">Any additional link attributes</param>
 /// <param name="isEditable">Make the link editable</param>
 /// <param name="contents">Content to override the default decription or item name</param>
 /// <returns></returns>
 public virtual string RenderLink <T>(T model, Expression <Func <T, object> > field, object attributes = null, bool isEditable = false, string contents = null)
 {
     return(GlassHtml.RenderLink(model, field, attributes, isEditable, contents));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Renders the link.
 /// </summary>
 /// <param name="link">The link.</param>
 /// <returns>RawString.</returns>
 public RawString RenderLink(Link link)
 {
     return(_glassHtml.RenderLink(link).RawString());
 }