1
0

RequestUserAgentTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\WorkflowEngine\Tests\Check;
  27. use OCA\WorkflowEngine\Check\RequestUserAgent;
  28. use OCP\IL10N;
  29. use OCP\IRequest;
  30. use Test\TestCase;
  31. class RequestUserAgentTest extends TestCase {
  32. /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
  33. protected $request;
  34. /** @var RequestUserAgent */
  35. protected $check;
  36. protected function setUp(): void {
  37. parent::setUp();
  38. $this->request = $this->createMock(IRequest::class);
  39. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l */
  40. $l = $this->getMockBuilder(IL10N::class)
  41. ->disableOriginalConstructor()
  42. ->getMock();
  43. $l->expects($this->any())
  44. ->method('t')
  45. ->willReturnCallback(function ($string, $args) {
  46. return sprintf($string, $args);
  47. });
  48. $this->check = new RequestUserAgent($l, $this->request);
  49. }
  50. public function dataExecuteCheck() {
  51. return [
  52. ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  53. ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  54. ['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  55. ['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  56. ['is', 'android', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  57. ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  58. ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  59. ['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  60. ['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  61. ['!is', 'android', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  62. ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  63. ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  64. ['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  65. ['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  66. ['is', 'ios', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  67. ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  68. ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  69. ['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  70. ['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  71. ['!is', 'ios', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  72. ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  73. ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  74. ['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  75. ['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  76. ['is', 'desktop', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  77. ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  78. ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  79. ['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  80. ['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  81. ['!is', 'desktop', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  82. ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  83. ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  84. ['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  85. ['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  86. ['is', 'mail', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  87. ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  88. ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  89. ['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  90. ['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  91. ['!is', 'mail', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  92. ];
  93. }
  94. /**
  95. * @dataProvider dataExecuteCheck
  96. * @param string $operation
  97. * @param string $checkValue
  98. * @param string $actualValue
  99. * @param bool $expected
  100. */
  101. public function testExecuteCheck($operation, $checkValue, $actualValue, $expected) {
  102. $this->request->expects($this->once())
  103. ->method('getHeader')
  104. ->willReturn($actualValue);
  105. /** @var \OCA\WorkflowEngine\Check\AbstractStringCheck $check */
  106. $this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue));
  107. }
  108. }