Skip to content

Commit

Permalink
OData serializer adjustments, unit tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Jan 31, 2022
1 parent 0f4f36b commit ac361a6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/OneNote/Onenote.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


use Office365\Entity;
use Office365\EntityCollection;
use Office365\OneNote\Pages\OnenotePageCollection;
use Office365\OneNote\Sections\OnenoteSection;
use Office365\Runtime\ResourcePath;
/**
* "The entry point for OneNote resources."
Expand All @@ -23,4 +25,15 @@ public function getPages()
return $this->getProperty("Pages",
new OnenotePageCollection($this->getContext(),new ResourcePath("Pages", $this->getResourcePath())));
}

/**
* @return EntityCollection
*/
public function getSections()
{
return $this->getProperty("Sections",
new EntityCollection($this->getContext(),
new ResourcePath("Sections",
$this->getResourcePath()), OnenoteSection::class));
}
}
5 changes: 3 additions & 2 deletions src/Runtime/OData/ODataRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function nextProperty($json, $format)
yield "value" => $json;


if (isset($json[$format->CollectionTag])) {
if (isset($json[$format->CollectionTag]) && is_array($json[$format->CollectionTag])) {
if (isset($json[$format->NextCollectionTag])) {
yield $format->NextCollectionTag => $json[$format->NextCollectionTag];
}
Expand Down Expand Up @@ -312,7 +312,8 @@ private function isValidProperty($key,$value,$format)
} else if ($format instanceof JsonFormat) {
return fnmatch("$format->ControlFamilyTag.*", $key) !== true
&& fnmatch("*$format->ControlFamilyTag.*", $key) !== true
&& fnmatch("$format->TypeTag.*", $key) !== true;
&& fnmatch("$format->TypeTag.*", $key) !== true
&& fnmatch("#microsoft.graph.*", $key) !== true;

}
return true;
Expand Down
4 changes: 3 additions & 1 deletion tests/onenote/OneNoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class OneNoteTest extends GraphTestCase
{

public function testListPages(){
$pages = self::$graphClient->getMe()->getOnenote()->getPages()->top(10)->get()->executeQuery();
$sections = self::$graphClient->getMe()->getOnenote()->getSections()->top(1)->get()->executeQuery();
self::assertGreaterThan(0, $sections->getCount());
$pages = $sections[0]->getPages()->top(10)->get()->executeQuery();
self::assertNotNull($pages->getServerObjectIsNull());
}

Expand Down
9 changes: 9 additions & 0 deletions tests/teams/TeamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
class TeamsTest extends GraphTestCase
{

/**
* @var Team
*/
protected static $targetTeam;

public function testGetJoinedTeams()
{
$myTeams = self::$graphClient->getMe()->getJoinedTeams()->get()->executeQuery();
Expand Down Expand Up @@ -70,6 +75,7 @@ public function testAddTeamMember(Team $team)
$user = self::$graphClient->getUsers()->getById(self::$testAccountName);
$member = $team->addMember($user, ["owner"])->executeQuery();
self::assertNotNull($member->getResourcePath());
self::$targetTeam = $team;
return $member;
}

Expand All @@ -91,7 +97,10 @@ public function testListTeamMembers(Team $team)
*/
public function testRemoveTeamMember(Entity $member)
{
$membersBefore = self::$targetTeam->getMembers()->get()->executeQuery();
$member->deleteObject()->executeQuery();
$membersAfter = self::$targetTeam->getMembers()->get()->executeQuery();
self::assertEquals($membersBefore->getCount() - 1, $membersAfter->getCount());
}

/**
Expand Down

0 comments on commit ac361a6

Please sign in to comment.