/**
  * @covers WindowsAzure\MediaServices\Templates\WidevineMessageSerializer::serialize
  */
 public function testToJson()
 {
     // Setup
     $template = new WidevineMessage();
     $template->allowed_track_types = AllowedTrackTypes::SD_HD;
     $contentKeySpecs = new ContentKeySpecs();
     $contentKeySpecs->required_output_protection = new RequiredOutputProtection();
     $contentKeySpecs->required_output_protection->hdcp = Hdcp::HDCP_NONE;
     $contentKeySpecs->security_level = 1;
     $contentKeySpecs->track_type = 'SD';
     $template->content_key_specs = array($contentKeySpecs);
     $policyOverrides = new \stdClass();
     $policyOverrides->can_play = true;
     $policyOverrides->can_persist = true;
     $policyOverrides->can_renew = false;
     $template->policy_overrides = $policyOverrides;
     $expected = '{"allowed_track_types":"SD_HD","content_key_specs":[{"track_type":"SD","key_id":null,"security_level":1,"required_output_protection":{"hdcp":"HDCP_NONE"}}],"policy_overrides":{"can_play":true,"can_persist":true,"can_renew":false}}';
     // Test
     $actual = WidevineMessageSerializer::serialize($template);
     // Assert
     $this->assertJsonStringEqualsJsonString($expected, $actual);
 }
 public function testCreateContentKeyAuthorizationPolicyOptionForWidevine()
 {
     // Setup Token
     $widevine = new WidevineMessage();
     $widevine->allowed_track_types = AllowedTrackTypes::SD_HD;
     $contentKeySpecs = new ContentKeySpecs();
     $contentKeySpecs->required_output_protection = new RequiredOutputProtection();
     $contentKeySpecs->required_output_protection->hdcp = Hdcp::HDCP_NONE;
     $contentKeySpecs->security_level = 1;
     $contentKeySpecs->track_type = 'SD';
     $widevine->content_key_specs = array($contentKeySpecs);
     $policyOverrides = new \stdClass();
     $policyOverrides->can_play = true;
     $policyOverrides->can_persist = true;
     $policyOverrides->can_renew = false;
     $widevine->policy_overrides = $policyOverrides;
     $jsonWidevine = WidevineMessageSerializer::serialize($widevine);
     $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::WIDEVINE);
     $options->setKeyDeliveryConfiguration($jsonWidevine);
     $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->assertJsonStringEqualsJsonString($jsonWidevine, $result->getKeyDeliveryConfiguration());
     $actualWidevine = WidevineMessageSerializer::deserialize($result->getKeyDeliveryConfiguration());
     $this->assertEqualsWidevineMessage($widevine, $actualWidevine);
     return $result->getId();
 }
function configureWidevineLicenseTemplate()
{
    $template = new WidevineMessage();
    $template->allowed_track_types = AllowedTrackTypes::SD_HD;
    $contentKeySpecs = new ContentKeySpecs();
    $contentKeySpecs->required_output_protection = new RequiredOutputProtection();
    $contentKeySpecs->required_output_protection->hdcp = Hdcp::HDCP_NONE;
    $contentKeySpecs->security_level = 1;
    $contentKeySpecs->track_type = "SD";
    $template->content_key_specs = array($contentKeySpecs);
    $policyOverrides = new \stdClass();
    $policyOverrides->can_play = true;
    $policyOverrides->can_persist = true;
    $policyOverrides->can_renew = false;
    $template->policy_overrides = $policyOverrides;
    return WidevineMessageSerializer::serialize($template);
}