Refactor tests to avoid deprecated assertions

This commit is contained in:
nathangray 2020-03-10 15:53:26 -06:00
parent d1ff8e9f07
commit d4b9397d62
7 changed files with 102 additions and 55 deletions

View File

@ -237,7 +237,12 @@ class UserCommandTest extends CommandBase {
// Changing primary group does not remove membership of previous
$this->assertEquals($pre_groups + array($this->group_id => $group['account_lid']), $post_groups);
$this->assertArraySubset($this->account, $GLOBALS['egw']->accounts->read($this->account_id));
$read_account = $GLOBALS['egw']->accounts->read($this->account_id);
foreach ($this->account as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $read_account);
$this->assertEquals($check_value, $read_account[$check_key]);
}
}
/**
@ -282,6 +287,11 @@ class UserCommandTest extends CommandBase {
$this->assertEquals($pre_group, $post_group);
$this->assertEquals($pre_groups + array($this->group_id => $group['account_lid']), $post_groups);
$this->assertArraySubset($this->account, $GLOBALS['egw']->accounts->read($this->account_id));
$read_account = $GLOBALS['egw']->accounts->read($this->account_id);
foreach ($this->account as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $read_account);
$this->assertEquals($check_value, $read_account[$check_key]);
}
}
}

View File

@ -104,18 +104,30 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
// Check for the load
$data = array();
foreach($result as $command)
foreach ($result as $command)
{
if($command['type'] == 'et2_load')
if ($command['type'] == 'et2_load')
{
$data = $command['data'];
break;
}
}
$this->assertArraySubset($this->content, $data['data']['content'], false, 'Content does not match');
$this->assertArraySubset($this->sel_options, $data['data']['sel_options'], false, 'Select options do not match');
$this->assertArraySubset($this->readonlys, $data['data']['readonlys'], false, 'Readonlys does not match');
foreach ($this->content as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $data['data']['content'], 'Content does not match');
$this->assertEquals($check_value, $data['data']['content'][$check_key], 'Content does not match');
}
foreach ($this->sel_options as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $data['data']['sel_options'], 'Select options does not match');
$this->assertEquals($check_value, $data['data']['sel_options'][$check_key], 'Select options does not match');
}
foreach ($this->readonlys as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $data['data']['readonlys'], 'Readonlys does not match');
$this->assertEquals($check_value, $data['data']['readonlys'][$check_key], 'Readonlys does not match');
}
}
/**
@ -188,8 +200,16 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
$result2 = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys, $preserve);
// The only input widget is readonly, expect preserve + content back
$this->assertArraySubset($this->content, $result2);
$this->assertArraySubset($preserve, $result2);
foreach ($this->content as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $result2, 'Content does not match');
$this->assertEquals($check_value, $result2[$check_key], 'Content does not match');
}
foreach ($preserve as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $result2, 'Preserve does not match');
$this->assertEquals($check_value, $result2[$check_key], 'Preserve does not match');
}
}
/**

View File

@ -10,8 +10,8 @@
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/
use PHPUnit\Framework\TestCase;
use EGroupware\Api;
use PHPUnit\Framework\TestCase;
class BaseTest extends TestCase
{
@ -65,8 +65,8 @@ class BaseTest extends TestCase
$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_start' => $start = Api\DateTime::to('now', 'ts'),
't_end' => $end = Api\DateTime::to('now', 'ts'),
't_modifier' => 123,
);
$this->storage->Save();
@ -74,13 +74,13 @@ class BaseTest extends TestCase
$row = self::$db->select('egw_test', '*', array('t_id' => $this->storage->data['t_id']),
__LINE__, __FILE__, false, '', 'test')->fetch();
$this->assertInternalType('array', $row);
$this->assertIsArray($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);
$this->assertEqualsWithDelta(new DateTime('now'), new DateTime($row['t_modified']), 1);
return $this->storage->data;
}

View File

@ -12,7 +12,6 @@
namespace EGroupware\Api\Storage;
use EGroupware\Api;
use EGroupware\Api\LoggedInTest as LoggedInTest;
class CustomfieldsTest extends LoggedInTest
@ -180,10 +179,10 @@ class CustomfieldsTest extends LoggedInTest
public function testGetOptionsFromGoodFile($expected, $file)
{
// Load
$options = Customfields::get_options_from_file('api/tests/fixtures/Storage/'.$file);
$options = Customfields::get_options_from_file('api/tests/fixtures/Storage/' . $file);
// Check
$this->assertInternalType('array', $options);
$this->assertIsArray($options);
$this->assertEquals($expected, $options);
}
@ -237,7 +236,7 @@ class CustomfieldsTest extends LoggedInTest
public function testGetOptionsFromMissingFile()
{
$options = Customfields::get_options_from_file('totally invalid');
$this->assertInternalType('array', $options);
$this->assertIsArray($options);
$this->assertCount(1, $options);
}

View File

@ -14,6 +14,9 @@ use EGroupware\Api\Link;
*/
class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
{
protected $debug = false;
// List of extra customizations to check
protected $customizations = array();
@ -73,8 +76,11 @@ class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
// We got this far, there should be elements
$this->assertGreaterThan(0, count($this->elements), "No project elements created");
if ($this->debug)
{
echo __METHOD__ . " Created test elements: \n";
print_r($this->elements);
}
// Force links to run notification now, or we won't get elements since it
// usually waits until Egw::on_shutdown();
@ -131,16 +137,23 @@ class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
$indexed_elements = array();
$unmatched_elements = $this->elements;
if ($this->debug)
{
echo "\n" . __METHOD__ . "\n";
echo "Checking on (copied) PM ID $clone_id\n";
}
$elements = $element_bo->search(array('pm_id' => $clone_id), false, 'pe_id ASC');
// Expect 1 sub-project, 2 infologs
$this->assertIsArray($elements, "Did not find any project elements in copy");
$this->assertCount(3, $elements, "Incorrect number of project elements");
foreach ($elements as $element)
{
if ($this->debug)
{
echo "\tPM:" . $element['pm_id'] . ' ' . $element['pe_id'] . "\t" . $element['pe_app'] . ':' . $element['pe_app_id'] . "\t" . $element['pe_title'] . "\n" . Link::title($element['pe_app'], $element['pe_app_id']) . "\n";
}
$indexed_elements[$element['pe_app']][] = $element;
}
foreach ($this->elements as $key => $_id)
@ -156,7 +169,10 @@ class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
$copied = array_shift($indexed_elements[$app]);
if ($this->debug)
{
echo "$_id:\tCopied element - PM:" . $copied['pm_id'] . ' ' . $copied['pe_app'] . ':' . $copied['pe_app_id'] . "\t" . $copied['pe_title'] . "\n";
}
$this->assertNotNull($copied, "$app entry $_id did not get copied");

View File

@ -6,8 +6,8 @@ namespace EGroupware\Infolog;
require_once realpath(__DIR__.'/../../api/tests/AppTest.php'); // Application test base
use Egroupware\Api;
use Egroupware\Api\Link;
use Egroupware\Api\Etemplate;
use Egroupware\Api\Link;
/**
* Test setting a project manager project on an infolog entry
@ -130,15 +130,15 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
->method('track')
->withConsecutive(
// First call - creation
[$this->callback(function($subject) { return is_null($subject['pm_status']);})],
[$this->callback(function ($subject) { return is_null($subject['pm_status']); })],
// Second call - after setting project
[$this->callback(function($subject) { return $subject['pm_id'] == $this->pm_id;})]
[$this->callback(function ($subject) { return $subject['pm_id'] == $this->pm_id; })]
);
$info = $this->getTestInfolog();
$this->info_id = $this->bo->write($info);
$this->assertInternalType('integer', $this->info_id);
$this->assertIsInt($this->info_id);
$this->assertGreaterThan(0, $this->info_id);
// Force links to run notification now so we get valid testing - it
@ -177,15 +177,15 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
->method('track')
->withConsecutive(
// First call - creation
[$this->callback(function($subject) { return is_null($subject['pm_status']);})],
[$this->callback(function ($subject) { return is_null($subject['pm_status']); })],
// Second call - after setting project
[$this->callback(function($subject) { return $subject['pm_id'] == $this->pm_id;})]
[$this->callback(function ($subject) { return $subject['pm_id'] == $this->pm_id; })]
);
$info = $this->getTestInfolog();
$this->info_id = $this->bo->write($info);
$this->assertInternalType('integer', $this->info_id);
$this->assertIsInt($this->info_id);
$this->assertGreaterThan(0, $this->info_id);
// Force links to run notification now so we get valid testing - it
@ -288,10 +288,12 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
$this->assertEquals($this->pm_id, $info['pm_id'], 'Project went missing');
// Check that infolog still has contact
$this->assertArraySubset(
array('app' => 'addressbook', 'id' =>$GLOBALS['egw_info']['user']['person_id']),
$info['info_contact']
);
$keys = array('app' => 'addressbook', 'id' => $GLOBALS['egw_info']['user']['person_id']);
foreach ($keys as $check_key => $check_value)
{
$this->assertArrayHasKey($check_key, $info['info_contact'], 'Infolog lost contact');
$this->assertEquals($check_value, $info['info_contact'][$check_key], 'Infolog lost contact');
}
// Force links to run notification now so we get valid testing - it
// usually waits until Egw::on_shutdown();

View File

@ -51,23 +51,23 @@ class SaveToVfsTest extends \PHPUnit\Framework\TestCase
{
$cleaned = VfsTestMail::clean_subject_for_filename($filename);
$this->assertNotContains('<', $cleaned);
$this->assertNotContains('>', $cleaned);
$this->assertNotContains('"', $cleaned);
$this->assertNotContains('#', $cleaned);
$this->assertNotContains(':', $cleaned);
$this->assertNotContains('|', $cleaned);
$this->assertNotContains('\\', $cleaned);
$this->assertNotContains('*', $cleaned);
$this->assertNotContains('/', $cleaned);
$this->assertNotContains('?', $cleaned);
$this->assertNotContains('\x0b', $cleaned);
$this->assertNotContains('😂', $cleaned);
$this->assertStringNotContainsString('<', $cleaned);
$this->assertStringNotContainsString('>', $cleaned);
$this->assertStringNotContainsString('"', $cleaned);
$this->assertStringNotContainsString('#', $cleaned);
$this->assertStringNotContainsString(':', $cleaned);
$this->assertStringNotContainsString('|', $cleaned);
$this->assertStringNotContainsString('\\', $cleaned);
$this->assertStringNotContainsString('*', $cleaned);
$this->assertStringNotContainsString('/', $cleaned);
$this->assertStringNotContainsString('?', $cleaned);
$this->assertStringNotContainsString('\x0b', $cleaned);
$this->assertStringNotContainsString('😂', $cleaned);
// Check if the filename is not empty
$this->assertGreaterThan(0, strlen($cleaned), 'File name is empty');
if(!$replacements)
if (!$replacements)
{
$this->assertEquals($filename, $cleaned);
}