public void DoNotPolluteCache() { SettingsForTests.UseDirectoryUrls = true; SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains SettingsForTests.UseDomainPrefixes = false; InitializeLanguagesAndDomains(); SetDomains1(); RoutingContext routingContext; string url = "http://domain1.com/1001-1/1001-1-1"; // get the nice url for 100111 routingContext = GetRoutingContext(url); Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // check that the proper route has been cached var cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes(); Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]); // route a rogue url url = "http://domain1.com/1001-1/1001-1-1"; var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url var docreq = new PublishedContentRequest(uri, routingContext); var builder = new PublishedContentRequestBuilder(docreq); builder.LookupDomain(); Assert.IsTrue(docreq.HasDomain); // check that it's been routed var lookup = new LookupByNiceUrl(); var result = lookup.TrySetDocument(docreq); Assert.IsTrue(result); Assert.AreEqual(100111, docreq.DocumentId); // has the cache been polluted? cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes(); Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]); // no //Assert.AreEqual("1001/1001-1/1001-1-1", cachedRoutes[100111]); // yes // what's the nice url now? Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111)); // good //Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad }
public void Lookup_SingleDomain(string url, int expectedId) { SetDomains3(); ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true"); var routingContext = GetRoutingContext(url); var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url var docreq = new PublishedContentRequest(uri, routingContext); // must lookup domain else lookup by url fails var builder = new PublishedContentRequestBuilder(docreq); builder.LookupDomain(); var lookup = new LookupByNiceUrl(); var result = lookup.TrySetDocument(docreq); Assert.IsTrue(result); Assert.AreEqual(expectedId, docreq.DocumentId); }
public void Render(StringWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } // instanciate a request a process // important to use CleanedUmbracoUrl - lowercase path-only version of the current url, though this isn't going to matter // terribly much for this implementation since we are just creating a doc content request to modify it's properties manually. var contentRequest = new PublishedContentRequest(_umbracoContext.CleanedUmbracoUrl, _umbracoContext.RoutingContext); var doc = contentRequest.RoutingContext.PublishedContentStore.GetDocumentById( contentRequest.RoutingContext.UmbracoContext, PageId); if (doc == null) { writer.Write("<!-- Could not render template for Id {0}, the document was not found -->", PageId); return; } //in some cases the UmbracoContext will not have a PublishedContentRequest assigned to it if we are not in the //execution of a front-end rendered page. In this case set the culture to the default. //set the culture to the same as is currently rendering if (_umbracoContext.PublishedContentRequest == null) { var defaultLanguage = Language.GetAllAsList().FirstOrDefault(); contentRequest.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.CultureAlias); } else { contentRequest.Culture = _umbracoContext.PublishedContentRequest.Culture; } //set the doc that was found by id contentRequest.PublishedContent = doc; //set the template, either based on the AltTemplate found or the standard template of the doc contentRequest.Template = !AltTemplate.HasValue ? global::umbraco.cms.businesslogic.template.Template.GetTemplate(doc.TemplateId) : global::umbraco.cms.businesslogic.template.Template.GetTemplate(AltTemplate.Value); //if there is not template then exit if (!contentRequest.HasTemplate) { if (!AltTemplate.HasValue) { writer.Write("<!-- Could not render template for Id {0}, the document's template was not found with id {0}-->", doc.TemplateId); } else { writer.Write("<!-- Could not render template for Id {0}, the altTemplate was not found with id {0}-->", AltTemplate); } return; } //ok, we have a document and a template assigned, now to do some rendering. var builder = new PublishedContentRequestBuilder(contentRequest); //determine the rendering engine builder.DetermineRenderingEngine(); //First, save all of the items locally that we know are used in the chain of execution, we'll need to restore these //after this page has rendered. SaveExistingItems(); //set the new items on context objects for this templates execution SetNewItemsOnContextObjects(contentRequest); //Render the template ExecuteTemplateRendering(writer, contentRequest); //restore items on context objects to continuing rendering the parent template RestoreItems(); }