Esempio n. 1
0
 /**
  * @covers MicrosoftAzure\Storage\Blob\Models\BlockList::toXml
  */
 public function testToXml()
 {
     // Setup
     $blockList = new BlockList();
     $blockList->addLatestEntry(base64_encode('1234'));
     $blockList->addCommittedEntry(base64_encode('1239'));
     $blockList->addLatestEntry(base64_encode('1236'));
     $blockList->addCommittedEntry(base64_encode('1237'));
     $blockList->addUncommittedEntry(base64_encode('1238'));
     $blockList->addLatestEntry(base64_encode('1235'));
     $blockList->addUncommittedEntry(base64_encode('1240'));
     $expected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<BlockList>' . "\n" . ' <Latest>MTIzNA==</Latest>' . "\n" . ' <Committed>MTIzOQ==</Committed>' . "\n" . ' <Latest>MTIzNg==</Latest>' . "\n" . ' <Committed>MTIzNw==</Committed>' . "\n" . ' <Uncommitted>MTIzOA==</Uncommitted>' . "\n" . ' <Latest>MTIzNQ==</Latest>' . "\n" . ' <Uncommitted>MTI0MA==</Uncommitted>' . "\n" . '</BlockList>' . "\n";
     // Test
     $actual = $blockList->toXml(new XmlSerializer());
     // Assert
     $this->assertEquals($expected, $actual);
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::commitBlobBlocks
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobBlock
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlockBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listBlobBlocks
  */
 public function testCommitBlobBlocksWorks()
 {
     // Act
     $container = self::$_test_container_for_blobs;
     $blob = 'test14';
     $blockId1 = base64_encode('1fedcba');
     $blockId2 = base64_encode('2abcdef');
     $blockId3 = base64_encode('3zzzzzz');
     $this->restProxy->createBlockBlob($container, $blob, '');
     $this->restProxy->createBlobBlock($container, $blob, $blockId1, str_pad('', 256));
     $this->restProxy->createBlobBlock($container, $blob, $blockId2, str_pad('', 512));
     $this->restProxy->createBlobBlock($container, $blob, $blockId3, str_pad('', 195));
     $blockList = new BlockList();
     $blockList->addUncommittedEntry($blockId1);
     $blockList->addLatestEntry($blockId3);
     $this->restProxy->commitBlobBlocks($container, $blob, $blockList);
     $opts = new ListBlobBlocksOptions();
     $opts->setIncludeCommittedBlobs(true);
     $opts->setIncludeUncommittedBlobs(true);
     $result = $this->restProxy->listBlobBlocks($container, $blob, $opts);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertNotNull($result->getLastModified(), '$result->getLastModified()');
     $this->assertNotNull($result->getETag(), '$result->getETag()');
     $this->assertEquals(256 + 195, $result->getContentLength(), '$result->getContentLength()');
     $this->assertNotNull($result->getCommittedBlocks(), '$result->getCommittedBlocks()');
     $this->assertEquals(2, count($result->getCommittedBlocks()), 'count($result->getCommittedBlocks())');
     $comblk = $result->getCommittedBlocks();
     $keys = array_keys($comblk);
     $this->assertEquals($blockId1, $keys[0], '$keys[0]');
     $this->assertEquals(256, $comblk[$keys[0]], '$comblk[$keys[0]]');
     $this->assertEquals($blockId3, $keys[1], '$keys[1]');
     $this->assertEquals(195, $comblk[$keys[1]], '$comblk[$keys[1]]');
     $this->assertNotNull($result->getUncommittedBlocks(), '$result->getUncommittedBlocks()');
     $this->assertEquals(0, count($result->getUncommittedBlocks()), 'count($result->getUncommittedBlocks())');
 }