/**
  * @covers WindowsAzure\Blob\Models\ListBlobBlocksOptions::getIncludeCommittedBlobs
  */
 public function testGetIncludeCommittedBlobs()
 {
     // Setup
     $options = new ListBlobBlocksOptions();
     $expected = true;
     $options->setIncludeCommittedBlobs($expected);
     // Test
     $actual = $options->getIncludeCommittedBlobs();
     // Assert
     $this->assertEquals($expected, $actual);
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  **/
 public function testCreateBlobLargerThanSingleBlock()
 {
     // First step, lets set the value for automagic splitting to somethign very small
     $max_size = 50;
     $this->restProxy->setSingleBlobUploadThresholdInBytes($max_size);
     $this->assertEquals($this->restProxy->getSingleBlobUploadThresholdInBytes(), $max_size);
     $name = 'createbloblargerthansingleblock' . $this->createSuffix();
     $this->createContainer($name);
     $contentType = 'text/plain; charset=UTF-8';
     $content = "This is a really long section of text needed for this test.";
     // Note this grows fast, each loop doubles the last run. Do not make too big
     // This results in a 1888 byte string, divided by 50 results in 38 blocks
     for ($i = 0; $i < 5; $i++) {
         $content .= $content;
     }
     $options = new CreateBlobOptions();
     $options->setContentType($contentType);
     $this->restProxy->createBlockBlob($name, 'little_split', $content, $options);
     // Block specific
     $boptions = new ListBlobBlocksOptions();
     $boptions->setIncludeUncommittedBlobs(true);
     $boptions->setIncludeCommittedBlobs(true);
     $result = $this->restProxy->listBlobBlocks($name, 'little_split', $boptions);
     $blocks = $result->getUnCommittedBlocks();
     $this->assertEquals(count($blocks), 0);
     $blocks = $result->getCommittedBlocks();
     $this->assertEquals(count($blocks), ceil(strlen($content) / $max_size));
     // Setting back to default value for one shot test
     $this->restProxy->setSingleBlobUploadThresholdInBytes(0);
     $this->restProxy->createBlockBlob($name, 'oneshot', $content, $options);
     $result = $this->restProxy->listBlobBlocks($name, 'oneshot', $boptions);
     $blocks = $result->getUnCommittedBlocks();
     $this->assertEquals(count($blocks), 0);
     $blocks = $result->getCommittedBlocks();
     // this one doesn't make sense. On emulator, there is no block created,
     // so relying on content size to be final approval
     $this->assertEquals(count($blocks), 0);
     $this->assertEquals($result->getContentLength(), strlen($content));
     // make string even larger for automagic splitting
     // This should result in a string longer than 32M, and force the blob into 2 blocks
     for ($i = 0; $i < 15; $i++) {
         $content .= $content;
     }
     $this->restProxy->createBlockBlob($name, 'bigsplit', $content, $options);
     $result = $this->restProxy->listBlobBlocks($name, 'bigsplit', $boptions);
     $blocks = $result->getUnCommittedBlocks();
     $this->assertEquals(count($blocks), 0);
     $blocks = $result->getCommittedBlocks();
     $this->assertEquals(count($blocks), ceil(strlen($content) / (4 * 1024 * 1024)));
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::commitBlobBlocks
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlobBlock
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::listBlobBlocks
  */
 public function testCommitBlobBlocksWithArrayWorks()
 {
     // Act
     $container = self::$_test_container_for_blobs;
     $blob = 'test14a';
     $blockId1 = '1fedcba';
     $blockId2 = '2abcdef';
     $blockId3 = '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));
     $block1 = new Block();
     $block1->setBlockId($blockId1);
     $block1->setType(BlobBlockType::UNCOMMITTED_TYPE);
     $block3 = new Block();
     $block3->setBlockId($blockId3);
     $block3->setType(BlobBlockType::LATEST_TYPE);
     $blockList = array($block1, $block3);
     $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())');
 }