Merge pull request #19936 from jmcclelland/only-include-completed
[civicrm-core.git] / tests / phpunit / api / v4 / Traits / OptionCleanupTrait.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19 namespace api\v4\Traits;
20
21 trait OptionCleanupTrait {
22
23 /**
24 * @var int
25 */
26 protected $optionGroupMaxId;
27
28 /**
29 * @var int
30 */
31 protected $optionValueMaxId;
32
33 public function setUp(): void {
34 $this->optionGroupMaxId = \CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_option_group');
35 $this->optionValueMaxId = \CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_option_value');
36 }
37
38 public function tearDown(): void {
39 if ($this->optionValueMaxId) {
40 \CRM_Core_DAO::executeQuery('DELETE FROM civicrm_option_value WHERE id > ' . $this->optionValueMaxId);
41 }
42 if ($this->optionGroupMaxId) {
43 \CRM_Core_DAO::executeQuery('DELETE FROM civicrm_option_group WHERE id > ' . $this->optionGroupMaxId);
44 }
45 }
46
47 }