ActionTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. protected function setUp(): void {
  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. [''],
  51. [str_repeat('a', 33)],
  52. ];
  53. }
  54. /**
  55. * @dataProvider dataSetLabelInvalid
  56. * @param mixed $label
  57. *
  58. */
  59. public function testSetLabelInvalid($label) {
  60. $this->expectException(\InvalidArgumentException::class);
  61. $this->action->setLabel($label);
  62. }
  63. public function dataSetParsedLabel() {
  64. return [
  65. ['test1'],
  66. [str_repeat('a', 1)],
  67. [str_repeat('a', 32)],
  68. ];
  69. }
  70. /**
  71. * @dataProvider dataSetParsedLabel
  72. * @param string $label
  73. */
  74. public function testSetParsedLabel($label) {
  75. $this->assertSame('', $this->action->getParsedLabel());
  76. $this->assertSame($this->action, $this->action->setParsedLabel($label));
  77. $this->assertSame($label, $this->action->getParsedLabel());
  78. }
  79. public function dataSetParsedLabelInvalid() {
  80. return [
  81. [''],
  82. ];
  83. }
  84. /**
  85. * @dataProvider dataSetParsedLabelInvalid
  86. * @param mixed $label
  87. *
  88. */
  89. public function testSetParsedLabelInvalid($label) {
  90. $this->expectException(\InvalidArgumentException::class);
  91. $this->action->setParsedLabel($label);
  92. }
  93. public function dataSetLink() {
  94. return [
  95. ['test1', 'GET'],
  96. ['test2', 'POST'],
  97. [str_repeat('a', 1), 'PUT'],
  98. [str_repeat('a', 256), 'DELETE'],
  99. ];
  100. }
  101. /**
  102. * @dataProvider dataSetLink
  103. * @param string $link
  104. * @param string $type
  105. */
  106. public function testSetLink($link, $type) {
  107. $this->assertSame('', $this->action->getLink());
  108. $this->assertSame($this->action, $this->action->setLink($link, $type));
  109. $this->assertSame($link, $this->action->getLink());
  110. $this->assertSame($type, $this->action->getRequestType());
  111. }
  112. public function dataSetLinkInvalid() {
  113. return [
  114. // Invalid link
  115. ['', 'GET'],
  116. [str_repeat('a', 257), 'GET'],
  117. // Invalid type
  118. ['url', 'notGET'],
  119. ];
  120. }
  121. /**
  122. * @dataProvider dataSetLinkInvalid
  123. * @param mixed $link
  124. * @param mixed $type
  125. *
  126. */
  127. public function testSetLinkInvalid($link, $type) {
  128. $this->expectException(\InvalidArgumentException::class);
  129. $this->action->setLink($link, $type);
  130. }
  131. public function dataSetPrimary() {
  132. return [
  133. [true],
  134. [false],
  135. ];
  136. }
  137. /**
  138. * @dataProvider dataSetPrimary
  139. * @param bool $primary
  140. */
  141. public function testSetPrimary($primary) {
  142. $this->assertSame(false, $this->action->isPrimary());
  143. $this->assertSame($this->action, $this->action->setPrimary($primary));
  144. $this->assertSame($primary, $this->action->isPrimary());
  145. }
  146. public function testIsValid() {
  147. $this->assertFalse($this->action->isValid());
  148. $this->assertFalse($this->action->isValidParsed());
  149. $this->action->setLabel('label');
  150. $this->assertFalse($this->action->isValid());
  151. $this->assertFalse($this->action->isValidParsed());
  152. $this->action->setLink('link', 'GET');
  153. $this->assertTrue($this->action->isValid());
  154. $this->assertFalse($this->action->isValidParsed());
  155. }
  156. public function testIsValidParsed() {
  157. $this->assertFalse($this->action->isValid());
  158. $this->assertFalse($this->action->isValidParsed());
  159. $this->action->setParsedLabel('label');
  160. $this->assertFalse($this->action->isValid());
  161. $this->assertFalse($this->action->isValidParsed());
  162. $this->action->setLink('link', 'GET');
  163. $this->assertFalse($this->action->isValid());
  164. $this->assertTrue($this->action->isValidParsed());
  165. }
  166. }