Merge pull request #231 from pratik-joshi/CRM-12170
[civicrm-core.git] / tests / phpunit / api / v3 / ReportTemplateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31 /**
32 * Test APIv3 civicrm_report_instance_* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Report
36 */
37
38 class api_v3_ReportTemplateTest extends CiviUnitTestCase {
39 protected $_apiversion;
40 public $_eNoticeCompliant = TRUE;
41 function setUp() {
42 $this->_apiversion = 3;
43 parent::setUp();
44 }
45
46 function tearDown() {}
47
48 public function testReportTemplate() {
49 $result = civicrm_api('ReportTemplate', 'create', array(
50 'version' => $this->_apiversion,
51 'label' => 'Example Form',
52 'description' => 'Longish description of the example form',
53 'class_name' => 'CRM_Report_Form_Examplez',
54 'report_url' => 'example/path',
55 'component' => 'CiviCase',
56 ));
57 $this->assertAPISuccess($result);
58 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
59 $entityId = $result['id'];
60 $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__);
61 $this->assertEquals(7, $result['values'][$entityId]['component_id'], 'In line ' . __LINE__);
62 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
63 WHERE name = "CRM_Report_Form_Examplez"
64 AND option_group_id = 40 ');
65 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
66 WHERE name = "CRM_Report_Form_Examplez"');
67
68 // change component to null
69 $result = civicrm_api('ReportTemplate', 'create', array(
70 'version' => $this->_apiversion,
71 'id' => $entityId,
72 'component' => '',
73 ));
74 $this->assertAPISuccess($result);
75 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
76 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
77 WHERE name = "CRM_Report_Form_Examplez"
78 AND option_group_id = 40');
79 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
80 WHERE name = "CRM_Report_Form_Examplez"
81 AND component_id IS NULL');
82
83 // deactivate
84 $result = civicrm_api('ReportTemplate', 'create', array(
85 'version' => $this->_apiversion,
86 'id' => $entityId,
87 'is_active' => 0,
88 ));
89 $this->assertAPISuccess($result);
90 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
91 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
92 WHERE name = "CRM_Report_Form_Examplez"
93 AND option_group_id = 40');
94 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
95 WHERE name = "CRM_Report_Form_Examplez"');
96
97 // activate
98 $result = civicrm_api('ReportTemplate', 'create', array(
99 'version' => $this->_apiversion,
100 'id' => $entityId,
101 'is_active' => 1,
102 ));
103 $this->assertAPISuccess($result);
104 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
105 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
106 WHERE name = "CRM_Report_Form_Examplez"
107 AND option_group_id = 40');
108 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
109 WHERE name = "CRM_Report_Form_Examplez"');
110
111 $result = civicrm_api('ReportTemplate', 'delete', array(
112 'version' => $this->_apiversion,
113 'id' => $entityId,
114 ));
115 $this->assertAPISuccess($result);
116 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
117 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
118 WHERE name = "CRM_Report_Form_Examplez"
119 ');
120 }
121 }