Add first Inventory unittests
authorMichael Spahn <m.spahn@metaways.de>
Mon, 17 Sep 2012 09:00:14 +0000 (11:00 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Thu, 4 Oct 2012 13:54:57 +0000 (15:54 +0200)
Change-Id: Ieb8db41a23c4d67baa6e23a16e20c4bff5585ebb
Reviewed-on: https://gerrit.tine20.org/tine20/1080
Tested-by: jenkins user
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/AllTests.php
tests/tine20/Inventory/AllTests.php [new file with mode: 0644]
tests/tine20/Inventory/JsonTest.php [new file with mode: 0644]
tests/tine20/Inventory/TestCase.php [new file with mode: 0644]
tine20/Inventory/Setup/setup.xml

index 2a651e2..80fb0ba 100644 (file)
@@ -44,6 +44,7 @@ class AllTests
         $suite->addTest(Filemanager_AllTests::suite());
         $suite->addTest(Projects_AllTests::suite());
         $suite->addTest(HumanResources_AllTests::suite());
+        $suite->addTest(Inventory_AllTests::suite());
         $suite->addTest(Zend_AllTests::suite());
         
         return $suite;
diff --git a/tests/tine20/Inventory/AllTests.php b/tests/tine20/Inventory/AllTests.php
new file mode 100644 (file)
index 0000000..3693c6e
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ * 
+ * @package     Inventory
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ * 
+ */
+
+/**
+ * Test helper
+ */
+require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+class Inventory_AllTests
+{
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+    
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Tine 2.0 Inventory All Tests');
+        
+        $suite->addTestSuite('Inventory_JsonTest');
+        return $suite;
+    }
+}
diff --git a/tests/tine20/Inventory/JsonTest.php b/tests/tine20/Inventory/JsonTest.php
new file mode 100644 (file)
index 0000000..42a3af9
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ * 
+ * @package     Inventory
+ * @subpackage  Record
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ */
+
+/**
+ * Test helper
+ */
+require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+/**
+ * Test class for Inventory_JsonTest
+ */
+class Inventory_JsonTest extends Inventory_TestCase
+{
+    /**
+     * Backend
+     *
+     * @var Inventory_Frontend_Json
+     */
+    public function setUp()
+    {
+        parent::setUp();
+        $this->_json = new Inventory_Frontend_Json();
+    }
+    
+    /**
+     * test creation of a InventoryItem
+     */
+    public function testCreateInventoryItem()
+    {
+        $inventoryItem = $this->_getInventoryItem();
+        
+        $this->assertTrue(is_object($inventoryItem), 'We have no inventory item');
+        
+        $inventoryItemArray = $inventoryItem->toArray();
+        
+        $this->assertTrue(is_array($inventoryItemArray), '$inventoryItemArray is not an array');
+        
+        $returned = $this->_json->saveInventoryItem($inventoryItemArray);
+        
+        $returnedGet = $this->_json->getInventoryItem($returned['id'], 0 , '');
+        $this->assertEquals($inventoryItem['description'], $returnedGet['description']);
+    }
+}
diff --git a/tests/tine20/Inventory/TestCase.php b/tests/tine20/Inventory/TestCase.php
new file mode 100644 (file)
index 0000000..3b6c648
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ *
+ * @package     Inventory
+ * @license     http://www.gnu.org/licenses/agpl.html
+ * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Michael Spahn <m.spahn@metawys.de
+ */
+
+/**
+ * Test helper
+ */
+require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+/**
+ * Test class for Inventory_TestCase
+ */
+class Inventory_TestCase extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Inventory_Frontend_Json
+     */
+    protected $_json = array();
+    
+    /**
+     * Runs the test methods of this class.
+     *
+     * @access public
+     * @static
+     */
+    public static function main()
+    {
+        $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Inventory Json Tests');
+        PHPUnit_TextUI_TestRunner::run($suite);
+    }
+    
+    /**
+     * Sets up the fixture.
+     * This method is called before a test is executed.
+     *
+     * @access protected
+     */
+    protected function setUp()
+    {
+        Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
+    }
+    
+    /**
+     * get InventoryItem record
+     *
+     * @return Inventory_Model_InventoryItem
+     */
+    protected function _getInventoryItem()
+    {
+        return new Inventory_Model_InventoryItem(array(
+                'name'          => 'minimal inventory item by PHPUnit::Inventory_JsonTest',
+                'type'          => '1',
+                'location'      => 'hamburg',
+                'description'   => 'Default description by PHPUnit::Inventory_JsonTest'
+        ));
+    }
+    
+    /**
+     * Tears down the fixture
+     * This method is called after a test is executed.
+     *
+     * @access protected
+     */
+    protected function tearDown()
+    {
+        Tinebase_TransactionManager::getInstance()->rollBack();
+    }
+}
index 1a99459..472353d 100644 (file)
@@ -4,7 +4,7 @@
     <!-- gettext('Inventory') -->   
     <version>0.2</version>
     <order>60</order>
-    <status>disabled</status>
+    <status>enabled</status>
     <tables>
         <table>
             <name>inventory_item</name>