Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim trailing slash when comparing landing page KPI #26

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EPiServer.Marketing.Testing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{00563401
README.md = README.md
setup.cmd = setup.cmd
Build\test.props = Build\test.props
src\EPiServer.Marketing.KPI\version.props = src\EPiServer.Marketing.KPI\version.props
build\version.props = build\version.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{4DCCE100-6879-491C-BCC9-85A6DA6B0EE7}"
Expand Down
23 changes: 10 additions & 13 deletions src/EPiServer.Marketing.KPI/Common/ContentComparatorKPI.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using EPiServer.Core;
using EPiServer.Framework.Localization;
using EPiServer.Marketing.KPI.Common.Attributes;
using EPiServer.Marketing.KPI.Common.Helpers;
using EPiServer.Marketing.KPI.Exceptions;
using EPiServer.Marketing.KPI.Manager.DataClass;
using EPiServer.Marketing.KPI.Results;
using EPiServer.ServiceLocation;
using EPiServer.Web.Routing;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.Mvc.Routing;
using EPiServer.Framework.Localization;
using EPiServer.Marketing.KPI.Exceptions;
using EPiServer.Web.Mvc.Html;
using EPiServer.Marketing.KPI.Results;
using EPiServer.Web.Routing;
using System.Web;
using System.Runtime.Caching;
using EPiServer.Marketing.KPI.Common.Helpers;
using System.Linq;
using EPiServer.Web.Mvc;
using System.Runtime.Caching;
using System.Runtime.Serialization;

namespace EPiServer.Marketing.KPI.Common
{
Expand Down Expand Up @@ -138,8 +134,9 @@ public override IKpiResult Evaluate(object sender, EventArgs e)
// if the target content is the start page, we also need to check
// the path to make sure its not just a request for some other static
// resources such as css or jscript
retval = (_startpagepaths.Contains(_kpiHelper.Service.GetRequestPath(), StringComparer.OrdinalIgnoreCase)
&& ContentGuid.Equals(ea.Content.ContentGuid));
retval = _startpagepaths.Any(path => path.Trim('/')
.Equals(_kpiHelper.Service.GetRequestPath().Trim('/'), StringComparison.OrdinalIgnoreCase))
&& ContentGuid.Equals(ea.Content.ContentGuid);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using EPiServer.Core;
using EPiServer.Marketing.KPI.Common;
using EPiServer.Marketing.KPI.Results;
using Moq;
using System;
using System.Collections.Generic;
using System.Threading;
using EPiServer.DataAbstraction;
using EPiServer.Framework.Localization;
using EPiServer.Marketing.KPI.Common;
using EPiServer.Marketing.KPI.Common.Helpers;
using EPiServer.Marketing.KPI.Exceptions;
using EPiServer.Marketing.KPI.Manager.DataClass;
using EPiServer.Marketing.KPI.Test.Fakes;
using EPiServer.ServiceLocation;
using EPiServer.Web.Routing;
using Xunit;
using EPiServer.Marketing.KPI.Common.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using System;
using System.Collections.Generic;
using System.Threading;
using Xunit;

namespace EPiServer.Marketing.KPI.Test.Common
{
Expand Down Expand Up @@ -256,6 +255,23 @@ public void Kpi_Converts_IfContentPathEqualsRequestedPath_IgnoringRequestedConte
Assert.True(retVal.HasConverted);
}

[Fact]
public void Kpi_Converts_IfRequestedPathEqualsStartPagePath_IgnoringUrlTrailingSlash_AndGuidsAreEqual()
{
var content3 = new Mock<IContent>();
content3.SetupGet(get => get.ContentLink).Returns(ContentReference.StartPage);
content3.SetupGet(get => get.ContentGuid).Returns(LandingPageGuid);
var arg = new ContentEventArgs(new ContentReference()) { Content = content3.Object };

var kpi = GetUnitUnderTest();
_contentRepo.Setup(c => c.Get<IContent>(It.Is<Guid>(g => g == LandingPageGuid))).Returns(content3.Object);
_kpiHelper.Setup(call => call.GetUrl(It.Is<ContentReference>(c => c == ContentReference.StartPage))).Returns("/en/");
_kpiHelper.Setup(call => call.GetRequestPath()).Returns("/en");

var retVal = kpi.Evaluate(new object(), arg);
Assert.True(retVal.HasConverted);
}

[Fact]
public void Kpi_DoesNotConvert_IfContentPathEqualsRequestedPath_AndGuidsAreNotEqual()
{
Expand Down