0010182: Sales test coupled with Tinebase
authorFlávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
Thu, 28 Aug 2014 19:11:58 +0000 (16:11 -0300)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 29 Aug 2014 20:59:56 +0000 (22:59 +0200)
 - Create new test for Sales
 - Remove test for Sales from Tinebase

Change-Id: Ia1ae4b3ff27ffdcad9190e6456620ac7bfc33edd
Reviewed-on: https://gerrit.tine20.org/tine20/2865
Tested-by: jenkins user
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Sales/AllTests.php
tests/tine20/Sales/CustomFieldTest.php [new file with mode: 0644]
tests/tine20/Tinebase/CustomFieldTest.php

index b7a7ad8..76e3b7f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Tine 2.0 - http://www.tine20.org
- * 
+ *
  * @package     Sales
  * @license     http://www.gnu.org/licenses/agpl.html
  * @copyright   Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de)
@@ -32,6 +32,7 @@ class Sales_AllTests
         $suite->addTestSuite('Sales_Backend_CostCenterTest');
         $suite->addTestSuite('Sales_ControllerTest');
         $suite->addTestSuite('Sales_JsonTest');
+        $suite->addTestSuite('Sales_CustomFieldTest');
         return $suite;
     }
 }
diff --git a/tests/tine20/Sales/CustomFieldTest.php b/tests/tine20/Sales/CustomFieldTest.php
new file mode 100644 (file)
index 0000000..61ab4fc
--- /dev/null
@@ -0,0 +1,198 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ *
+ * @package     Tinebase
+ * @license     http://www.gnu.org/licenses/agpl.html
+ * @copyright   Copyright (c) 2009-2013 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2014 Serpro (http://www.serpro.gov.br)
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ */
+
+/**
+ * Test helper
+ */
+require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+/**
+ * Test class for Tinebase_CustomField
+ */
+class Sales_CustomFieldTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * unit under test (UIT)
+     * @var Tinebase_CustomField
+     */
+    protected $_instance;
+
+    /**
+     * transaction id if test is wrapped in an transaction
+     */
+    protected $_transactionId = NULL;
+    
+    protected $_user = NULL;
+    
+    /**
+     * Runs the test methods of this class.
+     *
+     * @access public
+     * @static
+     */
+    public static function main()
+    {
+        $suite  = new PHPUnit_Framework_TestSuite('Sales_CustomFieldTest');
+        PHPUnit_TextUI_TestRunner::run($suite);
+    }
+
+    /**
+     * Sets up the fixture.
+     * This method is called before a test is executed.
+     *
+     * @access protected
+     */
+    protected function setUp()
+    {
+        $this->_transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
+        $this->_instance = Tinebase_CustomField::getInstance();
+    }
+
+    /**
+     * Tears down the fixture
+     * This method is called after a test is executed.
+     *
+     * @access protected
+     */
+    protected function tearDown()
+    {
+        if ($this->_transactionId) {
+            Tinebase_TransactionManager::getInstance()->rollBack();
+        }
+        
+        if ($this->_user) {
+            Tinebase_Core::set(Tinebase_Core::USER, $this->_user);
+        }
+    }
+    
+    /**
+     * get custom field record
+     *
+     * @param array $config
+     * @return Tinebase_Model_CustomField_Config
+     */
+    public static function getCustomField($config = array())
+    {
+        return new Tinebase_Model_CustomField_Config(array_replace_recursive(array(
+                'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId(),
+                'name'              => Tinebase_Record_Abstract::generateUID(),
+                'model'             => Tinebase_Record_Abstract::generateUID(),
+                'definition'        => array(
+                        'label' => Tinebase_Record_Abstract::generateUID(),
+                        'type'  => 'string',
+                        'uiconfig' => array(
+                                'xtype'  => Tinebase_Record_Abstract::generateUID(),
+                                'length' => 10,
+                                'group'  => 'unittest',
+                                'order'  => 100,
+                        )
+                )
+        ), $config));
+    }
+    
+    /**
+     * test searching records by record as a customfield type
+     * https://forge.tine20.org/mantisbt/view.php?id=6730
+     */
+    public function testSearchByRecord()
+    {
+        $cf = self::getCustomField(array(
+            'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(),
+            'model' => 'Addressbook_Model_Contact',
+            'definition' => array('type' => 'record', "recordConfig" => array("value" => array("records" => "Tine.Sales.Model.Contract")))
+        ));
+        $this->_instance->addCustomField($cf);
+        
+        $contract = Sales_Controller_Contract::getInstance()->create(
+            new Sales_Model_Contract(
+                array(
+                    'number' => Tinebase_Record_Abstract::generateUID(10),
+                    'title' => Tinebase_Record_Abstract::generateUID(10),
+                    'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId()
+                )
+            )
+        );
+        
+        // contact1 with customfield record = contract
+        $contact1 = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein'));
+        $contact1->customfields = array($cf->name => $contract->getId());
+        $contact1 = Addressbook_Controller_Contact::getInstance()->create($contact1, false);
+        
+        // contact2 with customfield record is not set -> should act like without this record
+        $contact2 = new Addressbook_Model_Contact(array('n_given' => 'Rainer', 'n_family' => 'Blütenrein'));
+        $contact2 = Addressbook_Controller_Contact::getInstance()->create($contact2, false);
+        
+        $json = new Addressbook_Frontend_Json();
+        
+        $result = $json->searchContacts(array(
+            array("condition" => "OR",
+                "filters" => array(array("condition" => "AND",
+                    "filters" => array(
+                        array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())),
+                    )
+                ))
+            )
+        ), array());
+        
+        $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record = contract (Rita Blütenrein)');
+        $this->assertEquals('Rita', $result['results'][0]['n_given'], 'The Record should be Rita Blütenrein');
+        
+        $result = $json->searchContacts(array(
+            array("condition" => "OR",
+                "filters" => array(array("condition" => "AND",
+                    "filters" => array(
+                        array("field" => "customfield", "operator" => "not", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())),
+                        array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')
+                    )
+                ))
+            )
+        ), array());
+        
+        $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record is not set (Rainer Blütenrein)');
+        $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
+        
+        // search using the same cf filter in an or - filter
+        
+        $contract2 = Sales_Controller_Contract::getInstance()->create(
+            new Sales_Model_Contract(
+                array(
+                    'number' => Tinebase_Record_Abstract::generateUID(10),
+                    'title' => Tinebase_Record_Abstract::generateUID(10),
+                    'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId()
+                )
+            )
+        );
+        $contact2->customfields = array($cf->name => $contract2->getId());
+        $contact2 = Addressbook_Controller_Contact::getInstance()->update($contact2, false);
+        
+        $result = $json->searchContacts(array(
+            array("condition" => "OR",
+                "filters" => array(
+                    array("condition" => "AND",
+                        "filters" => array(
+                            array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())),
+                        )
+                    ),
+                    array("condition" => "AND",
+                        "filters" => array(
+                            array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract2->getId())),
+                        )
+                    )
+                )
+            )
+        ), array());
+        
+        $this->assertEquals(2, $result['totalcount'], 'Rainer and Rita should have been found.');
+        
+        $this->assertEquals('Blütenrein', $result['results'][0]['n_family'], 'Rainer and Rita should have been found.');
+        $this->assertEquals('Blütenrein', $result['results'][1]['n_family'], 'Rainer and Rita should have been found.');
+    }
+}
\ No newline at end of file
index 9c392ba..9560f87 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Tine 2.0 - http://www.tine20.org
- * 
+ *
  * @package     Tinebase
  * @license     http://www.gnu.org/licenses/agpl.html
  * @copyright   Copyright (c) 2009-2013 Metaways Infosystems GmbH (http://www.metaways.de)
@@ -96,7 +96,7 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
     
     /**
      * test add customfield to the same record by multiple update
-     * 
+     *
      * @see #7330: https://forge.tine20.org/mantisbt/view.php?id=7330
      * @see 0007350: multipleUpdate - record not found
      */
@@ -198,7 +198,7 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
     
     /**
      * testAddressbookCustomFieldAcl
-     * 
+     *
      * @see 0007630: Customfield read access to all users
      */
     public function testAddressbookCustomFieldAcl()
@@ -240,11 +240,11 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
         $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId());
         $this->assertEquals(array($anotherCustomField->name => 'test value 2'), $contact->customfields, 'cf should be hidden: ' . print_r($contact->customfields, TRUE));
     }
