-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from kentico-timothyf/PageTypeAssignedToSite
Added new Page Type Not Assigned to site report
- Loading branch information
Showing
12 changed files
with
235 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
KenticoInspector.Reports.Tests/PageTypeAssignmentAnalysisTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using KenticoInspector.Core.Constants; | ||
using KenticoInspector.Reports.PageTypeAssignmentAnalysis; | ||
using KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
|
||
namespace KenticoInspector.Reports.Tests | ||
{ | ||
[TestFixture(10)] | ||
[TestFixture(11)] | ||
[TestFixture(12)] | ||
public class PageTypeAssignmentAnalysisTests : AbstractReportTest<Report, Terms> | ||
{ | ||
private Report _mockReport; | ||
|
||
public PageTypeAssignmentAnalysisTests(int majorVersion) : base(majorVersion) | ||
{ | ||
_mockReport = new Report(_mockDatabaseService.Object, _mockReportMetadataService.Object); | ||
} | ||
|
||
[Test] | ||
public void Should_ReturnListOfUnassignedPageTypes_When_SomeAreFound() | ||
{ | ||
// Arrange | ||
var unassignedPageTypes = GetListOfUnassignedPageTypes(); | ||
ArrangeDatabaseCalls(unassignedPageTypes); | ||
|
||
// Act | ||
var results = _mockReport.GetResults(); | ||
|
||
// Assert | ||
Assert.That(results.Data.Rows.Count > 0, "Expected more than 0 page types to be returned"); | ||
Assert.That(results.Status == ReportResultsStatus.Warning,$"Expected Warning status, got {results.Status} status"); | ||
} | ||
|
||
[Test] | ||
public void Should_ReturnEmptyListOfIdenticalLayouts_When_NoneFound() | ||
{ | ||
// Arrange | ||
ArrangeDatabaseCalls(); | ||
|
||
// Act | ||
var results = _mockReport.GetResults(); | ||
// Assert | ||
Assert.That(results.Data.Rows.Count == 0, $"Expected 0 page types to be returned, got {results.Data.Rows.Count}"); | ||
Assert.That(results.Status == ReportResultsStatus.Good, $"Expected Good status, got {results.Status} status"); | ||
} | ||
|
||
private void ArrangeDatabaseCalls(IEnumerable<PageType> unassignedPageTypes = null) { | ||
unassignedPageTypes = unassignedPageTypes ?? new List<PageType>(); | ||
_mockDatabaseService | ||
.Setup(p => p.ExecuteSqlFromFile<PageType>(Scripts.GetPageTypesNotAssignedToSite)) | ||
.Returns(unassignedPageTypes); | ||
} | ||
|
||
private IEnumerable<PageType> GetListOfUnassignedPageTypes() | ||
{ | ||
return new List<PageType> | ||
{ | ||
new PageType | ||
{ | ||
ClassName = "DancingGoatMvc.Article", | ||
ClassDisplayName = "Article (MVC)", | ||
NodeSiteID = 1, | ||
NodeClassID = 5494 | ||
}, | ||
new PageType | ||
{ | ||
ClassName = "DancingGoatMvc.Brewer", | ||
ClassDisplayName = "Brewer (MVC)", | ||
NodeSiteID = 1, | ||
NodeClassID = 5477 | ||
}, | ||
new PageType | ||
{ | ||
ClassName = "CMS.News", | ||
ClassDisplayName = "News", | ||
NodeSiteID = 2, | ||
NodeClassID = 5502 | ||
}, | ||
new PageType | ||
{ | ||
ClassName = "CMS.Office", | ||
ClassDisplayName = "Office", | ||
NodeSiteID = 2, | ||
NodeClassID = 5514 | ||
}, | ||
new PageType | ||
{ | ||
ClassName = "globaltypes.customtype", | ||
ClassDisplayName = "Custom Type", | ||
NodeSiteID = 2, | ||
NodeClassID = 5497 | ||
}, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
KenticoInspector.Reports/PageTypeAssignmentAnalysis/Metadata/en-US.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
details: | ||
name: Page Type Assignment Analysis | ||
shortDescription: Displays page types used by a certain site without being assigned to this site. | ||
longDescription: | | ||
If the page type is not assigned to the site and is used by this site, you will encounter problems while using import/export feature. | ||
terms: | ||
warningSummary: <unassignedPageTypeCount> page <unassignedPageTypeCount:type|types> found that <unassignedPageTypeCount:is|are> not assigned to the site <unassignedPageTypeCount:it|they> <unassignedPageTypeCount:is|are> used on. | ||
unassignedPageTypesTableHeader: Page types not assigned to site | ||
noIssuesFound: All page types are assigned to sites. |
10 changes: 10 additions & 0 deletions
10
KenticoInspector.Reports/PageTypeAssignmentAnalysis/Models/PageType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models | ||
{ | ||
public class PageType | ||
{ | ||
public string ClassDisplayName { get; set; } | ||
public string ClassName { get; set; } | ||
public int NodeClassID { get; set; } | ||
public int NodeSiteID { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
KenticoInspector.Reports/PageTypeAssignmentAnalysis/Models/Terms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using KenticoInspector.Core.Models; | ||
|
||
namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models | ||
{ | ||
public class Terms | ||
{ | ||
public Term WarningSummary { get; set; } | ||
public Term UnassignedPageTypesTableHeader { get; set; } | ||
public Term NoIssuesFound { get; set; } | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
KenticoInspector.Reports/PageTypeAssignmentAnalysis/Report.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using KenticoInspector.Core; | ||
using KenticoInspector.Core.Constants; | ||
using KenticoInspector.Core.Helpers; | ||
using KenticoInspector.Core.Models; | ||
using KenticoInspector.Core.Services.Interfaces; | ||
using KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis | ||
{ | ||
public class Report : AbstractReport<Terms> | ||
{ | ||
private readonly IDatabaseService databaseService; | ||
|
||
public Report(IDatabaseService databaseService, IReportMetadataService reportMetadataService) : base(reportMetadataService) | ||
{ | ||
this.databaseService = databaseService; | ||
} | ||
|
||
public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("10", "11", "12"); | ||
|
||
public override IList<string> Tags => new List<string> | ||
{ | ||
ReportTags.Health, | ||
ReportTags.Consistency | ||
}; | ||
|
||
public override ReportResults GetResults() | ||
{ | ||
var unassignedPageTypes = databaseService.ExecuteSqlFromFile<PageType>(Scripts.GetPageTypesNotAssignedToSite); | ||
|
||
return CompileResults(unassignedPageTypes); | ||
} | ||
|
||
private ReportResults CompileResults(IEnumerable<PageType> unassignedPageTypes) | ||
{ | ||
var results = new ReportResults | ||
{ | ||
Status = ReportResultsStatus.Good, | ||
Summary = Metadata.Terms.NoIssuesFound, | ||
Type = ReportResultsType.Table, | ||
Data = new TableResult<PageType>() | ||
{ | ||
Name = Metadata.Terms.UnassignedPageTypesTableHeader, | ||
Rows = unassignedPageTypes | ||
} | ||
}; | ||
|
||
var unassignedPageTypeCount = unassignedPageTypes.Count(); | ||
if (unassignedPageTypeCount > 0) | ||
{ | ||
results.Status = ReportResultsStatus.Warning; | ||
results.Summary = Metadata.Terms.WarningSummary.With(new { unassignedPageTypeCount }); | ||
} | ||
|
||
return results; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
KenticoInspector.Reports/PageTypeAssignmentAnalysis/Scripts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis | ||
{ | ||
public class Scripts | ||
{ | ||
public static string BaseDirectory = $"{nameof(PageTypeAssignmentAnalysis)}/Scripts"; | ||
|
||
public static string GetPageTypesNotAssignedToSite = $"{BaseDirectory}/{nameof(GetPageTypesNotAssignedToSite)}.sql"; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...icoInspector.Reports/PageTypeAssignmentAnalysis/Scripts/GetPageTypesNotAssignedToSite.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SELECT DISTINCT NodeSiteID, NodeClassID, ClassName, ClassDisplayName | ||
FROM View_CMS_Tree_Joined | ||
LEFT JOIN CMS_ClassSite on | ||
ClassID = NodeClassID AND | ||
SiteID = NodeSiteID | ||
WHERE SiteID is null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters