Resources
5 years ago
AzureTest.php
1 year ago
ContactTest.php
5 years ago
DeltaQueryTest.php
1 year ago
EventTest.php
5 years ago
ExcelTest.php
1 year ago
GraphTestBase.php
1 year ago
MailTest.php
1 year ago
OnedriveTest.php
1 year ago
OnenoteTest.php
1 year ago
OpenTypeTest.php
1 year ago
PlannerTest.php
1 year ago
SharepointTest.php
1 year ago
TermStoreTest.php
1 year ago
TestConstants.php
1 year ago
UserTest.php
1 year ago
WebhooksTest.php
1 year ago
OnenoteTest.php
125 lines
| 1 | <?php |
| 2 | use PHPUnit\Framework\TestCase; |
| 3 | use Microsoft\Graph\Test\GraphTestBase; |
| 4 | use Microsoft\Graph\Model; |
| 5 | |
| 6 | class OnenoteTest extends TestCase |
| 7 | { |
| 8 | private $_client; |
| 9 | private $_testNotebook; |
| 10 | private $_testSection; |
| 11 | private $_testPage; |
| 12 | |
| 13 | protected function setUp(): void |
| 14 | { |
| 15 | $graphTestBase = new GraphTestBase(); |
| 16 | $this->_client = $graphTestBase->graphClient; |
| 17 | |
| 18 | $this->_testNotebook = $this->_client |
| 19 | ->createRequest("GET", "/me/onenote/notebooks/1-525fe350-0199-4c02-879d-e5b142ae8632") |
| 20 | ->setReturnType(Model\Notebook::class) |
| 21 | ->execute(); |
| 22 | |
| 23 | $sectionReader = $this->_client |
| 24 | ->createCollectionRequest("GET", "/me/onenote/notebooks/" . $this->_testNotebook->getId() . "/sections") |
| 25 | ->setReturnType(Model\OnenoteSection::class); |
| 26 | $this->_testSection = $sectionReader->getPage()[0]; |
| 27 | |
| 28 | $pageReader = $this->_client |
| 29 | ->createCollectionRequest("GET", "/me/onenote/pages") |
| 30 | ->setReturnType(Model\OnenotePage::class); |
| 31 | $this->_testPage = $pageReader->getPage()[0]; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @group functional |
| 36 | */ |
| 37 | public function testODataQueries() |
| 38 | { |
| 39 | $countedBooks = $this->_client |
| 40 | ->createRequest("GET", "/me/onenote/notebooks?count=true") |
| 41 | ->setReturnType(Model\Notebook::class) |
| 42 | ->execute(); |
| 43 | $this->assertTrue(count($countedBooks) > 0); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @group functional |
| 48 | */ |
| 49 | public function testGetPageContent() |
| 50 | { |
| 51 | $content = $this->_client |
| 52 | ->createRequest("GET", "/me/onenote/pages/" . $this->_testPage->getId() . "/content") |
| 53 | ->setReturnType(AmeliaGuzzleHttp\Psr7\Stream::class) |
| 54 | ->execute(); |
| 55 | |
| 56 | $this->assertNotNull($content->getContents()); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @group functional |
| 61 | */ |
| 62 | public function testPostToNotebook() |
| 63 | { |
| 64 | $contentStream = AmeliaGuzzleHttp\Psr7\stream_for('<html><head><title>Test Title</title></head><body>Test body</body></html>'); |
| 65 | $newPage = $this->_client |
| 66 | ->createRequest("POST", "/me/onenote/sections/" . $this->_testSection->getId() . "/pages") |
| 67 | ->addHeaders(array("Content-Type" => "application/xhtml+xml")) |
| 68 | ->attachBody($contentStream) |
| 69 | ->setReturnType(Model\OnenotePage::class) |
| 70 | ->execute(); |
| 71 | $this->assertEquals("Test Title", $newPage->getTitle()); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @group functional |
| 76 | */ |
| 77 | public function testMultipartPost() |
| 78 | { |
| 79 | $boundary = md5(time()); |
| 80 | |
| 81 | $html = "--" . $boundary . "\r\n" . |
| 82 | "Content-Disposition:form-data; name=\"Presentation\"" . "\r\n" . |
| 83 | "Content-Type: text/html" . "\r\n" . |
| 84 | "\r\n" . |
| 85 | "<!DOCTYPE html>\r\n" . |
| 86 | "<html lang=\"en-US\">\r\n" . |
| 87 | "<head>\r\n" . |
| 88 | "<title>Test Multipart Page</title>\r\n" . |
| 89 | "<meta name=\"created\" content=\"2001-01-01T01:01+0100\">\r\n" . |
| 90 | "</head>\r\n" . |
| 91 | "<body>\r\n" . |
| 92 | "<p>\r\n" . |
| 93 | "<img src=\"name:image\" />\r\n" . |
| 94 | "</p>\r\n" . |
| 95 | "<p>\r\n" . |
| 96 | "<object data=\"name:attachment\" data-attachment=\"document.pdf\" /></p>\r\n" . |
| 97 | "\r\n" . |
| 98 | "</body>\r\n" . |
| 99 | "</html>\r\n" . |
| 100 | "\r\n" . |
| 101 | "--" . $boundary . "\r\n" . |
| 102 | "Content-Disposition:form-data; name=\"image\"\r\n" . |
| 103 | "Content-Type: image/jpeg\r\n\r\n"; |
| 104 | |
| 105 | $doc = "\r\n\r\n" . |
| 106 | "--" . $boundary . "\r\n" . |
| 107 | "Content-Disposition:form-data; name=\"attachment\"\r\n" . |
| 108 | "Content-Type:application/pdf\r\n\r\n"; |
| 109 | |
| 110 | $end = "\r\n\r\n" . |
| 111 | "--" . $boundary . "--"; |
| 112 | |
| 113 | $imageStream = AmeliaGuzzleHttp\Psr7\stream_for(fopen("./tests/Functional/Resources/hamilton.jpg", "r")); |
| 114 | $docStream = AmeliaGuzzleHttp\Psr7\stream_for(fopen("./tests/Functional/Resources/document.pdf", "r")); |
| 115 | |
| 116 | $request = AmeliaGuzzleHttp\Psr7\stream_for($html . $imageStream . $doc . $docStream . $end); |
| 117 | |
| 118 | $newPage = $this->_client |
| 119 | ->createRequest("POST", "/me/onenote/sections/" . $this->_testSection->getId() . "/pages") |
| 120 | ->addHeaders(array("Content-Type" => "multipart/form-data; boundary=\"" . $boundary . "\"")) |
| 121 | ->attachBody($request) |
| 122 | ->execute(); |
| 123 | $this->assertNotNull($newPage); |
| 124 | } |
| 125 | } |