public void Setup() { var loader = new AttributeConfigurationLoader( new string[] { "Glass.Sitecore.Mapper.Tests.HtmlFixtureNS, Glass.Sitecore.Mapper.Tests" } ); _context = new Context(loader, new AbstractSitecoreDataHandler[] { }); _db = global::Sitecore.Configuration.Factory.GetDatabase("master"); _sitecore = new SitecoreService(_db); _itemId = new Guid("{5864308D-A91A-4E74-B8CA-7F27372CBB73}"); _item = _db.GetItem(new ID(_itemId)); _html = new GlassHtml(_sitecore); _sltTextOriginal = _item["SingleLineText"]; _mltTextOriginal = _item["MultiLineText"]; _intOriginal = _item["Integer"]; _numberOriginal = _item["Number"]; using (new SecurityDisabler()) { _item.Editing.BeginEdit(); _item["SingleLineText"] = _sltContent; _item["MultiLineText"] = _mltContent; _item["Integer"] = _intContent; _item["Number"] = _numberContent; _item.Editing.EndEdit(); } }
public void FieldWithSpacesReturningNullIssue() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign string path = "/sitecore/content/Tests/Misc/FieldWithSpace"; string expected = "Hello space"; string imageValue = "<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />"; var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field With Space"] = expected; item["Image Field"] = imageValue; } var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); //Act var instance = scContext.GetItem<FieldWithSpaceIssue>(path); //Assert Assert.AreEqual(expected, instance.FieldWithSpace); Assert.IsNotNull(instance.ImageSpace); }
public void InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName() { /* * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper * project. When two interfaces have similar names are created as proxies * the method GetTypeConfiguration returns the wrong config. */ //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); var instance = scContext.GetItem<IBasePage>("/sitecore"); //Act glassHtml.Editable(instance, x => x.Title); //This method should execute without error }
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); }
public void RenderImage_AlternativeQuotationMarks_RendersCorrectHtml() { //Arrange var expected = "<img src=\"~/media/Images/Carousel/carousel-example.ashx?h=126&w=240\" alt=\"someAlt\" width=\"380\" />"; var scContext = Substitute.For<ISitecoreContext>(); scContext.Config = new Config(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var parameters = new { Width = 380, W = 240 }; var model = new { Image = image }; GlassHtml.QuotationMark = "\""; //Act var result = html.RenderImage(model, x => x.Image, parameters, true, true); //Assert Assert.AreEqual(expected, result); //reset GlassHtml GlassHtml.QuotationMark = "'"; }
public void RenderImage_MatchesSitecoreOutput_Issue133() { //Assign string targetPath = "/sitecore/content/Tests/GlassHtml/RenderImage/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= "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />"; var item = db.GetItem(targetPath); var field = item.Fields["Image"]; using (new ItemEditing(item, true)) { field.Value = fieldValue; } var model = service.GetItem<StubClassWithImage>(targetPath); var scControl = new Sitecore.Web.UI.WebControls.Image(); scControl.Item = item; scControl.Field = "Image"; scControl.Parameters = "mw=200"; 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(); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb)); //Act scControl.RenderControl(writer); var scResult = sb.ToString(); var result = html.RenderImage(model, x => x.Image, new {mw=200}); //Assert Assert.AreEqual(result,scResult); }
public override object ConvertTo(Type type, CultureInfo culture) { if (String.IsNullOrEmpty(_parameters)) return null; var glassHtml = new GlassHtml(SitecoreContext.GetFromHttpContext()); var genericMethod = method.MakeGenericMethod(type); return genericMethod.Invoke(glassHtml, new object[]{_parameters}) ?? base.ConvertTo(type, culture); }
public void Editable_InEditMode_StringFieldWithEditReturned() { //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); var model = service.GetItem<StubClass>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue ; using (new SecurityDisabler()) { service.Save(model); } 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.Edit); Sitecore.Context.Site = siteContext; //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); Console.WriteLine("result "+result); }
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); }
public void RenderImage_ValidImageWithParametersWidth_RendersCorrectHtmlNoWidthHeight() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=126&w=240' alt='someAlt' />"; var scContext = Substitute.For<ISitecoreContext>(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var parameters = new { Width = 380, W = 240 }; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true, false); //Assert Assert.AreEqual(expected, result); }
public void RenderImage_RendersImageWithAttributes() { GlassHtml html = new GlassHtml("master"); //Assign FieldTypes.Image img = new FieldTypes.Image(); img.Alt = "Some alt test"; img.Src = "/cats.jpg"; img.Class = "classy"; NameValueCollection attrs = new NameValueCollection(); attrs.Add("style", "allStyle"); //Act var result = html.RenderImage(img, attrs); //Assert Assert.AreEqual("<img src='/cats.jpg' style='allStyle' class='classy' alt='Some alt test' />", result); }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual IEncodedString RenderImage(Expression <Func <TModel, object> > field, ImageParameters parameters = null, bool isEditable = false) { return(GlassHtml.RenderImage(Model, field, parameters, isEditable)); }
public IEncodedString RenderImage(Image image) { return(GlassHtml.RenderImage(image)); }
/// <summary> /// Converts rendering parameters to a concrete type. Use this method if you have defined the template ID on the /// model configuration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameters"></param> /// <returns></returns> public virtual T RenderingParameters <T>(NameValueCollection parameters) where T : class { return(GlassHtml.GetRenderingParameters <T>(parameters)); }
/// <summary> /// Editables the specified field. /// </summary> /// <param name="field">The field.</param> /// <param name="parameters">Parameters to control field rendering</param> /// <returns>RawString.</returns> /// <exception cref="System.NullReferenceException"> /// No field set /// or /// No model set /// </exception> public IEncodedString Editable(Expression <Func <TModel, object> > field, object parameters = null) { return(GlassHtml.Editable(Model, field, parameters)); }
/// <summary> /// Initializes a new instance of the <see cref="GlassHtmlFacade"/> class. /// </summary> /// <param name="service">The service.</param> public GlassHtmlFacade(ISitecoreService service) { _glassHtml = new GlassHtml(service); }
/// <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)); }
/// <summary> /// Makes the field editable using the Sitecore Page Editor. Using the specifed service to write data. /// </summary> /// <param name="field">The field that should be made editable</param> /// <param name="standardOutput">The output to display when the Sitecore Page Editor is not being used</param> /// <returns>HTML output to either render the editable controls or normal HTML</returns> public HtmlString Editable(Expression <Func <TModel, object> > field, Expression <Func <TModel, string> > standardOutput, AbstractParameters parameters) { return(new HtmlString(GlassHtml.Editable(Model, field, standardOutput, parameters))); }
public void RenderImage_ValidImageWithLanguageParameterOverride_RendersCorrectHtmlWithParameterLanguage() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=210&la=en&w=400' width='200' vspace='15' height='105' hspace='10' border='9' alt='someAlt' />"; var scContext = Substitute.For<ISitecoreContext>(); scContext.Config = new Config(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.HSpace = 10; image.VSpace = 15; image.Border = "9"; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; image.Language = LanguageManager.GetLanguage("af-ZA"); var model = new { Image = image }; var parameters = new { w = 400, la="en" }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true, true); //Assert Assert.AreEqual(expected, result); }
/// <summary> /// Makes the field editable using the Sitecore Page Editor. Using the specifed service to write data. /// </summary> /// <param name="field">The field that should be made editable</param> /// <param name="parameters"> </param> /// <returns>HTML output to either render the editable controls or normal HTML</returns> public HtmlString Editable(Expression <Func <TModel, object> > field, string parameters) { return(new HtmlString(GlassHtml.Editable(Model, field, parameters))); }
/// <summary> /// Makes the field editable using the Sitecore Page Editor. Using the specifed service to write data. /// </summary> /// <param name="field">The field that should be made editable</param> /// <param name="standardOutput">The output to display when the Sitecore Page Editor is not being used</param> /// <returns>HTML output to either render the editable controls or normal HTML</returns> public HtmlString Editable(Expression <Func <TModel, object> > field, Expression <Func <TModel, string> > standardOutput) { return(new HtmlString(GlassHtml.Editable(Model, field, standardOutput))); }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <typeparam name="T">The model type</typeparam> /// <param name="model">The model that contains the image field</param> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual HtmlString RenderImage <T>(T target, Expression <Func <T, object> > field, ImageParameters parameters = null, bool isEditable = false) { return(new HtmlString(GlassHtml.RenderImage <T>(target, field, parameters, isEditable))); }
/// <summary> /// Makes the field editable using the Sitecore Page Editor. Using the specifed service to write data. /// </summary> /// <typeparam name="T">A class loaded by Glass.Sitecore.Mapper</typeparam> /// <param name="target">The target object that contains the item to be edited</param> /// <param name="field">The field that should be made editable</param> /// <param name="standardOutput">The output to display when the Sitecore Page Editor is not being used</param> /// <returns>HTML output to either render the editable controls or normal HTML</returns> public HtmlString Editable <T>(T target, Expression <Func <T, object> > field, Expression <Func <T, string> > standardOutput, AbstractParameters parameters) { return(new HtmlString(GlassHtml.Editable(target, field, standardOutput, parameters))); }
public virtual K GetRenderingParameters <K>() where K : class { return(GlassHtml.GetRenderingParameters <K>(RenderingParameters)); }
public void RenderLink_ContainsSpecialCharacters() { //Arrange var expected = "<a href='http://na2.se.voxco.com/se/?st=6M9NIk9SWq9dkYTuJI2wewuV3b3bWrDQMwgCt2aBnWDGTaoxLYNESg%3D%3D' title='hello & world' >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://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"); }
/// <summary> /// Render HTML for a link with contents /// </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> /// <returns></returns> public virtual RenderingResult BeginRenderLink(Expression <Func <TModel, object> > field, NameValueCollection attributes = null, bool isEditable = false) { return(GlassHtml.BeginRenderLink(this.Model, field, this.Output, attributes, isEditable)); }
public void RenderImage_MaxWidthWhereWidthIsBelowMaxWidth_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?mw=300&h=105&as=True&w=200' alt='someAlt' />"; var scContext = Substitute.For<ISitecoreContext>(); scContext.Config = new Config(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var parameters = new { mw = 300, As = true }; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true, false); //Assert Assert.AreEqual(expected, result); }
/// <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 HtmlString RenderLink(Expression <Func <TModel, object> > field, NameValueCollection attributes = null, bool isEditable = false, string contents = null) { return(new HtmlString(GlassHtml.RenderLink(this.Model, field, attributes, isEditable, contents))); }
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); }
/// <summary> /// Inits the helpers. /// </summary> public override void InitHelpers() { base.InitHelpers(); GlassHtml = new GlassHtml(new SitecoreContext()); }
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 & world' >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.Title = "hello & world"; var model = new { Link = link }; //Act var result = html.RenderLink(model, x => x.Link); //Assert AssertHtml.AreHtmlElementsEqual(expected, result, "a"); }
/// <summary> /// Makes the field editable using the Sitecore Page Editor. Using the specifed service to write data. /// </summary> /// <typeparam name="T">A class loaded by Glass.Sitecore.Mapper</typeparam> /// <param name="target">The target object that contains the item to be edited</param> /// <param name="field">The field that should be made editable</param> /// <param name="parameters"> </param> /// <returns>HTML output to either render the editable controls or normal HTML</returns> public HtmlString Editable <T>(T target, Expression <Func <T, object> > field, string parameters) { return(new HtmlString(GlassHtml.Editable(target, field, parameters))); }
/// <summary> /// Converts rendering parameters to a concrete type. Use this method if you have defined the template ID on the /// model configuration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameters"></param> /// <returns></returns> public virtual T RenderingParameters <T>(string parameters) where T : class { return(GlassHtml.GetRenderingParameters <T>(parameters)); }
public void FieldWithSpacesAutoMap() { //Assign var templateId = ID.NewID; var targetId = ID.NewID; var fieldName1 = "Field With Space"; var fieldName2 = "Field With Space 1"; var fieldName3 = "Image Space"; using (Db database = new Db { new DbTemplate(templateId) { { fieldName1, "" }, { fieldName2, "" }, { fieldName3, "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { string path = "/sitecore/content/Target"; string expected = "Hello space"; string expectedSpace1 = "Hello space"; string imageValue = "<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />"; var resolver = Utilities.CreateStandardResolver(); resolver.DataMapperResolverFactory.Add(() => new AbstractDataMapperFieldsWithSpace()); var context = Context.Create(resolver); context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(FieldWithSpaceAutoMap))); ; var db = Factory.GetDatabase("master"); var item = db.GetItem(path); using (new ItemEditing(item, true)) { item["Field With Space"] = expected; item["Field With Space 1"] = expectedSpace1; item["Image Space"] = imageValue; } var scContext = new SitecoreContext(db); var glassHtml = new GlassHtml(scContext); //Act var instance = scContext.GetItem <FieldWithSpaceAutoMap>(path); //Assert Assert.AreEqual(expected, instance.FieldWithSpace); Assert.IsNotNull(instance.ImageSpace); SitecoreFieldConfiguration imageFieldTypeConfig = scContext.GlassContext.TypeConfigurations[typeof(FieldWithSpaceAutoMap)].Properties.First( x => x.PropertyInfo.Name == "ImageSpace") as SitecoreFieldConfiguration; Assert.AreEqual("Image Space", imageFieldTypeConfig.FieldName); SitecoreFieldConfiguration stringFieldTypeConfig = scContext.GlassContext.TypeConfigurations[typeof(FieldWithSpaceAutoMap)].Properties.First( x => x.PropertyInfo.Name == "FieldWithSpace") as SitecoreFieldConfiguration; Assert.AreEqual("Field With Space", stringFieldTypeConfig.FieldName); SitecoreFieldConfiguration stringNumberFieldTypeConfig = scContext.GlassContext.TypeConfigurations[typeof(FieldWithSpaceAutoMap)].Properties.First( x => x.PropertyInfo.Name == "FieldWithSpace1") as SitecoreFieldConfiguration; Assert.AreEqual("Field With Space 1", stringNumberFieldTypeConfig.FieldName); } }
/// <summary> /// Editables the specified target. /// </summary> /// <typeparam name="T">The type of the t1.</typeparam> /// <param name="target">The target.</param> /// <param name="field">The field.</param> /// <param name="standardOutput">The standard output.</param> /// <param name="parameters">Parameters to control field rendering</param> /// <returns> /// IEncodedString. /// </returns> public IEncodedString Editable <T>(T target, Expression <Func <T, object> > field, Expression <Func <T, string> > standardOutput, object parameters = null) { return(GlassHtml.Editable(target, field, standardOutput, parameters)); }
public void Editable_SimpleLambdaInEditModeInterfaceWithInheritance_StringFieldWithEditReturned() { //Assign string targetPath = "/sitecore/content/target"; var templateId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { new DbField("StringField") { Type = "text" } }, new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId) { {"StringField", ""} } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreContext(database.Database); var html = new GlassHtml(service); var model = service.GetItem<IStubClassInherits>(targetPath); var fieldValue = "test content field"; model.StringField = fieldValue; using (new SecurityDisabler()) { service.Save(model); } 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 ) ); using (new EnableWebEditMode()) { using (new SiteContextSwitcher(siteContext)) { //Act string result; using (new SecurityDisabler()) { result = html.Editable(model, x => x.SubStub.StringField); } //Assert Assert.IsTrue(result.Contains(fieldValue)); //this is the webedit class Assert.IsTrue(result.Contains("scWebEditInput")); Console.WriteLine("result " + result); } } } }
/// <summary> /// Editables the specified field. /// </summary> /// <param name="field">The field.</param> /// <param name="standardOutput">The standard output.</param> /// <param name="parameters">Parameters to control field rendering</param> /// <returns> /// RawString. /// </returns> /// <exception cref="System.NullReferenceException">No field set /// or /// No model set</exception> public RawString Editable(Expression <Func <TModel, object> > field, Expression <Func <TModel, string> > standardOutput, object parameters = null) { return(GlassHtml.Editable(Model, field, standardOutput, parameters)); }
public void RenderLink_LinkHasQuestionMarkAndAnchorAtEnd() { //Arrange var expected = "<a href='http://www.seek.com.au/jobs/in-australia/?dateRange=test&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); }
/// <summary> /// Converts rendering parameters to a concrete type. Use this method if you have defined the template ID on the /// model configuration. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public virtual T GetRenderingParameters <T>() where T : class { return(GlassHtml.RenderingParameters <T>(ParentControl.Parameters)); }
/// <summary> /// Render HTML for a link with contents /// </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> /// <returns></returns> public virtual RenderingResult BeginRenderLink <T>(T model, Expression <Func <T, object> > field, object attributes = null, bool isEditable = false) { return(GlassHtml.BeginRenderLink(model, field, this.Output, attributes, isEditable)); }
public IEncodedString RenderImage(Image image, NameValueCollection attributes) { return(GlassHtml.RenderImage(image, attributes)); }
public void RenderLink_WithMultiParametersRepeated_ReturnsAllParamters() { //Arrange var expected = "<a href='/somewhere.aspx?temp=fred&temp=fred2&temp=fred3&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"); }
public void RenderImage_ValidImageWithParametersHeight_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=450&w=600' alt='someAlt' height='450' />"; var scContext = Substitute.For<ISitecoreContext>(); var html = new GlassHtml(scContext); scContext.Config = new Config(); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 150; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var parameters = new { Height = 450, H=450}; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true, true); //Assert Assert.AreEqual(expected, result); }
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); }
public void RenderImage_ValidImageWithClass_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=105&w=200' alt='someAlt' height='105' class='AClass' width='200' />"; var scContext = Substitute.For<ISitecoreContext>(); scContext.Config = new Config(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.Class = "AClass"; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, null, true, true); //Assert Assert.AreEqual(expected, result); }
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); }
public void RenderImage_RemoveHeightWidthAttributes_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=210&w=400' vspace='15' hspace='10' border='9' alt='someAlt' />"; var scContext = Substitute.For<ISitecoreContext>(); scContext.Config = new Config(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.HSpace = 10; image.VSpace = 15; image.Border = "9"; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var model = new { Image = image }; var parameters = new { w = 400 }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true, false); //Assert Assert.AreEqual(expected, result); }
public void RenderLink_HtmlEncodesTitle() { //Arrange var expected = "<a href='/somewhere.aspx' title='hello & world' >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.Title = "hello & world"; var model = new { Link = link }; //Act var result = html.RenderLink(model, x => x.Link); //Assert AssertHtml.AreHtmlElementsEqual(expected, result, "a"); }
public virtual T GetRenderingParameters <T>() where T : class { return(GlassHtml.GetRenderingParameters <T>(RenderingParameters)); }
/// <summary> /// Render HTML for a link with contents /// </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> /// <returns></returns> public virtual RenderingResult BeginRenderLink <T>(T model, Expression <Func <T, object> > field, object attributes = null, bool isEditable = false) { return(GlassHtml.BeginRenderLink(model, field, System.Web.HttpContext.Current.Response.Output, attributes, isEditable)); }
/// <summary> /// Makes a field editable via the Page Editor. Use the Model property as the target item, e.g. model => model.Title where Title is field name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model">The model.</param> /// <param name="field">The field.</param> /// <param name="standardOutput">The standard output.</param> /// <param name="parameters">The parameters.</param> /// <returns>System.String.</returns> public string Editable <T>(T model, Expression <Func <T, object> > field, Expression <Func <T, string> > standardOutput, object parameters = null) { return(GlassHtml.Editable(model, field, standardOutput, parameters)); }
public virtual T GetRenderingParameters <T>(NameValueCollection parameters, ID renderParametersTemplateId) where T : class { return(GlassHtml.GetRenderingParameters <T>(parameters, renderParametersTemplateId)); }
public void RenderingParameters_StringPassedInWithParametersUsingIdOnType_ReturnsModelWithValues() { //Arrange var expectedNumber = 234; var expectedId1 = new Guid("{032B690F-5113-44C4-AEC7-A16B44382D4C}"); var expectedId2 = new Guid("{6CF01319-0234-42C8-AEC1-FE757169F7A0}"); var expectedFieldValue = "hello world"; var parameters = "StringField={0}&Number={1}&Items={2}" .Formatted( WebUtil.UrlEncode(expectedFieldValue), WebUtil.UrlEncode(expectedNumber.ToString()), WebUtil.UrlEncode("{0}|{1}".Formatted(expectedId1, expectedId2))); 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); //Act var result = html.GetRenderingParameters<RenderingTestWithAttribute>(parameters); //Assert Assert.AreEqual(expectedNumber, result.Number); Assert.AreEqual(expectedFieldValue, result.StringField); Assert.IsTrue(result.Items.Any(x => x.Id == expectedId1)); Assert.IsTrue(result.Items.Any(x => x.Id == expectedId2)); Assert.AreEqual(2, result.Items.Count()); }
protected virtual T GetRenderingParameters <T>() where T : class { string renderingParameters = MvcContext.RenderingParameters; return(renderingParameters.HasValue() ? GlassHtml.GetRenderingParameters <T>(renderingParameters) : null); }
public void RenderImage_ValidImageWithBorderHSpaceVSpace_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx' alt='someAlt' border='9' hspace='10' vspace='15' />"; var scContext = Substitute.For<ISitecoreContext>(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.HSpace = 10; image.VSpace = 15; image.Border = "9"; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, null, true); //Assert Assert.AreEqual(expected, result); }
/// <summary> /// Editables the specified target. /// </summary> /// <typeparam name="T1">The type of the t1.</typeparam> /// <param name="target">The target.</param> /// <param name="field">The field.</param> /// <param name="parameters">The parameters.</param> /// <returns>IEncodedString.</returns> public IEncodedString Editable <T1>(T1 target, Expression <Func <T1, object> > field, string parameters) { return(GlassHtml.Editable(target, field, parameters)); }
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); }
/// <summary> /// Editables the specified target. /// </summary> /// <typeparam name="T1">The type of the t1.</typeparam> /// <param name="target">The target.</param> /// <param name="field">The field.</param> /// <param name="standardOutput">The standard output.</param> /// <returns>IEncodedString.</returns> public IEncodedString Editable <T1>(T1 target, Expression <Func <T1, object> > field, Expression <Func <T1, string> > standardOutput) { return(GlassHtml.Editable(target, field, standardOutput)); }
public void RenderImage_ValidImageWithWidthAndStretcj_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?w=900&as=True' alt='someAlt' width='900' />"; var scContext = Substitute.For<ISitecoreContext>(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var parameters = new ImageParameters { Width = 900, AllowStretch = true}; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true); //Assert Assert.AreEqual(expected, result); }
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"); }