mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 07:53:39 +01:00
added test app in fixtures
This commit is contained in:
parent
d8d3b5a12b
commit
3ae16b20e6
107
api/tests/Storage/BaseTest.php
Normal file
107
api/tests/Storage/BaseTest.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* EGroupware test app to test eg. Api\Storage\Base
|
||||
*
|
||||
* @package api
|
||||
* @subpackage tests
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @copyright 2017RalfBecker@outdoor-training.de
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use EGroupware\Api;
|
||||
|
||||
class BaseTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Api\Db
|
||||
*/
|
||||
private static $db;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Api\Storage\Base
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (ini_get('session.save_handler') == 'files' && !is_writable(ini_get('session.save_path')) && is_dir('/tmp') && is_writable('/tmp'))
|
||||
{
|
||||
ini_set('session.save_path','/tmp'); // regular users may have no rights to apache's session dir
|
||||
}
|
||||
$_REQUEST['domain'] = $GLOBALS['EGW_DOMAIN'];
|
||||
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'noheader' => True,
|
||||
'nonavbar' => True,
|
||||
'currentapp' => 'setup',
|
||||
'noapi' => true,
|
||||
));
|
||||
require(__DIR__.'/../../../header.inc.php');
|
||||
|
||||
$GLOBALS['egw'] = new stdClass();
|
||||
$GLOBALS['egw']->db = self::$db = new Api\Db($GLOBALS['egw_domain'][$GLOBALS['EGW_DOMAIN']]);
|
||||
self::$db->connect();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->storage = new Api\Storage\Base('test', 'egw_test', self::$db);
|
||||
}
|
||||
|
||||
protected function assertPreConditions()
|
||||
{
|
||||
$tables = self::$db->table_names(true);
|
||||
$this->assertContains('egw_test', $tables);
|
||||
}
|
||||
|
||||
public function testSaveInternalState()
|
||||
{
|
||||
$this->storage->data = $data = array(
|
||||
't_title' => 'Test',
|
||||
't_desc' => "First Line\nSecond Line\n\n...",
|
||||
't_start' => $start=Api\DateTime::to('now', 'ts'),
|
||||
't_end' => $end=Api\DateTime::to('now', 'ts'),
|
||||
't_modifier' => 123,
|
||||
);
|
||||
$this->storage->Save();
|
||||
$this->assertGreaterThan(0, $this->storage->data['t_id']);
|
||||
|
||||
$row = self::$db->select('egw_test', '*', array('t_id' => $this->storage->data['t_id']),
|
||||
__LINE__, __FILE__, false, '', 'test')->fetch();
|
||||
$this->assertInternalType('array', $row);
|
||||
$this->assertEquals($data['t_title'], $row['t_title']);
|
||||
$this->assertEquals($data['t_desc'], $row['t_desc']);
|
||||
$this->assertEquals($data['t_modifier'], $row['t_modifier']);
|
||||
$this->assertEquals(Api\DateTime::user2server($start), $row['t_start']);
|
||||
$this->assertEquals(Api\DateTime::user2server($end, Api\DateTime::DATABASE), $row['t_end']);
|
||||
$this->assertEquals(new DateTime('now'), new DateTime($row['t_modified']), '', 1);
|
||||
|
||||
return $this->storage->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $data
|
||||
* @depends testSaveInternalState
|
||||
*/
|
||||
public function testReadFromDb(array $data)
|
||||
{
|
||||
$read = $this->storage->read($data['t_id']);
|
||||
// not set above, just be DB or read method
|
||||
unset($read['t_modified'], $read['user_timezone_read']);
|
||||
// set as ts, but read as is in DB
|
||||
$data['t_end'] = Api\DateTime::to($data['t_end'], Api\DateTime::DATABASE);
|
||||
$this->assertEquals($data, $read);
|
||||
}
|
||||
|
||||
/*public function testSaveGivenState()
|
||||
{
|
||||
|
||||
}*/
|
||||
}
|
37
api/tests/fixtures/apps/test/setup/setup.inc.php
vendored
Normal file
37
api/tests/fixtures/apps/test/setup/setup.inc.php
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* EGroupware test app to test eg. Api\Storage\Base
|
||||
*
|
||||
* @package api
|
||||
* @subpackage tests
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @copyright 2017RalfBecker@outdoor-training.de
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
*/
|
||||
|
||||
$setup_info['test']['name'] = 'test';
|
||||
$setup_info['test']['version'] = '17.1.001';
|
||||
$setup_info['test']['app_order'] = 5;
|
||||
$setup_info['test']['tables'] = array('egw_test');
|
||||
$setup_info['test']['enable'] = 1;
|
||||
$setup_info['test']['index'] = 'timesheet.timesheet_ui.index&ajax=true';
|
||||
|
||||
$setup_info['test']['author'] =
|
||||
$setup_info['test']['maintainer'] = array(
|
||||
'name' => 'Ralf Becker',
|
||||
'email' => 'rb@egroupware.org',
|
||||
);
|
||||
$setup_info['test']['license'] = 'GPL';
|
||||
$setup_info['test']['description'] = 'Testapp for phpUnit tests';
|
||||
$setup_info['test']['note'] = '';
|
||||
|
||||
/* The hooks this app includes, needed for hooks registration */
|
||||
$setup_info['test']['hooks'] = array();
|
||||
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['test']['depends'][] = array(
|
||||
'appname' => 'api',
|
||||
'versions' => Array('16.1')
|
||||
);
|
||||
|
29
api/tests/fixtures/apps/test/setup/tables_current.inc.php
vendored
Normal file
29
api/tests/fixtures/apps/test/setup/tables_current.inc.php
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare - Setup
|
||||
* http://www.egroupware.org
|
||||
* Created by eTemplates DB-Tools written by ralfbecker@outdoor-training.de
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package api
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
|
||||
$phpgw_baseline = array(
|
||||
'egw_test' => array(
|
||||
'fd' => array(
|
||||
't_id' => array('type' => 'auto','nullable' => False),
|
||||
't_title' => array('type' => 'varchar','precision' => '80'),
|
||||
't_desc' => array('type' => 'varchar','precision' => '16000'),
|
||||
't_modifier' => array('type' => 'int','meta' => 'account','precision' => '4'),
|
||||
't_modified' => array('type' => 'timestamp','meta' => 'timestamp','default' => 'current_timestamp', 'nullable' => false),
|
||||
't_start' => array('type' => 'int','meta' => 'timestamp','precision' => '8'),
|
||||
't_end' => array('type' => 'timestamp','meta' => 'timestamp')
|
||||
),
|
||||
'pk' => array('t_id'),
|
||||
'fk' => array(),
|
||||
'ix' => array('t_modified'),
|
||||
'uc' => array()
|
||||
)
|
||||
);
|
@ -14,6 +14,7 @@
|
||||
<testsuite name="Api">
|
||||
<directory>../api/src/test/</directory>
|
||||
<directory>../api/src/*/test/</directory>
|
||||
<directory>../api/tests</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Etemplate">
|
||||
<file>../api/src/test/EtemplateTest.php</file>
|
||||
@ -23,10 +24,10 @@
|
||||
<testsuite name="Apps">
|
||||
<!-- Apps with test directory -->
|
||||
<directory>../*/test/</directory>
|
||||
|
||||
<!-- Apps with namespace -->
|
||||
<directory>../*/src/test/</directory>
|
||||
<directory>../*/src/*/test/</directory>
|
||||
<directory>../*/tests/</directory>
|
||||
|
||||
<exclude>../api</exclude>
|
||||
</testsuite>
|
||||
|
Loading…
Reference in New Issue
Block a user