1
0

ManagerTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  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
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace OCA\WorkflowEngine\Tests;
  22. use OCA\WorkflowEngine\Manager;
  23. use OCP\IDBConnection;
  24. use OCP\IL10N;
  25. use OCP\IServerContainer;
  26. use Test\TestCase;
  27. /**
  28. * Class ManagerTest
  29. *
  30. * @package OCA\WorkflowEngine\Tests
  31. * @group DB
  32. */
  33. class ManagerTest extends TestCase {
  34. /** @var Manager */
  35. protected $manager;
  36. /** @var IDBConnection */
  37. protected $db;
  38. protected function setUp() {
  39. parent::setUp();
  40. $this->db = \OC::$server->getDatabaseConnection();
  41. $container = $this->createMock(IServerContainer::class);
  42. $l = $this->createMock(IL10N::class);
  43. $l->method('t')
  44. ->will($this->returnCallback(function($text, $parameters = []) {
  45. return vsprintf($text, $parameters);
  46. }));
  47. $this->manager = new Manager(
  48. \OC::$server->getDatabaseConnection(),
  49. $container,
  50. $l
  51. );
  52. $this->clearChecks();
  53. }
  54. protected function tearDown() {
  55. $this->clearChecks();
  56. parent::tearDown();
  57. }
  58. public function clearChecks() {
  59. $query = $this->db->getQueryBuilder();
  60. $query->delete('flow_checks')
  61. ->execute();
  62. }
  63. public function testChecks() {
  64. $check1 = $this->invokePrivate($this->manager, 'addCheck', ['Test', 'equal', 1]);
  65. $check2 = $this->invokePrivate($this->manager, 'addCheck', ['Test', '!equal', 2]);
  66. $data = $this->manager->getChecks([$check1]);
  67. $this->assertArrayHasKey($check1, $data);
  68. $this->assertArrayNotHasKey($check2, $data);
  69. $data = $this->manager->getChecks([$check1, $check2]);
  70. $this->assertArrayHasKey($check1, $data);
  71. $this->assertArrayHasKey($check2, $data);
  72. $data = $this->manager->getChecks([$check2, $check1]);
  73. $this->assertArrayHasKey($check1, $data);
  74. $this->assertArrayHasKey($check2, $data);
  75. $data = $this->manager->getChecks([$check2]);
  76. $this->assertArrayNotHasKey($check1, $data);
  77. $this->assertArrayHasKey($check2, $data);
  78. }
  79. }