/** * @test */ public function testToXml() { $cfg = new DistributionConfigData(); $cfg->setAliases(array(array('cname' => 'cname-1'), new DistributionConfigAliasData('cname-2'))); $cfg->callerReference = 'caller-reference'; $cfg->comment = 'the-comment'; $cfg->enabled = true; $cfg->priceClass = 'price-class'; $cfg->defaultRootObject = 'default-root-object'; $cbd = new CacheBehaviorData(); $cbd->minTtl = 3600; $cbd->pathPattern = 'path-pattern'; $cbd->targetOriginId = 'target-origin-id'; $cbd->viewerProtocolPolicy = 'pp-1'; $cbd->setTrustedSigners(array(array('awsAccountNumber' => 'awsAccountNumber-1'), array('awsAccountNumber' => 'awsAccountNumber-2'))); $fc = new ForwardedValuesCookiesData(); $fc->forward = 'whitelist'; $fc->setWhitelistedNames(array(array('name' => 'cookie-name-1'), array('name' => 'cookie-name-2'))); $fwd = new ForwardedValuesData(); $fwd->queryString = true; $fwd->setCookies($fc); $cbd->setForwardedValues($fwd); $cfg->setCacheBehaviors(array($cbd, $cbd)); $cfg->setDefaultCacheBehavior($cbd); $this->assertEquals($this->getFixtureFileContent('CloudFront/20150727/DistributionConfig1.xml'), $cfg->toXml()); unset($cfg); }
/** * Loads CacheBehaviorData from simple xml object * * @param \SimpleXMLElement $sxml * @return CacheBehaviorData Returns CacheBehaviorData */ protected function _loadCacheBehaviorData(\SimpleXMLElement $sxml) { $item = null; if ($this->exist($sxml)) { $item = new CacheBehaviorData(); $item->setCloudFront($this->cloudFront); $item->forwardedValues = $this->_loadForwardedValuesData($sxml->ForwardedValues); $item->minTtl = $this->exist($sxml->MinTTL) ? $sxml->MinTTL - 0 : null; $item->defaultTtl = $this->exist($sxml->DefaultTTL) ? $sxml->DefaultTTL - 0 : null; $item->maxTtl = $this->exist($sxml->MaxTTL) ? $sxml->MaxTTL - 0 : null; $item->smoothStreaming = $this->exist($sxml->SmoothStreaming) ? (string) $sxml->SmoothStreaming == 'true' : null; $item->pathPattern = $this->exist($sxml->PathPattern) ? (string) $sxml->PathPattern : null; $item->targetOriginId = $this->exist($sxml->TargetOriginId) ? (string) $sxml->TargetOriginId : null; $item->trustedSigners = $this->_loadTrustedSignerList($sxml->TrustedSigners); $item->viewerProtocolPolicy = $this->exist($sxml->ViewerProtocolPolicy) ? (string) $sxml->ViewerProtocolPolicy : null; $item->allowedMethods = []; if (!empty($sxml->AllowedMethods->Items->Method)) { foreach ($sxml->AllowedMethods->Items->Method as $v) { $item->allowedMethods[] = (string) $v; } } $item->cachedMethods = []; if (!empty($sxml->AllowedMethods->CachedMethods->Items->Method)) { foreach ($sxml->AllowedMethods->CachedMethods->Items->Method as $v) { $item->cachedMethods[] = (string) $v; } } } return $item; }
/** * @test */ public function testFunctional() { $this->skipIfEc2PlatformDisabled(); $aws = $this->aws; //$aws->setDebug(true); $list = $aws->cloudFront->distribution->describe(); $this->assertInstanceOf($this->getCloudFrontClassName('DataType\\DistributionList'), $list); /* @var $dist CloudFrontDataType\DistirbutionData */ foreach ($list as $dist) { $dist->refresh(); $this->assertNotEmpty($dist->getOriginalXml()); $this->assertNotNull($dist->distributionConfig->getETag()); $dist->refreshConfig(); $this->assertNotNull($dist->getETag()); $this->assertInstanceOf($this->getCloudFrontClassName('DataType\\DistributionConfigData'), $dist->distributionConfig); $this->assertNotEmpty($dist->distributionConfig->getOriginalXml()); $dom = new \DOMDocument(); $dom->loadXML($dist->distributionConfig->getOriginalXml()); $this->assertEqualXMLStructure($dom->firstChild, $dist->distributionConfig->toXml(true)->firstChild); unset($dist); } unset($list); //Creates distribution $origin = new CloudFrontDataType\DistributionConfigOriginData(); $origin->originId = 'MyOriginId'; $origin->domainName = 'test.s3.amazonaws.com'; $origin->setS3OriginConfig(new CloudFrontDataType\DistributionS3OriginConfigData('')); $fvd = new CloudFrontDataType\ForwardedValuesData(); $fvd->queryString = false; $fvd->setCookies(new CloudFrontDataType\ForwardedValuesCookiesData(CloudFrontDataType\ForwardedValuesCookiesData::FORWARD_NONE)); $ts = new CloudFrontDataType\TrustedSignerList(); $ts->setEnabled(false); $dcb = new CloudFrontDataType\CacheBehaviorData(); $dcb->minTtl = 3600; $dcb->targetOriginId = $origin->originId; $dcb->viewerProtocolPolicy = 'allow-all'; $dcb->setForwardedValues($fvd); $dcb->setTrustedSigners($ts); $dc = new CloudFrontDataType\DistributionConfigData(); $dc->comment = 'phpunit test distribution'; $dc->enabled = false; $dc->setAliases(array(array('cname' => 'test2.scalr.com'))); $dc->priceClass = 'PriceClass_All'; $dc->setOrigins($origin); $dc->setDefaultCacheBehavior($dcb); $dist = $aws->cloudFront->distribution->create($dc); $this->assertInstanceOf($this->getCloudFrontClassName('DataType\\DistributionData'), $dist); $dist->refresh(); //Too time consuming test // $ret = $dist->delete(); // $this->assertTrue($ret); //Releases all memory from storage. $aws->getEntityManager()->detachAll(); }
/** * Loads CacheBehaviorData from simple xml object * * @param \SimpleXMLElement $sxml * @return CacheBehaviorData Returns CacheBehaviorData */ protected function _loadCacheBehaviorData(\SimpleXMLElement $sxml) { $item = null; if ($this->exist($sxml)) { $item = new CacheBehaviorData(); $item->setCloudFront($this->cloudFront); $item->forwardedValues = $this->_loadForwardedValuesData($sxml->ForwardedValues); $item->minTtl = $this->exist($sxml->MinTTL) ? $sxml->MinTTL - 0 : null; $item->pathPattern = $this->exist($sxml->PathPattern) ? (string) $sxml->PathPattern : null; $item->targetOriginId = $this->exist($sxml->TargetOriginId) ? (string) $sxml->TargetOriginId : null; $item->trustedSigners = $this->_loadTrustedSignerList($sxml->TrustedSigners); $item->viewerProtocolPolicy = $this->exist($sxml->ViewerProtocolPolicy) ? (string) $sxml->ViewerProtocolPolicy : null; } return $item; }