Merge pull request #10030 from eileenmcnaughton/test
[civicrm-core.git] / tests / phpunit / api / v3 / ReportTemplateTest.php
index 34904b5ab6cbfa29fd1a9fffd2559b8c618f2a74..3b636b1523a51a33af81d43aa031ce48fff834c0 100644 (file)
@@ -235,6 +235,30 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
     $this->assertEquals(1, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
   }
 
+  /**
+   * Test Lybunt report applies ACLs.
+   */
+  public function testLybuntReportWithDataAndACLFilter() {
+    CRM_Core_Config::singleton()->userPermissionClass->permissions = array('administer CiviCRM');
+    $inInd = $this->individualCreate();
+    $outInd = $this->individualCreate();
+    $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-03-01'));
+    $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL));
+    $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
+    $params = array(
+      'report_id' => 'contribute/lybunt',
+      'yid_value' => 2015,
+      'yid_op' => 'calendar',
+      'options' => array('metadata' => array('sql')),
+      'check_permissions' => 1,
+    );
+
+    $rows = $this->callAPISuccess('report_template', 'getrows', $params);
+    $this->assertEquals(0, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
+
+    CRM_Utils_Hook::singleton()->reset();
+  }
+
   /**
    * Test Lybunt report to check basic inclusion of a contact who gave in the year before the chosen year.
    */
@@ -532,4 +556,62 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
     return array($groupID, $groupID2);
   }
 
+  /**
+   * Test Deferred Revenue Report.
+   */
+  public function testDeferredRevenueReport() {
+    $indv1 = $this->individualCreate();
+    $indv2 = $this->individualCreate();
+    $params = array(
+      'contribution_invoice_settings' => array(
+        'deferred_revenue_enabled' => '1',
+      ),
+    );
+    $this->callAPISuccess('Setting', 'create', $params);
+    $this->contributionCreate(
+      array(
+        'contact_id' => $indv1,
+        'receive_date' => '2016-10-01',
+        'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+3 month')),
+        'financial_type_id' => 2,
+      )
+    );
+    $this->contributionCreate(
+      array(
+        'contact_id' => $indv1,
+        'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+22 month')),
+        'financial_type_id' => 4,
+        'trxn_id' => NULL,
+        'invoice_id' => NULL,
+      )
+    );
+    $this->contributionCreate(
+      array(
+        'contact_id' => $indv2,
+        'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+1 month')),
+        'financial_type_id' => 4,
+        'trxn_id' => NULL,
+        'invoice_id' => NULL,
+      )
+    );
+    $this->contributionCreate(
+      array(
+        'contact_id' => $indv2,
+        'receive_date' => '2016-03-01',
+        'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+4 month')),
+        'financial_type_id' => 2,
+        'trxn_id' => NULL,
+        'invoice_id' => NULL,
+      )
+    );
+    $rows = $this->callAPISuccess('report_template', 'getrows', array(
+      'report_id' => 'contribute/deferredrevenue',
+    ));
+    $this->assertEquals(2, $rows['count'], "Report failed to get row count");
+    $count = array(2, 1);
+    foreach ($rows['values'] as $row) {
+      $this->assertEquals(array_pop($count), count($row['rows']), "Report failed to get row count");
+    }
+  }
+
 }