PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/unit/WindowsAzure/MediaServices/Models/LocatorTest.php

http://github.com/WindowsAzure/azure-sdk-for-php
PHP | 317 lines | 154 code | 50 blank | 113 comment | 0 complexity | f76a9290aba4e9c42d119ea5ade41d7f MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0.
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. *
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. *
  22. * @link https://github.com/windowsazure/azure-sdk-for-php
  23. */
  24. namespace Tests\unit\WindowsAzure\MediaServices\Models;
  25. use WindowsAzure\MediaServices\Models\Locator;
  26. use PHPUnit\Framework\TestCase;
  27. /**
  28. * Represents access policy object used in media services.
  29. *
  30. * @category Microsoft
  31. *
  32. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  33. * @copyright Microsoft Corporation
  34. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  35. *
  36. * @version Release: 0.5.0_2016-11
  37. *
  38. * @link https://github.com/windowsazure/azure-sdk-for-php
  39. */
  40. class LocatorTest extends TestCase
  41. {
  42. /**
  43. * @covers \WindowsAzure\MediaServices\Models\Locator::__construct
  44. */
  45. public function test__construct()
  46. {
  47. // Setup
  48. $assetId = 'uifygid75';
  49. $accessId = 'ljhsdfl45';
  50. $type = Locator::TYPE_NONE;
  51. // Test
  52. $result = new Locator($assetId, $accessId, $type);
  53. // Assert
  54. $this->assertEquals($assetId, $result->getAssetId());
  55. $this->assertEquals($accessId, $result->getAccessPolicyId());
  56. $this->assertEquals($type, $result->getType());
  57. }
  58. /**
  59. * @covers \WindowsAzure\MediaServices\Models\Locator::getStartTime
  60. * @covers \WindowsAzure\MediaServices\Models\Locator::setStartTime
  61. */
  62. public function testGetStartTime()
  63. {
  64. // Setup
  65. $assetId = 'uifygid75';
  66. $accessId = 'ljhsdfl45';
  67. $type = Locator::TYPE_NONE;
  68. $locator = new Locator($assetId, $accessId, $type);
  69. $start = new \Datetime('2013-11-14');
  70. $locator->setStartTime($start);
  71. // Test
  72. $actual = $locator->getStartTime();
  73. // Assert
  74. $this->assertEquals($start->getTimestamp(), $actual->getTimestamp());
  75. }
  76. /**
  77. * @covers \WindowsAzure\MediaServices\Models\Locator::getAssetId
  78. */
  79. public function testGetAssetId()
  80. {
  81. // Setup
  82. $assetId = 'uifygid75';
  83. $accessId = 'ljhsdfl45';
  84. $type = Locator::TYPE_NONE;
  85. $locator = new Locator($assetId, $accessId, $type);
  86. // Test
  87. $actual = $locator->getAssetId();
  88. // Assert
  89. $this->assertEquals($assetId, $actual);
  90. }
  91. /**
  92. * @covers \WindowsAzure\MediaServices\Models\Locator::getAccessPolicyId
  93. */
  94. public function testGetAccessPolicyId()
  95. {
  96. // Setup
  97. $assetId = 'uifygid75';
  98. $accessId = 'ljhsdfl45';
  99. $type = Locator::TYPE_NONE;
  100. $locator = new Locator($assetId, $accessId, $type);
  101. // Test
  102. $actual = $locator->getAccessPolicyId();
  103. // Assert
  104. $this->assertEquals($accessId, $actual);
  105. }
  106. /**
  107. * @covers \WindowsAzure\MediaServices\Models\Locator::getContentAccessComponent
  108. */
  109. public function testGetContentAccessComponent()
  110. {
  111. // Setup
  112. $locatorArray = [
  113. 'Type' => Locator::TYPE_NONE,
  114. 'ContentAccessComponent' => 'AccessComponent',
  115. 'AccessPolicyId' => 'ljhsdfl45',
  116. 'AssetId' => 'uifygid75',
  117. ];
  118. $result = Locator::createFromOptions($locatorArray);
  119. // Test
  120. $result = $result->getContentAccessComponent();
  121. // Assert
  122. $this->assertEquals($locatorArray['ContentAccessComponent'], $result);
  123. }
  124. /**
  125. * @covers \WindowsAzure\MediaServices\Models\Locator::getBaseUri
  126. */
  127. public function testGetBaseUri()
  128. {
  129. // Setup
  130. $locatorArray = [
  131. 'Type' => Locator::TYPE_NONE,
  132. 'BaseUri' => 'http://someurl.com/uysfdu56y',
  133. 'AccessPolicyId' => 'ljhsdfl45',
  134. 'AssetId' => 'uifygid75',
  135. ];
  136. $result = Locator::createFromOptions($locatorArray);
  137. // Test
  138. $result = $result->getBaseUri();
  139. // Assert
  140. $this->assertEquals($locatorArray['BaseUri'], $result);
  141. }
  142. /**
  143. * @covers \WindowsAzure\MediaServices\Models\Locator::getPath
  144. */
  145. public function testGetPath()
  146. {
  147. // Setup
  148. $locatorArray = [
  149. 'Type' => Locator::TYPE_NONE,
  150. 'Path' => 'http://someurl.com/uysfdu56y',
  151. 'AccessPolicyId' => 'ljhsdfl45',
  152. 'AssetId' => 'uifygid75',
  153. ];
  154. $result = Locator::createFromOptions($locatorArray);
  155. // Test
  156. $result = $result->getPath();
  157. // Assert
  158. $this->assertEquals($locatorArray['Path'], $result);
  159. }
  160. /**
  161. * @covers \WindowsAzure\MediaServices\Models\Locator::getType
  162. * @covers \WindowsAzure\MediaServices\Models\Locator::setType
  163. */
  164. public function testGetType()
  165. {
  166. // Setup
  167. $assetId = 'uifygid75';
  168. $accessId = 'ljhsdfl45';
  169. $type = Locator::TYPE_NONE;
  170. $locator = new Locator($assetId, $accessId, Locator::TYPE_NONE);
  171. $type = Locator::TYPE_SAS;
  172. $locator->setType($type);
  173. // Test
  174. $actual = $locator->getType();
  175. // Assert
  176. $this->assertEquals($type, $actual);
  177. }
  178. /**
  179. * @covers \WindowsAzure\MediaServices\Models\Locator::getExpirationDateTime
  180. * @covers \WindowsAzure\MediaServices\Models\Locator::setExpirationDateTime
  181. */
  182. public function testGetExpirationDateTime()
  183. {
  184. // Setup
  185. $assetId = 'uifygid75';
  186. $accessId = 'ljhsdfl45';
  187. $type = Locator::TYPE_NONE;
  188. $locator = new Locator($assetId, $accessId, Locator::TYPE_NONE);
  189. $date = new \Datetime('2013-12-30');
  190. $locator->setExpirationDateTime($date);
  191. // Test
  192. $actual = $locator->getExpirationDateTime();
  193. // Assert
  194. $this->assertEquals($date->getTimestamp(), $actual->getTimestamp());
  195. }
  196. /**
  197. * @covers \WindowsAzure\MediaServices\Models\Locator::getName
  198. * @covers \WindowsAzure\MediaServices\Models\Locator::setName
  199. */
  200. public function testGetName()
  201. {
  202. // Setup
  203. $assetId = 'uifygid75';
  204. $accessId = 'ljhsdfl45';
  205. $type = Locator::TYPE_NONE;
  206. $locator = new Locator($assetId, $accessId, $type);
  207. $name = 'nameName';
  208. $locator->setName($name);
  209. // Test
  210. $actual = $locator->getName();
  211. // Assert
  212. $this->assertEquals($name, $actual);
  213. }
  214. /**
  215. * @covers \WindowsAzure\MediaServices\Models\Locator::getId
  216. * @covers \WindowsAzure\MediaServices\Models\Locator::setId
  217. */
  218. public function testGetId()
  219. {
  220. // Setup
  221. $assetId = 'uifygid75';
  222. $accessId = 'ljhsdfl45';
  223. $type = Locator::TYPE_NONE;
  224. $locator = new Locator($assetId, $accessId, $type);
  225. $id = 'NameID';
  226. $locator->setId($id);
  227. // Test
  228. $actual = $locator->getId();
  229. // Assert
  230. $this->assertEquals($id, $actual);
  231. }
  232. /**
  233. * @covers \WindowsAzure\MediaServices\Models\Locator::createFromOptions
  234. * @covers \WindowsAzure\MediaServices\Models\Locator::fromArray
  235. */
  236. public function testLocatorFromOptions()
  237. {
  238. // Setup
  239. $locatorArray = [
  240. 'Id' => 'kjshfs89',
  241. 'Name' => 'newLocator',
  242. 'ExpirationDateTime' => '2013-11-30',
  243. 'Type' => Locator::TYPE_NONE,
  244. 'Path' => 'http://someurl.com/gdkf76r',
  245. 'BaseUri' => 'http://someurl.com/uysfdu56y',
  246. 'ContentAccessComponent' => 'AccessComponent',
  247. 'AccessPolicyId' => 'uifygid75',
  248. 'AssetId' => 'ljhsdfl45',
  249. 'StartTime' => '2013-11-19',
  250. ];
  251. $expiration = new \Datetime($locatorArray['ExpirationDateTime']);
  252. $start = new \Datetime($locatorArray['StartTime']);
  253. // Test
  254. $resultLocator = Locator::createFromOptions($locatorArray);
  255. // Assert
  256. $this->assertEquals($locatorArray['Id'], $resultLocator->getId());
  257. $this->assertEquals($locatorArray['Name'], $resultLocator->getName());
  258. $this->assertEquals($expiration->getTimestamp(), $resultLocator->getExpirationDateTime()->getTimestamp());
  259. $this->assertEquals($locatorArray['Type'], $resultLocator->getType());
  260. $this->assertEquals($locatorArray['Path'], $resultLocator->getPath());
  261. $this->assertEquals($locatorArray['BaseUri'], $resultLocator->getBaseUri());
  262. $this->assertEquals($locatorArray['ContentAccessComponent'], $resultLocator->getContentAccessComponent());
  263. $this->assertEquals($locatorArray['AccessPolicyId'], $resultLocator->getAccessPolicyId());
  264. $this->assertEquals($locatorArray['AssetId'], $resultLocator->getAssetId());
  265. $this->assertEquals($start->getTimestamp(), $resultLocator->getStartTime()->getTimestamp());
  266. }
  267. }