RequestUserAgentTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\WorkflowEngine\Tests\Check;
  7. use OCA\WorkflowEngine\Check\RequestUserAgent;
  8. use OCP\IL10N;
  9. use OCP\IRequest;
  10. use Test\TestCase;
  11. class RequestUserAgentTest extends TestCase {
  12. /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
  13. protected $request;
  14. /** @var RequestUserAgent */
  15. protected $check;
  16. protected function setUp(): void {
  17. parent::setUp();
  18. $this->request = $this->createMock(IRequest::class);
  19. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l */
  20. $l = $this->getMockBuilder(IL10N::class)
  21. ->disableOriginalConstructor()
  22. ->getMock();
  23. $l->expects($this->any())
  24. ->method('t')
  25. ->willReturnCallback(function ($string, $args) {
  26. return sprintf($string, $args);
  27. });
  28. $this->check = new RequestUserAgent($l, $this->request);
  29. }
  30. public function dataExecuteCheck() {
  31. return [
  32. ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  33. ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  34. ['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  35. ['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  36. ['is', 'android', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  37. ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  38. ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  39. ['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  40. ['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  41. ['!is', 'android', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  42. ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  43. ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  44. ['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  45. ['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  46. ['is', 'ios', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  47. ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  48. ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  49. ['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  50. ['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  51. ['!is', 'ios', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  52. ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  53. ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  54. ['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  55. ['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  56. ['is', 'desktop', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  57. ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  58. ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  59. ['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  60. ['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  61. ['!is', 'desktop', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  62. ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
  63. ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
  64. ['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
  65. ['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
  66. ['is', 'mail', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
  67. ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
  68. ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
  69. ['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
  70. ['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
  71. ['!is', 'mail', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
  72. ];
  73. }
  74. /**
  75. * @dataProvider dataExecuteCheck
  76. * @param string $operation
  77. * @param string $checkValue
  78. * @param string $actualValue
  79. * @param bool $expected
  80. */
  81. public function testExecuteCheck($operation, $checkValue, $actualValue, $expected): void {
  82. $this->request->expects($this->once())
  83. ->method('getHeader')
  84. ->willReturn($actualValue);
  85. /** @var \OCA\WorkflowEngine\Check\AbstractStringCheck $check */
  86. $this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue));
  87. }
  88. }