-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathWebTest.php
120 lines (100 loc) · 3.41 KB
/
WebTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Office365;
use Office365\SharePoint\PrincipalType;
use Office365\SharePoint\RoleAssignment;
use Office365\SharePoint\Web;
use Office365\SharePoint\WebCreationInformation;
class WebTest extends SharePointTestCase
{
public function testGetWebByAbsUrl()
{
$pageAbsUrl = self::$settings["Url"] . "/sites/team/SitePages/Home.aspx";
$result = Web::getWebUrlFromPageUrl(self::$context,$pageAbsUrl)->executeQuery();
self::assertNotEmpty($result->getValue());
}
public function testGetWebGroups()
{
$groups = self::$context->getWeb()->getRoleAssignments()->getGroups()->get()->executeQuery();
self::assertNotEmpty($groups->getData());
}
public function testGetWebUsers()
{
$assignments = self::$context->getWeb()->getRoleAssignments()
->expand("Member")
->get()
->executeQuery();
$result = array_filter(
$assignments->getData(),
function (RoleAssignment $assignment) {
$principal = $assignment->getMember();
return ($principal->getPrincipalType() === PrincipalType::SharePointGroup
|| $principal->getPrincipalType() === PrincipalType::User);
}
);
self::assertGreaterThanOrEqual(1,count($result));
}
public function testCreateWeb()
{
$targetWebUrl = "Workspace_" . date("Y-m-d") . rand(1,10000);
$info = new WebCreationInformation($targetWebUrl,$targetWebUrl);
$targetWeb = self::$context->getWeb()->getWebs()->add($info)->executeQuery();
$this->assertEquals($targetWebUrl,$targetWeb->getTitle());
return $targetWeb;
}
/**
* @depends testCreateWeb
* @param Web $targetWeb
* @return Web
*/
public function testIfWebExist(Web $targetWeb)
{
$webTitle = $targetWeb->getTitle();
$webs = self::$context->getWeb()->getWebs()
->filter("Title eq '$webTitle'")
->get()
->executeQuery();
$this->assertEquals(1, $webs->getCount());
return $targetWeb;
}
/**
* @depends testCreateWeb
* @param Web $targetWeb
* @return Web
*/
public function testUpdateWeb(Web $targetWeb)
{
$webTitle = self::createUniqueName("WS_Updated");
$targetWeb->setTitle($webTitle)->update()->executeQuery();
$webs = self::$context->getWeb()->getWebs()
->filter("Title eq '$webTitle'")
->get()
->executeQuery();
$this->assertEquals(1,$webs->getCount());
return $targetWeb;
}
/**
* @depends testCreateWeb
* @param Web $targetWeb
*/
public function testAssignUniquePermissions(Web $targetWeb)
{
$targetWeb
->breakRoleInheritance(true)
->executeQuery();
$result = $targetWeb->select(["HasUniqueRoleAssignments"])->get()->executeQuery();
self::assertTrue($result->getHasUniqueRoleAssignments());
}
/**
* @depends testCreateWeb
* @param Web $targetWeb
*/
public function testTryDeleteWeb(Web $targetWeb){
$title = $targetWeb->getTitle();
$targetWeb->deleteObject()->executeQuery();
$webs = self::$context->getWeb()->getWebs()
->filter("Title eq '$title'")
->get()
->executeQuery();
$this->assertEquals(0,$webs->getCount());
}
}