public function testCreateContentKeyAuthorizationPolicyOptionForPlayReady()
 {
     // Setup Token
     $template = new TokenRestrictionTemplate(TokenType::SWT);
     $template->setPrimaryVerificationKey(new SymmetricVerificationKey());
     $template->setAlternateVerificationKeys(array(new SymmetricVerificationKey()));
     $template->setAudience('http://sampleaudience/');
     $template->setIssuer('http://sampleissuerurl/');
     $claims = array();
     $claims[] = new TokenClaim(TokenClaim::CONTENT_KEY_ID_CLAIM_TYPE);
     $claims[] = new TokenClaim('Rental', 'true');
     $template->setRequiredClaims($claims);
     $serializedTemplate = TokenRestrictionTemplateSerializer::serialize($template);
     // Setup Options
     $name = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_OPTIONS_NAME . $this->createSuffix();
     $restrictionName = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_POLICY_RESTRICTION_NAME . $this->createSuffix();
     $restriction = new ContentKeyAuthorizationPolicyRestriction();
     $restriction->setName($restrictionName);
     $restriction->setKeyRestrictionType(ContentKeyRestrictionType::TOKEN_RESTRICTED);
     $restriction->setRequirements($serializedTemplate);
     $restrictions = array($restriction);
     $options = new ContentKeyAuthorizationPolicyOption();
     $options->setName($name);
     $options->setKeyDeliveryType(ContentKeyDeliveryType::PLAYREADY_LICENSE);
     $playReadytemplate = $this->getPlayReadyTemplate();
     $deliveryConfiguration = MediaServicesLicenseTemplateSerializer::serialize($playReadytemplate);
     $options->setKeyDeliveryConfiguration($deliveryConfiguration);
     $options->setRestrictions($restrictions);
     // Test
     $result = $this->createContentKeyAuthorizationPolicyOption($options);
     // Retrieve the CKAPO again.
     $result = $this->restProxy->getContentKeyAuthorizationPolicyOption($result->getId());
     // Assert Options
     $this->assertEquals($options->getName(), $result->getName());
     $this->assertEquals($options->getKeyDeliveryType(), $result->getKeyDeliveryType());
     $this->assertEquals($options->getRestrictions(), $result->getRestrictions());
     $receivedTemplate = $result->getRestrictions()[0]->getRequirements();
     $receivedPlayReadyTemplate = $options->getKeyDeliveryConfiguration();
     $playReadyTemplate2 = MediaServicesLicenseTemplateSerializer::deserialize($receivedPlayReadyTemplate);
     // Assert Restrictions
     $template2 = TokenRestrictionTemplateSerializer::deserialize($receivedTemplate);
     $this->assertEqualsTokenRestrictionTemplate($template, $template2);
     $this->assertEqualsLicenseResponseTemplate($playReadytemplate, $playReadyTemplate2);
     return $result->getId();
 }
 /**
  * @covers \WindowsAzure\MediaServices\Templates\MediaServicesLicenseTemplateSerializer::serialize
  * @covers \WindowsAzure\MediaServices\Templates\MediaServicesLicenseTemplateSerializer::deserialize
  */
 public function testRoundTripTest()
 {
     $template = new PlayReadyLicenseResponseTemplate();
     $template->setResponseCustomData('test custom data');
     $licenseTemplate = new PlayReadyLicenseTemplate();
     $template->setLicenseTemplates(array($licenseTemplate));
     $licenseTemplate->setLicenseType(PlayReadyLicenseType::PERSISTENT);
     $licenseTemplate->setBeginDate(new \DateTime('now'));
     $licenseTemplate->setRelativeExpirationDate(new \DateInterval('PT6H'));
     $licenseTemplate->setContentKey(new ContentEncryptionKeyFromKeyIdentifier('test custom id'));
     $playRight = new PlayReadyPlayRight();
     $licenseTemplate->setPlayRight($playRight);
     $playRight->setAgcAndColorStripeRestriction(new AgcAndColorStripeRestriction(1));
     $playRight->setAllowPassingVideoContentToUnknownOutput(UnknownOutputPassingOption::ALLOWED);
     $playRight->setAnalogVideoOpl(100);
     $playRight->setCompressedDigitalAudioOpl(300);
     $playRight->setCompressedDigitalVideoOpl(400);
     $playRight->setExplicitAnalogTelevisionOutputRestriction(new ExplicitAnalogTelevisionRestriction(0, true));
     $playRight->setImageConstraintForAnalogComponentVideoRestriction(true);
     $playRight->setImageConstraintForAnalogComputerMonitorRestriction(true);
     $playRight->setScmsRestriction(new ScmsRestriction(2));
     $playRight->setUncompressedDigitalAudioOpl(250);
     $playRight->setUncompressedDigitalVideoOpl(270);
     $result = MediaServicesLicenseTemplateSerializer::serialize($template);
     $playreadyLicense = MediaServicesLicenseTemplateSerializer::deserialize($result);
     $this->assertEqualsLicenseResponseTemplate($template, $playreadyLicense);
 }