Skip to content

Commit

Permalink
+ fixed ListItemAllFields error for WebPart Pages not in lists #984
Browse files Browse the repository at this point in the history
+ added CanDeploy_WebpartTo_VideoContentType_VideoPlayerPage
+ CSOM fix, green tests
  • Loading branch information
SubPointSupport committed Mar 29, 2017
1 parent 7022a43 commit 6195fae
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 70 deletions.
25 changes: 24 additions & 1 deletion SPMeta2/SPMeta2.CSOM/ModelHandlers/FolderModelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,33 @@ public override void WithResolvingModelHost(ModelHostResolveContext modelHostCon
var folderModelHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull());
var folderModel = model.WithAssertAndCast<FolderDefinition>("model", value => value.RequireNotNull());

var isSpecialFolderContext = false;

if (folderModelHost.CurrentList != null && folderModelHost.CurrentList.BaseType == BaseType.DocumentLibrary)
{
var currentFolder = EnsureLibraryFolder(folderModelHost, folderModel);

// preload props to identify 'special folder'
// once done, pass down via model host
if (folderModel.Name.ToLower() == "forms")
{
currentFolder.Context.Load(currentFolder, f => f.Properties);
currentFolder.Context.ExecuteQueryWithTrace();

var doesFileHaveListItem =
//Forms folders
!(currentFolder != null
&&
(currentFolder.Properties.FieldValues.ContainsKey("vti_winfileattribs")
&&
currentFolder.Properties.FieldValues["vti_winfileattribs"].ToString() ==
"00000012"));

isSpecialFolderContext = !doesFileHaveListItem;

folderModelHost.IsSpecialFolderContext = isSpecialFolderContext;
}

var newContext = ModelHostBase.Inherit<FolderModelHost>(folderModelHost, c =>
{
c.CurrentList = folderModelHost.CurrentList;
Expand Down Expand Up @@ -383,7 +406,7 @@ private Folder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefini
var currentFolderItem = currentFolder.ListItemAllFields;

// could be NULL, in the /Forms or other hidden folders
if (currentFolderItem != null
if (currentFolderItem != null
&& currentFolderItem.ServerObjectIsNull != null
&& !currentFolderItem.ServerObjectIsNull.Value)
{
Expand Down
6 changes: 0 additions & 6 deletions SPMeta2/SPMeta2.CSOM/ModelHandlers/ModuleFileModelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,7 @@ public static void WithSafeFileOperation(List list, File file,
if (file != null)
{
context.Load(file, f => f.Exists);
context.Load(file, f => f.ListItemAllFields); //SergeiSnitko. Need to be loaded to get if object is null
context.ExecuteQueryWithTrace();
//SergeiSnitko. I don't know all logic based on doesFileHasListItem. So I fill doesFileHasListItem by the real value
//of ListItem existing only if doesFileHasListItem is true. This action helps to prevent exceptions on web part provision
//on the page without ListItem not only under Forms folder (for example Forms/ContentTypeName/videoplayerpage.aspx fires exception)
doesFileHasListItem = doesFileHasListItem ? !(bool)file.ListItemAllFields.ServerObjectIsNull : doesFileHasListItem;


if (file.Exists)
{
Expand Down
6 changes: 6 additions & 0 deletions SPMeta2/SPMeta2.CSOM/ModelHandlers/WebPartModelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ public override void DeployModel(object modelHost, DefinitionBase model)
listItemModelHost.HostFolder.Properties.FieldValues["vti_winfileattribs"].ToString() ==
"00000012"));

// is parent /forms folder or nay other special page?
if (doesFileHasListItem)
{
doesFileHasListItem = !listItemModelHost.IsSpecialFolderContext;
}

#endif

#if NET35
Expand Down
54 changes: 28 additions & 26 deletions SPMeta2/SPMeta2.CSOM/ModelHosts/FolderModelHost.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using Microsoft.SharePoint.Client;

namespace SPMeta2.CSOM.ModelHosts
{
public class FolderModelHost : CSOMModelHostBase
{
#region properties

public List CurrentList { get; set; }
public ListItem CurrentListItem { get; set; }

public Folder CurrentListFolder { get; set; }

public Web CurrentWeb { get; set; }
public Folder CurrentWebFolder { get; set; }

public ContentType CurrentContentType { get; set; }
public Folder CurrentContentTypeFolder { get; set; }

//public Folder Folder { get; set; }
//public List List { get; set; }
//public Web Web { get; set; }

#endregion
}
}
using Microsoft.SharePoint.Client;

namespace SPMeta2.CSOM.ModelHosts
{
public class FolderModelHost : CSOMModelHostBase
{
#region properties

public List CurrentList { get; set; }
public ListItem CurrentListItem { get; set; }

public Folder CurrentListFolder { get; set; }

public Web CurrentWeb { get; set; }
public Folder CurrentWebFolder { get; set; }

public ContentType CurrentContentType { get; set; }
public Folder CurrentContentTypeFolder { get; set; }

//public Folder Folder { get; set; }
//public List List { get; set; }
//public Web Web { get; set; }

public bool IsSpecialFolderContext { get; set; }

#endregion
}
}
4 changes: 3 additions & 1 deletion SPMeta2/SPMeta2.CSOM/ModelHosts/ListItemModelHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class ListItemModelHost : CSOMModelHostBase

#endregion

public List HostList { get; set; }
public List HostList { get; set; }

public bool IsSpecialFolderContext { get; set; }
}
}
145 changes: 109 additions & 36 deletions SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/WebpartScenariosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void CanDeploy_Random_V3_Webpart_WithAllChrome()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.ListViews")]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_UploadForm_InLibrary()
{
var model = SPMeta2Model
Expand All @@ -170,6 +171,7 @@ public void CanDeploy_WebpartTo_UploadForm_InLibrary()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.ListViews")]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_OOTBListViews_InLibrary()
{
var model = SPMeta2Model
Expand Down Expand Up @@ -205,6 +207,7 @@ public void CanDeploy_WebpartTo_OOTBListViews_InLibrary()
}

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
[TestCategory("Regression.Scenarios.Webparts.ListViews")]
public void CanDeploy_WebpartTo_CustomListViews_InLibrary()
{
Expand Down Expand Up @@ -244,6 +247,7 @@ public void CanDeploy_WebpartTo_CustomListViews_InLibrary()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.ListViews")]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_OOTBListViews_InList()
{
var model = SPMeta2Model
Expand Down Expand Up @@ -289,6 +293,7 @@ public void CanDeploy_WebpartTo_OOTBListViews_InList()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.ListViews")]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_CustomListViews_InList()
{
var model = SPMeta2Model
Expand Down Expand Up @@ -331,6 +336,7 @@ public void CanDeploy_WebpartTo_CustomListViews_InList()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.ListForms")]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_ListForm_InLibrary()
{
var model = SPMeta2Model
Expand Down Expand Up @@ -361,6 +367,7 @@ public void CanDeploy_WebpartTo_ListForm_InLibrary()
}

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
[TestCategory("Regression.Scenarios.Webparts.ListForms")]
public void CanDeploy_WebpartTo_ListForm_InList()
{
Expand Down Expand Up @@ -431,7 +438,8 @@ public void CanDeploy_Webpart_With_AuthorizationFilter()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToWebpartPage()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_WebpartPage()
{
var model = SPMeta2Model
.NewWebModel(web =>
Expand Down Expand Up @@ -461,7 +469,8 @@ public void CanDeploy_WebpartToWebpartPage()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToWebpartPage_WithCustomPageLayout()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_WebpartPage_WithCustomPageLayout()
{
var webPartPage1 = ModelGeneratorService.GetRandomDefinition<WebPartPageDefinition>(def =>
{
Expand Down Expand Up @@ -538,48 +547,109 @@ public void CanDeploy_Webpart_WithTitleUrl_WithTokens()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToPublishingPageWebPartZone()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_VideoContentType_VideoPlayerPage()
{
var siteModel = SPMeta2Model
.NewSiteModel(site =>
{
site
.AddSiteFeature(RegSiteFeatures.Publishing);
});
// aiming to deploy a web part to the following page with in a library
// forms/videocontenttype/videoplayerpage.aspx

var listDef = ModelGeneratorService.GetRandomDefinition<ListDefinition>(def =>
{
def.ContentTypesEnabled = true;
def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary;
});

var contentTypeName = "Video";
var contentTypeLinkDef = new ContentTypeLinkDefinition
{
ContentTypeName = contentTypeName,
ContentTypeId = BuiltInSiteContentTypeId.Video
};

var formsFolder = new FolderDefinition
{
Name = "Forms"
};

var contentTypeFolder = new FolderDefinition
{
Name = contentTypeName
};

var pageDefinition = new WebPartPageDefinition
{
FileName = "videoplayerpage.aspx",
PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1,
NeedOverride = false
};

var model = SPMeta2Model.NewWebModel(web =>
{
web.AddList(listDef, list =>
{
list.AddContentTypeLink(contentTypeLinkDef);
list.AddFolder(formsFolder, forms =>
{
forms.AddFolder(contentTypeFolder, folder =>
{
folder.AddHostWebPartPage(pageDefinition, page =>
{
page.AddRandomWebpart();
page.AddRandomWebpart();
page.AddRandomWebpart();
});
});
});
});
});

TestModel(model);
}

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_PublishingPageWebPartZone()
{
var siteModel = SPMeta2Model.NewSiteModel(site =>
{
site.AddSiteFeature(RegSiteFeatures.Publishing);
});

TestModel(siteModel);

var webModel = SPMeta2Model
.NewWebModel(web =>
{
web
.AddWebFeature(RegWebFeatures.Publishing)
.AddHostList(BuiltInListDefinitions.Pages, list =>
{
list
.AddRandomPublishingPage(page =>
{
page
.AddRandomWebpart()
.AddRandomWebpart();
})
.AddRandomPublishingPage(page =>
{
page
.AddRandomWebpart()
.AddRandomWebpart();
});
});
var webModel = SPMeta2Model.NewWebModel(web =>
{
web
.AddWebFeature(RegWebFeatures.Publishing)
.AddHostList(BuiltInListDefinitions.Pages, list =>
{
list
.AddRandomPublishingPage(page =>
{
page
.AddRandomWebpart()
.AddRandomWebpart();
})
.AddRandomPublishingPage(page =>
{
page
.AddRandomWebpart()
.AddRandomWebpart();
});
});
});
});

TestModel(webModel);
}


[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToPublishingPageContent()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_PublishingPageContent()
{
var webModel = SPMeta2Model
.NewWebModel(web =>
Expand Down Expand Up @@ -656,7 +726,8 @@ public void CanDeploy_WebpartToPublishingPageContent()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToWikiPageContent_AsItIs()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_WikiPageContent_AsItIs()
{
// Some web part provision on wiki page give empty markup
// https://github.com/SubPointSolutions/spmeta2/issues/693
Expand All @@ -683,7 +754,7 @@ public void CanDeploy_WebpartToWikiPageContent_AsItIs()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_ScriptEditorToWikiPageContent_As_AddToPageContent()
public void CanDeploy_ScriptEditorTo_WikiPageContent_As_AddToPageContent()
{
// Some web part provision on wiki page give empty markup
// https://github.com/SubPointSolutions/spmeta2/issues/693
Expand Down Expand Up @@ -735,7 +806,8 @@ public void CanDeploy_ScriptEditorToWikiPageContent_As_AddToPageContent()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToWikiPageContent_As_AddToPageContent()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_WikiPageContent_As_AddToPageContent()
{
// Some web part provision on wiki page give empty markup
// https://github.com/SubPointSolutions/spmeta2/issues/693
Expand Down Expand Up @@ -800,7 +872,8 @@ public void CanDeploy_WebpartToWikiPageContent_As_AddToPageContent()

[TestMethod]
[TestCategory("Regression.Scenarios.Webparts")]
public void CanDeploy_WebpartToWikiPageContent()
[TestCategory("Regression.Scenarios.Webparts.Hosts")]
public void CanDeploy_WebpartTo_WikiPageContent()
{
var webModel = SPMeta2Model
.NewWebModel(web =>
Expand Down

0 comments on commit 6195fae

Please sign in to comment.