1
0

ActionTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Notification;
  22. use OC\Notification\Action;
  23. use OCP\Notification\IAction;
  24. use Test\TestCase;
  25. class ActionTest extends TestCase {
  26. /** @var IAction */
  27. protected $action;
  28. public function setUp() {
  29. parent::setUp();
  30. $this->action = new Action();
  31. }
  32. public function dataSetLabel() {
  33. return [
  34. ['test1'],
  35. [str_repeat('a', 1)],
  36. [str_repeat('a', 32)],
  37. ];
  38. }
  39. /**
  40. * @dataProvider dataSetLabel
  41. * @param string $label
  42. */
  43. public function testSetLabel($label) {
  44. $this->assertSame('', $this->action->getLabel());
  45. $this->assertSame($this->action, $this->action->setLabel($label));
  46. $this->assertSame($label, $this->action->getLabel());
  47. }
  48. public function dataSetLabelInvalid() {
  49. return [
  50. [true],
  51. [false],
  52. [0],
  53. [1],
  54. [''],
  55. [str_repeat('a', 33)],
  56. [[]],
  57. [[str_repeat('a', 33)]],
  58. ];
  59. }
  60. /**
  61. * @dataProvider dataSetLabelInvalid
  62. * @param mixed $label
  63. *
  64. * @expectedException \InvalidArgumentException
  65. */
  66. public function testSetLabelInvalid($label) {
  67. $this->action->setLabel($label);
  68. }
  69. public function dataSetParsedLabel() {
  70. return [
  71. ['test1'],
  72. [str_repeat('a', 1)],
  73. [str_repeat('a', 32)],
  74. ];
  75. }
  76. /**
  77. * @dataProvider dataSetParsedLabel
  78. * @param string $label
  79. */
  80. public function testSetParsedLabel($label) {
  81. $this->assertSame('', $this->action->getParsedLabel());
  82. $this->assertSame($this->action, $this->action->setParsedLabel($label));
  83. $this->assertSame($label, $this->action->getParsedLabel());
  84. }
  85. public function dataSetParsedLabelInvalid() {
  86. return [
  87. [true],
  88. [false],
  89. [0],
  90. [1],
  91. [''],
  92. [[]],
  93. [[str_repeat('a', 33)]],
  94. ];
  95. }
  96. /**
  97. * @dataProvider dataSetParsedLabelInvalid
  98. * @param mixed $label
  99. *
  100. * @expectedException \InvalidArgumentException
  101. */
  102. public function testSetParsedLabelInvalid($label) {
  103. $this->action->setParsedLabel($label);
  104. }
  105. public function dataSetLink() {
  106. return [
  107. ['test1', 'GET'],
  108. ['test2', 'POST'],
  109. [str_repeat('a', 1), 'PUT'],
  110. [str_repeat('a', 256), 'DELETE'],
  111. ];
  112. }
  113. /**
  114. * @dataProvider dataSetLink
  115. * @param string $link
  116. * @param string $type
  117. */
  118. public function testSetLink($link, $type) {
  119. $this->assertSame('', $this->action->getLink());
  120. $this->assertSame($this->action, $this->action->setLink($link, $type));
  121. $this->assertSame($link, $this->action->getLink());
  122. $this->assertSame($type, $this->action->getRequestType());
  123. }
  124. public function dataSetLinkInvalid() {
  125. return [
  126. // Invalid link
  127. [true, 'GET'],
  128. [false, 'GET'],
  129. [0, 'GET'],
  130. [1, 'GET'],
  131. ['', 'GET'],
  132. [str_repeat('a', 257), 'GET'],
  133. [[], 'GET'],
  134. [[str_repeat('a', 257)], 'GET'],
  135. // Invalid type
  136. ['url', 'notGET'],
  137. ['url', true],
  138. ['url', false],
  139. ['url', 0],
  140. ['url', 1],
  141. ['url', []],
  142. ['url', ['GET']],
  143. ];
  144. }
  145. /**
  146. * @dataProvider dataSetLinkInvalid
  147. * @param mixed $link
  148. * @param mixed $type
  149. *
  150. * @expectedException \InvalidArgumentException
  151. */
  152. public function testSetLinkInvalid($link, $type) {
  153. $this->action->setLink($link, $type);
  154. }
  155. public function dataSetPrimary() {
  156. return [
  157. [true],
  158. [false],
  159. ];
  160. }
  161. /**
  162. * @dataProvider dataSetPrimary
  163. * @param bool $primary
  164. */
  165. public function testSetPrimary($primary) {
  166. $this->assertSame(false, $this->action->isPrimary());
  167. $this->assertSame($this->action, $this->action->setPrimary($primary));
  168. $this->assertSame($primary, $this->action->isPrimary());
  169. }
  170. public function dataSetPrimaryInvalid() {
  171. return [
  172. [0],
  173. [1],
  174. [''],
  175. [str_repeat('a', 257)],
  176. [[]],
  177. [[str_repeat('a', 257)]],
  178. ];
  179. }
  180. /**
  181. * @dataProvider dataSetPrimaryInvalid
  182. * @param mixed $primary
  183. *
  184. * @expectedException \InvalidArgumentException
  185. */
  186. public function testSetPrimaryInvalid($primary) {
  187. $this->action->setPrimary($primary);
  188. }
  189. public function testIsValid() {
  190. $this->assertFalse($this->action->isValid());
  191. $this->assertFalse($this->action->isValidParsed());
  192. $this->action->setLabel('label');
  193. $this->assertFalse($this->action->isValid());
  194. $this->assertFalse($this->action->isValidParsed());
  195. $this->action->setLink('link', 'GET');
  196. $this->assertTrue($this->action->isValid());
  197. $this->assertFalse($this->action->isValidParsed());
  198. }
  199. public function testIsValidParsed() {
  200. $this->assertFalse($this->action->isValid());
  201. $this->assertFalse($this->action->isValidParsed());
  202. $this->action->setParsedLabel('label');
  203. $this->assertFalse($this->action->isValid());
  204. $this->assertFalse($this->action->isValidParsed());
  205. $this->action->setLink('link', 'GET');
  206. $this->assertFalse($this->action->isValid());
  207. $this->assertTrue($this->action->isValidParsed());
  208. }
  209. }