/tests/unit/WindowsAzure/Common/Internal/Atom/CategoryTest.php

https://bitbucket.org/skudatech/azure-sdk-for-php · PHP · 459 lines · 214 code · 80 blank · 165 comment · 0 complexity · 76e818e1f0e8f2ec06552179f02b0cbc 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. * @package Tests\Unit\WindowsAzure\Common\Internal\Atom
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/WindowsAzure/azure-sdk-for-php
  22. */
  23. namespace Tests\Unit\WindowsAzure\Common\Internal\Atom;
  24. use WindowsAzure\Common\Internal\Atom\Category;
  25. /**
  26. * Unit tests for class Category.
  27. *
  28. * @category Microsoft
  29. * @package Tests\Unit\WindowsAzure\Common\Internal\Atom
  30. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  31. * @copyright 2012 Microsoft Corporation
  32. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  33. * @version Release: @package_version@
  34. * @link https://github.com/WindowsAzure/azure-sdk-for-php
  35. */
  36. class CategoryTest extends \PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * @covers WindowsAzure\Common\Internal\Atom\Category::__construct
  40. */
  41. public function testCategoryConstructor()
  42. {
  43. // Setup
  44. // Test
  45. $category = new Category();
  46. // Assert
  47. $this->assertNotNull($category);
  48. }
  49. /**
  50. * @covers WindowsAzure\Common\Internal\Atom\Category::__construct
  51. */
  52. public function testCategoryConstructorWithParameterSuccess()
  53. {
  54. // Setup
  55. $expectedUndefinedContent = 'testCategoryConstructorWithParameterSuccess';
  56. // Test
  57. $category = new Category($expectedUndefinedContent);
  58. $actualUndefinedContent = $category->getUndefinedContent();
  59. // Assert
  60. $this->assertEquals(
  61. $expectedUndefinedContent,
  62. $actualUndefinedContent
  63. );
  64. }
  65. /**
  66. * @covers WindowsAzure\Common\Internal\Atom\Category::getTerm
  67. * @covers WindowsAzure\Common\Internal\Atom\Category::setTerm
  68. */
  69. public function testCategoryGetSetTerm()
  70. {
  71. // Setup
  72. $expectedTerm = 'testCategoryGetSetTerm';
  73. $category = new Category();
  74. // Test
  75. $category->setTerm($expectedTerm);
  76. $actualTerm = $category->getTerm();
  77. // Assert
  78. $this->assertEquals(
  79. $expectedTerm,
  80. $actualTerm
  81. );
  82. }
  83. /**
  84. * @covers WindowsAzure\Common\Internal\Atom\Category::getScheme
  85. * @covers WindowsAzure\Common\Internal\Atom\Category::setScheme
  86. */
  87. public function testCategoryGetSetScheme()
  88. {
  89. // Setup
  90. $expectedScheme = 'testCategoryGetSetScheme';
  91. $category = new Category();
  92. // Test
  93. $category->setScheme($expectedScheme);
  94. $actualScheme = $category->getScheme();
  95. // Assert
  96. $this->assertEquals(
  97. $expectedScheme,
  98. $actualScheme
  99. );
  100. }
  101. /**
  102. * @covers WindowsAzure\Common\Internal\Atom\Category::getLabel
  103. * @covers WindowsAzure\Common\Internal\Atom\Category::setLabel
  104. */
  105. public function testCategoryGetSetLabel()
  106. {
  107. // Setup
  108. $expectedLabel = 'testCategoryGetSetLabel';
  109. $category = new Category();
  110. // Test
  111. $category->setLabel($expectedLabel);
  112. $actualLabel = $category->getLabel();
  113. // Assert
  114. $this->assertEquals(
  115. $expectedLabel,
  116. $actualLabel
  117. );
  118. }
  119. /**
  120. * @covers WindowsAzure\Common\Internal\Atom\Category::getUndefinedContent
  121. * @covers WindowsAzure\Common\Internal\Atom\Category::setUndefinedContent
  122. */
  123. public function testCategoryGetSetUndefinedContent()
  124. {
  125. // Setup
  126. $expectedUndefinedContent = 'testCategoryGetSetUndefinedContent';
  127. $category = new Category();
  128. // Test
  129. $category->setUndefinedContent($expectedUndefinedContent);
  130. $actualUndefinedContent = $category->getUndefinedContent();
  131. // Assert
  132. $this->assertEquals(
  133. $expectedUndefinedContent,
  134. $actualUndefinedContent
  135. );
  136. }
  137. /**
  138. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  139. */
  140. public function testCategoryCreate()
  141. {
  142. // Setup
  143. $xml = '<category/>';
  144. // Test
  145. $category = new Category();
  146. $category->parseXml($xml);
  147. // Assert
  148. $this->assertNotNull($category);
  149. }
  150. /**
  151. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  152. * @covers WindowsAzure\Common\Internal\Atom\Category::getTerm
  153. */
  154. public function testCategoryCreateWithTerm()
  155. {
  156. // Setup
  157. $xml = '<category term="testTerm"></category>';
  158. $expected = 'testTerm';
  159. // Test
  160. $category = new Category();
  161. $category->parseXml($xml);
  162. $actual = $category->getTerm();
  163. // Assert
  164. $this->assertEquals(
  165. $expected,
  166. $actual
  167. );
  168. }
  169. /**
  170. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  171. * @covers WindowsAzure\Common\Internal\Atom\Category::getScheme
  172. */
  173. public function testCategoryCreateWithScheme()
  174. {
  175. // Setup
  176. $xml = '<category scheme="testScheme"></category>';
  177. $expected = 'testScheme';
  178. // Test
  179. $category = new Category();
  180. $category->parseXml($xml);
  181. $actual = $category->getScheme();
  182. // Assert
  183. $this->assertEquals(
  184. $expected,
  185. $actual
  186. );
  187. }
  188. /**
  189. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  190. * @covers WindowsAzure\Common\Internal\Atom\Category::getLabel
  191. */
  192. public function testCategoryCreateWithLabel()
  193. {
  194. // Setup
  195. $xml = '<category label="testLabel"></category>';
  196. $expected = 'testLabel';
  197. // Test
  198. $category = new Category();
  199. $category->parseXml($xml);
  200. $actual = $category->getLabel();
  201. // Assert
  202. $this->assertEquals(
  203. $expected,
  204. $actual
  205. );
  206. }
  207. /**
  208. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  209. * @covers WindowsAzure\Common\Internal\Atom\Category::writeXml
  210. */
  211. public function testCategoryWriteEmptyXml()
  212. {
  213. // Setup
  214. $category = new Category();
  215. $expected = '<atom:category xmlns:atom="http://www.w3.org/2005/Atom"/>';
  216. // Test
  217. $xmlWriter = new \XMLWriter();
  218. $xmlWriter->openMemory();
  219. $category->writeXml($xmlWriter);
  220. $actual = $xmlWriter->outputMemory();
  221. // Assert
  222. $this->assertEquals(
  223. $expected,
  224. $actual
  225. );
  226. }
  227. /**
  228. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  229. * @covers WindowsAzure\Common\Internal\Atom\Category::writeXml
  230. */
  231. public function testCategoryWriteXmlSuccess()
  232. {
  233. // Setup
  234. $category = new Category();
  235. $expected = '<atom:category term="testTerm" scheme="testScheme" label="testLabel" xmlns:atom="http://www.w3.org/2005/Atom"/>';
  236. $category->setTerm('testTerm');
  237. $category->setScheme('testScheme');
  238. $category->setLabel('testLabel');
  239. // Test
  240. $xmlWriter = new \XMLWriter();
  241. $xmlWriter->openMemory();
  242. $category->writeXml($xmlWriter);
  243. $actual = $xmlWriter->outputMemory();
  244. // Assert
  245. $this->assertEquals(
  246. $expected,
  247. $actual
  248. );
  249. }
  250. /**
  251. * @covers WindowsAzure\Common\Internal\Atom\Category::getTerm
  252. * @covers WindowsAzure\Common\Internal\Atom\Category::setTerm
  253. */
  254. public function testGetSetTerm() {
  255. // Setup
  256. $expected = 'testTerm';
  257. $category = new Category();
  258. // Test
  259. $category->setTerm($expected);
  260. $actual = $category->getTerm();
  261. // Assert
  262. $this->assertEquals(
  263. $expected,
  264. $actual
  265. );
  266. }
  267. /**
  268. * @covers WindowsAzure\Common\Internal\Atom\Category::getScheme
  269. * @covers WindowsAzure\Common\Internal\Atom\Category::setScheme
  270. */
  271. public function testGetSetScheme() {
  272. // Setup
  273. $expected = 'testScheme';
  274. $category = new Category();
  275. // Test
  276. $category->setScheme($expected);
  277. $actual = $category->getScheme();
  278. // Assert
  279. $this->assertEquals(
  280. $expected,
  281. $actual
  282. );
  283. }
  284. /**
  285. * @covers WindowsAzure\Common\Internal\Atom\Category::getLabel
  286. * @covers WindowsAzure\Common\Internal\Atom\Category::setLabel
  287. */
  288. public function testGetSetLabel() {
  289. // Setup
  290. $expected = 'testLabel';
  291. $category = new Category();
  292. // Test
  293. $category->setLabel($expected);
  294. $actual = $category->getLabel();
  295. // Assert
  296. $this->assertEquals(
  297. $expected,
  298. $actual
  299. );
  300. }
  301. /**
  302. * @covers WindowsAzure\Common\Internal\Atom\Category::getUndefinedContent
  303. * @covers WindowsAzure\Common\Internal\Atom\Category::setUndefinedContent
  304. */
  305. public function testGetSetUndefinedContent() {
  306. // Setup
  307. $expected = 'testUndefinedContent';
  308. $category = new Category();
  309. // Test
  310. $category->setUndefinedContent($expected);
  311. $actual = $category->getUndefinedContent();
  312. // Assert
  313. $this->assertEquals(
  314. $expected,
  315. $actual
  316. );
  317. }
  318. /**
  319. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  320. */
  321. public function testCategoryParseXmlSuccess() {
  322. // Setup
  323. $expected = new Category();
  324. $xml = '<category/>';
  325. $actual = new Category();
  326. // Test
  327. $actual->parseXml($xml);
  328. // Assert
  329. $this->assertEquals(
  330. $expected,
  331. $actual
  332. );
  333. }
  334. /**
  335. * @covers WindowsAzure\Common\Internal\Atom\Category::parseXml
  336. */
  337. public function testCategoryParseXmlInvlalidParameter() {
  338. // Setup
  339. $actual = new Category();
  340. $this->setExpectedException(get_class(new \InvalidArgumentException()));
  341. // Test
  342. $actual->parseXml(null);
  343. // Assert
  344. }
  345. /**
  346. * @covers WindowsAzure\Common\Internal\Atom\Category::writeXml
  347. */
  348. public function testCategoryWriteXmlSuccessAllProperties() {
  349. // Setup
  350. $category = new Category();
  351. $category->setTerm('testTerm');
  352. $category->setScheme('testScheme');
  353. $category->setLabel('testLabel');
  354. $category->setUndefinedContent('testUndefinedContent');
  355. $actual = new Category();
  356. $xmlWriter = new \XMLWriter();
  357. $xmlWriter->openMemory();
  358. $expected = '<atom:category term="testTerm" scheme="testScheme" label="testLabel" xmlns:atom="http://www.w3.org/2005/Atom">testUndefinedContent</atom:category>';
  359. // Test
  360. $category->writeXml($xmlWriter);
  361. $actual = $xmlWriter->outputMemory();
  362. // Assert
  363. $this->assertEquals(
  364. $expected,
  365. $actual
  366. );
  367. }
  368. /**
  369. * @covers WindowsAzure\Common\Internal\Atom\Category::writeXml
  370. */
  371. public function testCategoryWriteXmlInvalidParameter() {
  372. // Setup
  373. $this->setExpectedException(get_class(new \InvalidArgumentException()));
  374. $category = new Category();
  375. // Test
  376. $category->writeXml(null);
  377. // Assert
  378. }
  379. }