-    
+
     /**
      * get custom field record
      *
-     * @param array $config 
+     * @param array $config
      * @return Tinebase_Model_CustomField_Config
      */
     public static function getCustomField($config = array())
@@ -262,7 +262,7 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
                     'group'  => 'unittest',
                     'order'  => 100,
                 )
-            )  
+            )
         ), $config));
     }
     
@@ -283,7 +283,7 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
         $json = new Addressbook_Frontend_Json();
         $result = $json->searchContacts(array(
             array("condition" => "OR",
-                "filters" => array(array("condition" => "AND", 
+                "filters" => array(array("condition" => "AND",
                     "filters" => array(
                         array("field" => "customfield", "operator" => "within", "value" => array("cfId" => $cf->getId(), "value" => "weekThis")),
                         )
@@ -325,7 +325,7 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
         $json = new Addressbook_Frontend_Json();
         $result = $json->searchContacts(array(
             array("condition" => "OR",
-                "filters" => array(array("condition" => "AND", 
+                "filters" => array(array("condition" => "AND",
                     "filters" => array(
                         array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => true)),
                         array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')
@@ -340,7 +340,7 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
         
         $result = $json->searchContacts(array(
             array("condition" => "OR",
-                "filters" => array(array("condition" => "AND", 
+                "filters" => array(array("condition" => "AND",
                     "filters" => array(
                         array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => false)),
                         array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')
@@ -352,102 +352,4 @@ class Tinebase_CustomFieldTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-bool is not set (Rainer Blütenrein)');
         $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
     }
-    
-    /**
-     * test searching records by record as a customfield type
-     * https://forge.tine20.org/mantisbt/view.php?id=6730
-     */
-    public function testSearchByRecord()
-    {
-        $cf = self::getCustomField(array(
-            'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(),
-            'model' => 'Addressbook_Model_Contact',
-            'definition' => array('type' => 'record', "recordConfig" => array("value" => array("records" => "Tine.Sales.Model.Contract")))
-        ));
-        $this->_instance->addCustomField($cf);
-        
-        $contract = Sales_Controller_Contract::getInstance()->create(
-            new Sales_Model_Contract(
-                array(
-                    'number' => Tinebase_Record_Abstract::generateUID(10),
-                    'title' => Tinebase_Record_Abstract::generateUID(10),
-                    'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId()
-                )
-            )
-        );
-        
-        // contact1 with customfield record = contract
-        $contact1 = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein'));
-        $contact1->customfields = array($cf->name => $contract->getId());
-        $contact1 = Addressbook_Controller_Contact::getInstance()->create($contact1, false);
-        
-        // contact2 with customfield record is not set -> should act like without this record
-        $contact2 = new Addressbook_Model_Contact(array('n_given' => 'Rainer', 'n_family' => 'Blütenrein'));
-        $contact2 = Addressbook_Controller_Contact::getInstance()->create($contact2, false);
-        
-        $json = new Addressbook_Frontend_Json();
-        
-        $result = $json->searchContacts(array(
-            array("condition" => "OR",
-                "filters" => array(array("condition" => "AND", 
-                    "filters" => array(
-                        array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())),
-                    )
-                ))
-            )
-        ), array());
-        
-        $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record = contract (Rita Blütenrein)');
-        $this->assertEquals('Rita', $result['results'][0]['n_given'], 'The Record should be Rita Blütenrein');
-        
-        $result = $json->searchContacts(array(
-            array("condition" => "OR",
-                "filters" => array(array("condition" => "AND", 
-                    "filters" => array(
-                        array("field" => "customfield", "operator" => "not", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())),
-                        array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')
-                    )
-                ))
-            )
-        ), array());
-        
-        $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record is not set (Rainer Blütenrein)');
-        $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
-        
-        // search using the same cf filter in an or - filter
-        
-        $contract2 = Sales_Controller_Contract::getInstance()->create(
-            new Sales_Model_Contract(
-                array(
-                    'number' => Tinebase_Record_Abstract::generateUID(10),
-                    'title' => Tinebase_Record_Abstract::generateUID(10),
-                    'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId()
-                )
-            )
-        );
-        $contact2->customfields = array($cf->name => $contract2->getId());
-        $contact2 = Addressbook_Controller_Contact::getInstance()->update($contact2, false);
-        
-        $result = $json->searchContacts(array(
-            array("condition" => "OR",
-                "filters" => array(
-                    array("condition" => "AND", 
-                        "filters" => array(
-                            array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())),
-                        )
-                    ),
-                    array("condition" => "AND", 
-                        "filters" => array(
-                            array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract2->getId())),
-                        )
-                    )
-                )
-            )
-        ), array());
-        
-        $this->assertEquals(2, $result['totalcount'], 'Rainer and Rita should have been found.');
-        
-        $this->assertEquals('Blütenrein', $result['results'][0]['n_family'], 'Rainer and Rita should have been found.');
-        $this->assertEquals('Blütenrein', $result['results'][1]['n_family'], 'Rainer and Rita should have been found.');
-    }
-}
+}
\ No newline at end of file