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 // Changing primary group does not remove membership of previous
$this->assertEquals($pre_groups + array($this->group_id => $group['account_lid']), $post_groups); $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_group, $post_group);
$this->assertEquals($pre_groups + array($this->group_id => $group['account_lid']), $post_groups); $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

@ -113,9 +113,21 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
} }
} }
$this->assertArraySubset($this->content, $data['data']['content'], false, 'Content does not match'); foreach ($this->content as $check_key => $check_value)
$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'); $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); $result2 = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys, $preserve);
// The only input widget is readonly, expect preserve + content back // The only input widget is readonly, expect preserve + content back
$this->assertArraySubset($this->content, $result2); foreach ($this->content as $check_key => $check_value)
$this->assertArraySubset($preserve, $result2); {
$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 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/ */
use PHPUnit\Framework\TestCase;
use EGroupware\Api; use EGroupware\Api;
use PHPUnit\Framework\TestCase;
class BaseTest extends TestCase class BaseTest extends TestCase
{ {
@ -74,13 +74,13 @@ class BaseTest extends TestCase
$row = self::$db->select('egw_test', '*', array('t_id' => $this->storage->data['t_id']), $row = self::$db->select('egw_test', '*', array('t_id' => $this->storage->data['t_id']),
__LINE__, __FILE__, false, '', 'test')->fetch(); __LINE__, __FILE__, false, '', 'test')->fetch();
$this->assertInternalType('array', $row); $this->assertIsArray($row);
$this->assertEquals($data['t_title'], $row['t_title']); $this->assertEquals($data['t_title'], $row['t_title']);
$this->assertEquals($data['t_desc'], $row['t_desc']); $this->assertEquals($data['t_desc'], $row['t_desc']);
$this->assertEquals($data['t_modifier'], $row['t_modifier']); $this->assertEquals($data['t_modifier'], $row['t_modifier']);
$this->assertEquals(Api\DateTime::user2server($start), $row['t_start']); $this->assertEquals(Api\DateTime::user2server($start), $row['t_start']);
$this->assertEquals(Api\DateTime::user2server($end, Api\DateTime::DATABASE), $row['t_end']); $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; return $this->storage->data;
} }

View File

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

View File

@ -14,6 +14,9 @@ use EGroupware\Api\Link;
*/ */
class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
{ {
protected $debug = false;
// List of extra customizations to check // List of extra customizations to check
protected $customizations = array(); protected $customizations = array();
@ -73,8 +76,11 @@ class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
// We got this far, there should be elements // We got this far, there should be elements
$this->assertGreaterThan(0, count($this->elements), "No project elements created"); $this->assertGreaterThan(0, count($this->elements), "No project elements created");
if ($this->debug)
{
echo __METHOD__ . " Created test elements: \n"; echo __METHOD__ . " Created test elements: \n";
print_r($this->elements); print_r($this->elements);
}
// Force links to run notification now, or we won't get elements since it // Force links to run notification now, or we won't get elements since it
// usually waits until Egw::on_shutdown(); // usually waits until Egw::on_shutdown();
@ -131,16 +137,23 @@ class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
$indexed_elements = array(); $indexed_elements = array();
$unmatched_elements = $this->elements; $unmatched_elements = $this->elements;
if ($this->debug)
{
echo "\n" . __METHOD__ . "\n"; echo "\n" . __METHOD__ . "\n";
echo "Checking on (copied) PM ID $clone_id\n"; echo "Checking on (copied) PM ID $clone_id\n";
}
$elements = $element_bo->search(array('pm_id' => $clone_id), false, 'pe_id ASC'); $elements = $element_bo->search(array('pm_id' => $clone_id), false, 'pe_id ASC');
// Expect 1 sub-project, 2 infologs // Expect 1 sub-project, 2 infologs
$this->assertIsArray($elements, "Did not find any project elements in copy"); $this->assertIsArray($elements, "Did not find any project elements in copy");
$this->assertCount(3, $elements, "Incorrect number of project elements"); $this->assertCount(3, $elements, "Incorrect number of project elements");
foreach ($elements as $element) 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"; 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; $indexed_elements[$element['pe_app']][] = $element;
} }
foreach ($this->elements as $key => $_id) foreach ($this->elements as $key => $_id)
@ -156,7 +169,10 @@ class ProjectTemplateTest extends \EGroupware\Projectmanager\TemplateTest
$copied = array_shift($indexed_elements[$app]); $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"; 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"); $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 require_once realpath(__DIR__.'/../../api/tests/AppTest.php'); // Application test base
use Egroupware\Api; use Egroupware\Api;
use Egroupware\Api\Link;
use Egroupware\Api\Etemplate; use Egroupware\Api\Etemplate;
use Egroupware\Api\Link;
/** /**
* Test setting a project manager project on an infolog entry * Test setting a project manager project on an infolog entry
@ -138,7 +138,7 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
$info = $this->getTestInfolog(); $info = $this->getTestInfolog();
$this->info_id = $this->bo->write($info); $this->info_id = $this->bo->write($info);
$this->assertInternalType('integer', $this->info_id); $this->assertIsInt($this->info_id);
$this->assertGreaterThan(0, $this->info_id); $this->assertGreaterThan(0, $this->info_id);
// Force links to run notification now so we get valid testing - it // Force links to run notification now so we get valid testing - it
@ -185,7 +185,7 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
$info = $this->getTestInfolog(); $info = $this->getTestInfolog();
$this->info_id = $this->bo->write($info); $this->info_id = $this->bo->write($info);
$this->assertInternalType('integer', $this->info_id); $this->assertIsInt($this->info_id);
$this->assertGreaterThan(0, $this->info_id); $this->assertGreaterThan(0, $this->info_id);
// Force links to run notification now so we get valid testing - it // 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'); $this->assertEquals($this->pm_id, $info['pm_id'], 'Project went missing');
// Check that infolog still has contact // Check that infolog still has contact
$this->assertArraySubset( $keys = array('app' => 'addressbook', 'id' => $GLOBALS['egw_info']['user']['person_id']);
array('app' => 'addressbook', 'id' =>$GLOBALS['egw_info']['user']['person_id']), foreach ($keys as $check_key => $check_value)
$info['info_contact'] {
); $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 // Force links to run notification now so we get valid testing - it
// usually waits until Egw::on_shutdown(); // usually waits until Egw::on_shutdown();

View File

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