_client = $graphTestBase->graphClient; $this->_testNotebook = $this->_client ->createRequest("GET", "/me/onenote/notebooks/1-525fe350-0199-4c02-879d-e5b142ae8632") ->setReturnType(Model\Notebook::class) ->execute(); $sectionReader = $this->_client ->createCollectionRequest("GET", "/me/onenote/notebooks/" . $this->_testNotebook->getId() . "/sections") ->setReturnType(Model\OnenoteSection::class); $this->_testSection = $sectionReader->getPage()[0]; $pageReader = $this->_client ->createCollectionRequest("GET", "/me/onenote/pages") ->setReturnType(Model\OnenotePage::class); $this->_testPage = $pageReader->getPage()[0]; } /** * @group functional */ public function testODataQueries() { $countedBooks = $this->_client ->createRequest("GET", "/me/onenote/notebooks?count=true") ->setReturnType(Model\Notebook::class) ->execute(); $this->assertTrue(count($countedBooks) > 0); } /** * @group functional */ public function testGetPageContent() { $content = $this->_client ->createRequest("GET", "/me/onenote/pages/" . $this->_testPage->getId() . "/content") ->setReturnType(GuzzleHttp\Psr7\Stream::class) ->execute(); $this->assertNotNull($content->getContents()); } /** * @group functional */ public function testPostToNotebook() { $contentStream = GuzzleHttp\Psr7\stream_for('Test TitleTest body'); $newPage = $this->_client ->createRequest("POST", "/me/onenote/sections/" . $this->_testSection->getId() . "/pages") ->addHeaders(array("Content-Type" => "application/xhtml+xml")) ->attachBody($contentStream) ->setReturnType(Model\OnenotePage::class) ->execute(); $this->assertEquals("Test Title", $newPage->getTitle()); } /** * @group functional */ public function testMultipartPost() { $boundary = md5(time()); $html = "--" . $boundary . "\r\n" . "Content-Disposition:form-data; name=\"Presentation\"" . "\r\n" . "Content-Type: text/html" . "\r\n" . "\r\n" . "\r\n" . "\r\n" . "\r\n" . "Test Multipart Page\r\n" . "\r\n" . "\r\n" . "\r\n" . "

\r\n" . "\r\n" . "

\r\n" . "

\r\n" . "

\r\n" . "\r\n" . "\r\n" . "\r\n" . "\r\n" . "--" . $boundary . "\r\n" . "Content-Disposition:form-data; name=\"image\"\r\n" . "Content-Type: image/jpeg\r\n\r\n"; $doc = "\r\n\r\n" . "--" . $boundary . "\r\n" . "Content-Disposition:form-data; name=\"attachment\"\r\n" . "Content-Type:application/pdf\r\n\r\n"; $end = "\r\n\r\n" . "--" . $boundary . "--"; $imageStream = GuzzleHttp\Psr7\stream_for(fopen("./tests/Functional/Resources/hamilton.jpg", "r")); $docStream = GuzzleHttp\Psr7\stream_for(fopen("./tests/Functional/Resources/document.pdf", "r")); $request = GuzzleHttp\Psr7\stream_for($html . $imageStream . $doc . $docStream . $end); $newPage = $this->_client ->createRequest("POST", "/me/onenote/sections/" . $this->_testSection->getId() . "/pages") ->addHeaders(array("Content-Type" => "multipart/form-data; boundary=\"" . $boundary . "\"")) ->attachBody($request) ->execute(); $this->assertNotNull($newPage); } }