Merge branch '2015.11-develop' into 2016.11
[tine20] / tests / tine20 / Calendar / performanceTests.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Calendar
6  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
7  * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Cornelius Weiss <c.weiss@metaways.de>
9  */
10
11 /**
12  * Test helper
13  */
14 require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
15
16 if (!defined('PHPUnit_MAIN_METHOD')) {
17     define('PHPUnit_MAIN_METHOD', 'Calendar_performanceTests::main');
18 }
19
20 /**
21  * Test class for Json Frontend
22  * 
23  * @package     Calendar
24  */
25 class Calendar_performanceTests extends PHPUnit_Framework_TestCase
26 {
27     /**
28      * Calendar Json Object
29      *
30      * @var Calendar_Frontend_Json
31      */
32     protected $_json = null;
33     
34     public function setUp()
35     {
36         // invalidate all caches
37         $cache = Tinebase_Core::get(Tinebase_Core::CACHE);
38         if (!$cache || !$cache->getOption('caching')) {
39             return;
40         }
41         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
42         $_db = Tinebase_Core::getDb();
43         if ($_db instanceof Zend_Db_Adapter_Mysql) {
44             $_db->query("RESET QUERY CACHE;");
45         }
46         $this->_json = new Calendar_Frontend_Json();
47     }
48     
49     public function testGetEvent()
50     {
51         $user = Tinebase_User::getInstance()->getFullUsers('')->getFirstRecord();
52         
53         echo "getting month view for {$user->accountDisplayName}\n";
54         $filterData = array(
55             array('field' => 'container_id', 'operator' => 'in', 'value' => array(
56                 '/personal/' . $user->getId(),
57                 '/shared'
58             )),
59             array('field' => 'period', 'operator' => 'within', 'value' => array(
60                 'from'  => '2010-03-01 00:00:00',
61                 'until' => '2010-04-01 00:00:00'
62             )),
63         );
64         $filter = new Calendar_Model_EventFilter($filterData);
65         $eventIds = Calendar_Controller_Event::getInstance()->search($filter, NULL, FALSE, TRUE);
66         
67         foreach ($eventIds as $id) {
68             $time_start = microtime(true);
69             
70             Calendar_Controller_Event::getInstance()->get($id);
71             
72             $time_end = microtime(true);
73             $time = $time_end - $time_start;
74             echo "getting event {$id} took {$time} seconds\n";
75         }
76         
77     }
78     
79     public function testSearchEvents()
80     {
81         $allUsers = Tinebase_User::getInstance()->getFullUsers('');
82
83         xhprof_enable();
84
85         $numSearches = 0;
86         foreach ($allUsers as $user) {
87             if ($numSearches > 5) {
88                 break;
89             }
90             
91             echo "getting month view for {$user->accountDisplayName}\n";
92             $filterData = array(
93                 array('field' => 'container_id', 'operator' => 'in', 'value' => array(
94                     '/personal/' . $user->getId(),
95                     '/shared'
96                 )),
97                 array('field' => 'period', 'operator' => 'within', 'value' => array(
98                     'from'  => '2010-03-01 00:00:00',
99                     'until' => '2010-04-01 00:00:00'
100                 )),
101             );
102             
103 //            $filter = new Calendar_Model_EventFilter($filterData);
104 //            $events = Calendar_Controller_Event::getInstance()->search($filter, NULL, FALSE);
105             
106             $this->_json->searchEvents($filterData, NULL);
107             $numSearches += 1;
108             
109         }
110         $xhprof_data = xhprof_disable();
111         //Tinebase_Core::getDbProfiling();
112
113         $XHPROF_ROOT = '/opt/local/www/php5-xhprof';
114         include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
115         include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
116
117         $xhprof_runs = new XHProfRuns_Default();
118         $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_tine20");
119
120         echo "http://localhost/xhprof_html/index.php?run={$run_id}&source=xhprof_tine20 \n";
121         print_r(Tinebase_Record_Abstract::$cns);
122     }
123     
124     public function _testTasks()
125     {
126         $allUsers = Tinebase_User::getInstance()->getFullUsers('');
127         
128         $numSearches = 0;
129         foreach ($allUsers as $user) {
130             if ($numSearches > 120) {
131                 break;
132             }
133             
134             echo ".";
135             $filterData = array(
136                 array('field' => 'container_id', 'operator' => 'in', 'value' => '/'),
137             );
138             
139             $filter = new Tasks_Model_TaskFilter($filterData);
140             Tasks_Controller_Task::getInstance()->search($filter, NULL, FALSE);
141             //$json = new Tasks_Frontend_Json();
142             //$json->searchTasks($filterData, array());
143             $numSearches += 1;
144         }
145     }
146 }
147     
148
149 if (PHPUnit_MAIN_METHOD == 'Calendar_performanceTests::main') {
150     Calendar_performanceTests::main();
151 }