aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/includes
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/includes')
-rw-r--r--tests/unit/includes/AccountTest.php2
-rw-r--r--tests/unit/includes/BBCodeTest.php6
-rw-r--r--tests/unit/includes/FeedutilsTest.php66
-rw-r--r--tests/unit/includes/LanguageTest.php2
-rw-r--r--tests/unit/includes/MarkdownTest.php4
-rw-r--r--tests/unit/includes/NetworkTest.php4
-rw-r--r--tests/unit/includes/TextTest.php4
-rw-r--r--tests/unit/includes/dba/TransactionTest.php6
8 files changed, 77 insertions, 17 deletions
diff --git a/tests/unit/includes/AccountTest.php b/tests/unit/includes/AccountTest.php
index af5bcd3c1..3978f9d04 100644
--- a/tests/unit/includes/AccountTest.php
+++ b/tests/unit/includes/AccountTest.php
@@ -19,7 +19,7 @@ class AccountTest extends Zotlabs\Tests\Unit\UnitTestCase {
$this->assertEquals($expected, check_account_email($email));
}
- function check_account_email_provider() : array {
+ public static function check_account_email_provider() : array {
return [
// Empty and valid emails return the same result
['', ['error' => false, 'message' => '']],
diff --git a/tests/unit/includes/BBCodeTest.php b/tests/unit/includes/BBCodeTest.php
index 94cad1367..daa66bf72 100644
--- a/tests/unit/includes/BBCodeTest.php
+++ b/tests/unit/includes/BBCodeTest.php
@@ -101,7 +101,7 @@ class BBCodeTest extends UnitTestCase {
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
- private function bbcode_to_html_provider(): array {
+ public static function bbcode_to_html_provider(): array {
return [
'code block' => [
"[code]\ntestvar = \"this is a test\"\necho \"the message is \$testvar\"\n[/code]",
@@ -153,7 +153,7 @@ class BBCodeTest extends UnitTestCase {
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
- private function bbcode_observer_provider(): array {
+ public static function bbcode_observer_provider(): array {
return [
'authenticated observer' => [
'[observer=1]This should be visible[/observer][observer=0]but not this[/observer]',
@@ -205,7 +205,7 @@ class BBCodeTest extends UnitTestCase {
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
- private function html2bbcode_provider(): array {
+ public static function html2bbcode_provider(): array {
return [
'paragraph over multiple lines' => [
"<p>A paragraph over\nmultiple lines\nshould be unwrapped</p>",
diff --git a/tests/unit/includes/FeedutilsTest.php b/tests/unit/includes/FeedutilsTest.php
index bda0bf425..05bff06a3 100644
--- a/tests/unit/includes/FeedutilsTest.php
+++ b/tests/unit/includes/FeedutilsTest.php
@@ -47,7 +47,7 @@ class FeedutilsTest extends UnitTestCase {
public function test_atom_author() {
$this->assertEquals('', atom_author('', 'nick', 'name', 'uri', 72, 72, 'png', 'photourl'));
- $a = '<tag>
+ $expected = '<tag>
<id>uri</id>
<name>nick</name>
<uri>uri</uri>
@@ -57,7 +57,10 @@ class FeedutilsTest extends UnitTestCase {
<poco:displayName>name</poco:displayName>
</tag>';
- $this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'nick', 'name', 'uri', 72, 72, 'png', 'http://photourl'));
+ $this->assertAtomAuthorMatches(
+ $expected,
+ atom_author('tag', 'nick', 'name', 'uri', 72, 72, 'png', 'http://photourl')
+ );
}
/**
@@ -86,6 +89,63 @@ class FeedutilsTest extends UnitTestCase {
<poco:displayName>Chan</poco:displayName>
</tag>';
- $this->assertXmlStringEqualsXmlString($a, atom_render_author('tag', $xchan));
+ $this->assertAtomAuthorMatches($a, atom_render_author('tag', $xchan));
+ }
+
+ /**
+ * Helper method to assert that the generated author tag matches
+ * what we expect.
+ *
+ * Calling `assertXmlStringEqualsXmlString` directly on the fragments
+ * does not work anymore in PHPUnit >= 10.x, as t will throw an XMLException
+ * because of undefined namespaces.
+ *
+ * To overcome that we wrap the generated tags in the proper template,
+ * and compare the fully generated XML from the template instead.
+ *
+ * @param string $expected The expected author XML fragment.
+ * @param string $actual The actually generated authr XML fragment.
+ */
+ private function assertAtomAuthorMatches(string $expected, string $actual): void {
+
+ // Make sure the template engine is initialized before we try to render
+ // the template.
+ //
+ // This may be problematic, as it will compile the template into the same
+ // directory as the site. Assuming that nobody is crazy enough to run the
+ // test suite in a production server, it should probably be fine for now.
+ $smarty = new \Zotlabs\Render\SmartyTemplate();
+ \App::register_template_engine(get_class($smarty));
+
+ $feed_template = get_markup_template('atom_feed.tpl');
+ $expected_xml = replace_macros($feed_template, [
+ '$version' => 42,
+ '$generator' => 'Hubzilla test',
+ '$generator_uri' => 'https://hubzilla.test',
+ '$feed_id' => 'test_channel',
+ '$feed_title' => 'Test channel',
+ '$feed_updated' => 'Sometime',
+ '$author' => $expected,
+ '$owner' => $expected,
+ '$profile_page' => xmlify('https://hubzilla.test/channel/test'),
+ ]);
+
+ $expected_xml .= '</feed>';
+
+ $actual_xml = replace_macros($feed_template, [
+ '$version' => 42,
+ '$generator' => 'Hubzilla test',
+ '$generator_uri' => 'https://hubzilla.test',
+ '$feed_id' => 'test_channel',
+ '$feed_title' => 'Test channel',
+ '$feed_updated' => 'Sometime',
+ '$author' => $actual,
+ '$owner' => $actual,
+ '$profile_page' => xmlify('https://hubzilla.test/channel/test'),
+ ]);
+
+ $actual_xml .= '</feed>';
+
+ $this->assertXmlStringEqualsXmlString($expected_xml, $actual_xml);
}
}
diff --git a/tests/unit/includes/LanguageTest.php b/tests/unit/includes/LanguageTest.php
index 3367232f3..8f62e71e2 100644
--- a/tests/unit/includes/LanguageTest.php
+++ b/tests/unit/includes/LanguageTest.php
@@ -46,7 +46,7 @@ class LanguageTest extends UnitTestCase {
}
}
- public function getLanguageNameProvider() {
+ public static function getLanguageNameProvider() {
return [
'empty language code' => [
'',
diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php
index 960c15139..310130bf1 100644
--- a/tests/unit/includes/MarkdownTest.php
+++ b/tests/unit/includes/MarkdownTest.php
@@ -39,7 +39,7 @@ class MarkdownTest extends UnitTestCase {
$this->assertEquals($expected, markdown_to_bb($src));
}
- private function markdown_to_bbcode_provider(): array {
+ public static function markdown_to_bbcode_provider(): array {
return [
'empty text' => [
'',
@@ -104,7 +104,7 @@ class MarkdownTest extends UnitTestCase {
$this->assertEquals($markdown, html2markdown($html));
}
- public function html2markdownProvider(): array {
+ public static function html2markdownProvider(): array {
return [
'empty text' => [
'',
diff --git a/tests/unit/includes/NetworkTest.php b/tests/unit/includes/NetworkTest.php
index 9fb00e9d3..5bf175953 100644
--- a/tests/unit/includes/NetworkTest.php
+++ b/tests/unit/includes/NetworkTest.php
@@ -20,7 +20,7 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase {
$this->assertEquals($expected, is_local_url($url));
}
- public function localUrlTestProvider() : array {
+ public static function localUrlTestProvider() : array {
return [
[ '/some/path', true ],
[ 'https://mytest.org/some/path', true ],
@@ -47,7 +47,7 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase {
$this->assertTrue(validate_email($email));
}
- function validate_email_provider() : array {
+ public static function validate_email_provider() : array {
return [
// First some invalid email addresses
['', false],
diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php
index b76b15dcf..1e80d71d8 100644
--- a/tests/unit/includes/TextTest.php
+++ b/tests/unit/includes/TextTest.php
@@ -85,7 +85,7 @@ empty line above';
public function testNotags($string, $expected) {
$this->assertEquals($expected, notags($string));
}
- public function notagsProvider() {
+ public static function notagsProvider() {
return [
'empty string' => ['', ''],
'simple tag' => ['<value>', '[value]'],
@@ -102,7 +102,7 @@ empty line above';
sanitise_acl($string);
$this->assertEquals($expected, $string);
}
- public function sanitise_aclProvider() {
+ public static function sanitise_aclProvider() {
return [
'text' => ['value', '<value>'],
'text with angle bracket' => ['<value>', '<[value]>'],
diff --git a/tests/unit/includes/dba/TransactionTest.php b/tests/unit/includes/dba/TransactionTest.php
index 99e3f459d..0b986c6aa 100644
--- a/tests/unit/includes/dba/TransactionTest.php
+++ b/tests/unit/includes/dba/TransactionTest.php
@@ -24,8 +24,8 @@
require_once 'tests/fakes/fake_dba.php';
require_once 'include/dba/dba_transaction.php';
-use \PHPUnit\Framework\TestCase;
-use \Zotlabs\Tests\Fakes\FakeDba;
+use PHPUnit\Framework\TestCase;
+use Zotlabs\Tests\Fakes\FakeDba;
/**
* Test database transactions.
@@ -39,7 +39,7 @@ class DbaTransactionTest extends TestCase {
private $pdo_stub;
public function setUp(): void {
- $this->pdo_stub = $this->createStub(PDO::class);
+ $this->pdo_stub = $this->createMock(PDO::class);
}