/**
  * @covers WindowsAzure\MediaServices\Templates\PlayReadyLicenseResponseTemplate::getResponseCustomData
  * @covers WindowsAzure\MediaServices\Templates\PlayReadyLicenseResponseTemplate::setResponseCustomData
  */
 public function testGetSetResponseCustomData()
 {
     // Setup
     $entity = new PlayReadyLicenseResponseTemplate();
     $payload = "custom data";
     // Test
     $entity->setResponseCustomData($payload);
     $result = $entity->getResponseCustomData();
     // Assert
     $this->assertEquals($payload, $result);
 }
 private function getPlayReadyTemplate()
 {
     $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 ContentEncryptionKeyFromHeader());
     $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);
     return $template;
 }
 /**
  * @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);
 }
function configurePlayReadyLicenseTemplate()
{
    // The following code configures PlayReady License Template using PHP classes
    // and returns the XML string.
    //The PlayReadyLicenseResponseTemplate class represents the template for the response sent back to the end user.
    //It contains a field for a custom data string between the license server and the application
    //(may be useful for custom app logic) as well as a list of one or more license templates.
    $responseTemplate = new PlayReadyLicenseResponseTemplate();
    // The PlayReadyLicenseTemplate class represents a license template for creating PlayReady licenses
    // to be returned to the end users.
    //It contains the data on the content key in the license and any rights or restrictions to be
    //enforced by the PlayReady DRM runtime when using the content key.
    $licenseTemplate = new PlayReadyLicenseTemplate();
    //Configure whether the license is persistent (saved in persistent storage on the client)
    //or non-persistent (only held in memory while the player is using the license).
    $licenseTemplate->setLicenseType(PlayReadyLicenseType::NON_PERSISTENT);
    // AllowTestDevices controls whether test devices can use the license or not.
    // If true, the MinimumSecurityLevel property of the license
    // is set to 150.  If false (the default), the MinimumSecurityLevel property of the license is set to 2000.
    $licenseTemplate->setAllowTestDevices(true);
    // You can also configure the Play Right in the PlayReady license by using the PlayReadyPlayRight class.
    // It grants the user the ability to playback the content subject to the zero or more restrictions
    // configured in the license and on the PlayRight itself (for playback specific policy).
    // Much of the policy on the PlayRight has to do with output restrictions
    // which control the types of outputs that the content can be played over and
    // any restrictions that must be put in place when using a given output.
    // For example, if the DigitalVideoOnlyContentRestriction is enabled,
    //then the DRM runtime will only allow the video to be displayed over digital outputs
    //(analog video outputs won’t be allowed to pass the content).
    //IMPORTANT: These types of restrictions can be very powerful but can also affect the consumer experience.
    // If the output protections are configured too restrictive,
    // the content might be unplayable on some clients. For more information, see the PlayReady Compliance Rules document.
    // For example:
    //$licenseTemplate->getPlayRight()->setAgcAndColorStripeRestriction(new AgcAndColorStripeRestriction(1));
    $responseTemplate->setLicenseTemplates(array($licenseTemplate));
    return MediaServicesLicenseTemplateSerializer::serialize($responseTemplate);
}
 /**
  * @param PlayReadyLicenseResponseTemplate $template
  */
 private static function ValidateLicenseResponseTemplate($template)
 {
     // Validate the PlayReadyLicenseResponseTemplate has at least one license
     if (count($template->getLicenseTemplates()) <= 0) {
         throw new \RuntimeException(ErrorMessages::AT_LEAST_ONE_LICENSE_TEMPLATE_REQUIRED);
     }
     foreach ($template->getLicenseTemplates() as $license) {
         // This is actually enforced in the DataContract with the IsRequired attribute
         // so this check should never fail.
         if ($license->getContentKey() == null) {
             throw new \RuntimeException(ErrorMessages::PLAY_READY_CONTENT_KEY_REQUIRED);
         }
         // A PlayReady license must have at least one Right in it.  Today we only
         // support the PlayRight so it is required.  In the future we might support
         // other types of rights (CopyRight, perhaps an extensible Right, whatever)
         // so we enforce this in code and not in the DataContract itself.
         if ($license->getPlayRight() == null) {
             throw new \RuntimeException(ErrorMessages::PLAY_READY_PLAY_RIGHT_REQUIRED);
         }
         //  Per the PlayReady Compliance rules (section 3.8 - Output Control for Unknown Outputs), passing content to
         //  unknown output is prohibited if the DigitalVideoOnlyContentRestriction is enabled.
         if ($license->getPlayRight()->getDigitalVideoOnlyContentRestriction()) {
             if ($license->getPlayRight()->getAllowPassingVideoContentToUnknownOutput() == UnknownOutputPassingOption::ALLOWED || $license->getPlayRight()->getAllowPassingVideoContentToUnknownOutput() == UnknownOutputPassingOption::ALLOWED_WITH_VIDEO_CONSTRICTION) {
                 throw new \RuntimeException(ErrorMessages::DIGITAL_VIDEO_ONLY_MUTUALLY_EXCLUSIVE_WITH_PASSING_TO_UNKNOWN_OUTPUT_ERROR);
             }
         }
         //  License template should not have both BeginDate and RelativeBeginDate set.
         //  Only one of these two values should be set.
         if ($license->getBeginDate() != null && $license->getRelativeBeginDate() != null) {
             throw new \RuntimeException(ErrorMessages::BEGIN_DATE_AND_RELATIVE_BEGIN_DATE_CANNOTBE_SET_SIMULTANEOUSLY_ERROR);
         }
         //  License template should not have both ExpirationDate and RelativeExpirationDate set.
         //  Only one of these two values should be set.
         if ($license->getExpirationDate() != null && $license->getRelativeExpirationDate() != null) {
             throw new \RuntimeException(ErrorMessages::EXPIRATION_DATE_AND_RELATIVE_EXPIRATION_DATE_CANNOTBE_SET_SIMULTANEOUSLY_ERROR);
         }
         if ($license->getLicenseType() == PlayReadyLicenseType::NON_PERSISTENT) {
             //  The PlayReady Rights Manager SDK will return an error if you try to specify a license
             //  that is non-persistent and has a first play expiration set.  The event log message related
             //  to the error will say "LicenseGenerationFailure: FirstPlayExpiration can not be set on Non
             //  Persistent license PlayRight."
             if ($license->getPlayRight()->getFirstPlayExpiration() != null) {
                 throw new \RuntimeException(ErrorMessages::FIRST_PLAY_EXPIRATION_CANNOT_BE_SET_ON_NON_PERSISTENT_LICENSE);
             }
             //  The PlayReady Rights Manager SDK will return an error if you try to specify a license
             //  that is non-persistent and has a GracePeriod set.
             if ($license->getGracePeriod() != null) {
                 throw new \RuntimeException(ErrorMessages::GRACE_PERIOD_CANNOT_BE_SET_ON_NON_PERSISTENT_LICENSE);
             }
             //  The PlayReady Rights Manager SDK will return an error if you try to specify a license
             //  that is non-persistent and has a GracePeriod set.  The event log message related
             //  to the error will say "LicenseGenerationFailure: BeginDate or ExpirationDate should not be set
             //  on Non Persistent licenses"
             if ($license->getBeginDate() != null) {
                 throw new \RuntimeException(ErrorMessages::BEGIN_DATE_CANNOT_BE_SET_ON_NON_PERSISTENT_LICENSE);
             }
             //  The PlayReady Rights Manager SDK will return an error if you try to specify a license
             //  that is non-persistent and has a GracePeriod set.  The event log message related
             //  to the error will say "LicenseGenerationFailure: BeginDate or ExpirationDate should not be set
             //  on Non Persistent licenses"
             if ($license->getExpirationDate() != null) {
                 throw new \RuntimeException(ErrorMessages::EXPIRATION_CANNOT_BE_SET_ON_NON_PERSISTENT_LICENSE);
             }
         }
     }
     return true;
 }