diff --git a/templates/system/incompatible.html b/templates/system/incompatible.html
index 113843b4b6b14..620387cd3dd3d 100644
--- a/templates/system/incompatible.html
+++ b/templates/system/incompatible.html
@@ -6,7 +6,7 @@
diff --git a/tests/Integration/DBTestInterface.php b/tests/Integration/DBTestInterface.php
index 257cc323d279c..dc57733e27eb7 100644
--- a/tests/Integration/DBTestInterface.php
+++ b/tests/Integration/DBTestInterface.php
@@ -29,7 +29,6 @@ interface DBTestInterface
public function setDBDriver(DatabaseDriver $driver);
/**
- *
* @return DatabaseDriver
*
* @since 4.0.0
@@ -37,7 +36,6 @@ public function setDBDriver(DatabaseDriver $driver);
public function getDBDriver(): DatabaseDriver;
/**
- *
* @return array
*
* @since 4.0.0
diff --git a/tests/Integration/DBTestTrait.php b/tests/Integration/DBTestTrait.php
index e19edd2100754..01651c766a353 100644
--- a/tests/Integration/DBTestTrait.php
+++ b/tests/Integration/DBTestTrait.php
@@ -42,7 +42,6 @@ public function setDBDriver(DatabaseDriver $driver)
}
/**
- *
* @return mixed
*
* @since 4.0.0
@@ -53,7 +52,6 @@ public function getDBDriver(): DatabaseDriver
}
/**
- *
* @return array
*
* @since 4.0.0
diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php
index f5379fabc6704..148c1d7dc3977 100644
--- a/tests/Integration/IntegrationTestCase.php
+++ b/tests/Integration/IntegrationTestCase.php
@@ -18,7 +18,6 @@
abstract class IntegrationTestCase extends \PHPUnit\Framework\TestCase
{
/**
- *
* @return void
* @since 4.0.0
*/
diff --git a/tests/Integration/Libraries/Cms/Table/TableTest.php b/tests/Integration/Libraries/Cms/Table/TableTest.php
index abef0abf7a68d..c82d6733e8fa7 100644
--- a/tests/Integration/Libraries/Cms/Table/TableTest.php
+++ b/tests/Integration/Libraries/Cms/Table/TableTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Table\Table;
use Joomla\Event\Dispatcher;
use Joomla\Event\DispatcherInterface;
+use Joomla\Event\EventInterface;
use Joomla\Tests\Integration\DBTestInterface;
use Joomla\Tests\Integration\DBTestTrait;
use Joomla\Tests\Integration\IntegrationTestCase;
@@ -45,7 +46,7 @@ protected function setUp(): void
parent::setUp();
$dispatcher = new Dispatcher();
- $this->object = $this->getMockForAbstractClass(Table::class, ['#__testtable', 'id', $this->getDBDriver(), $dispatcher]);
+ $this->object = new class ('#__testtable', 'id', $this->getDBDriver(), $dispatcher) extends Table {};
}
/**
@@ -82,7 +83,7 @@ public function testObjectHasAttributesFromTable()
'params',
];
- $this->assertEquals(
+ $this->assertSame(
$fields,
array_keys($this->object->getFields())
);
@@ -105,19 +106,19 @@ public function testBindWorksWithArraysAndObjects()
$this->object->bind($data);
- $this->assertEquals('Test Title', $this->object->title);
- $this->assertEquals(42, $this->object->hits);
- $this->assertEquals(1, $this->object->published);
- $this->assertEquals(23, $this->object->ordering);
+ $this->assertSame('Test Title', $this->object->title);
+ $this->assertSame(42, $this->object->hits);
+ $this->assertSame(1, $this->object->published);
+ $this->assertSame(23, $this->object->ordering);
$this->object->reset();
$this->object->bind((object) $data);
- $this->assertEquals('Test Title', $this->object->title);
- $this->assertEquals(42, $this->object->hits);
- $this->assertEquals(1, $this->object->published);
- $this->assertEquals(23, $this->object->ordering);
+ $this->assertSame('Test Title', $this->object->title);
+ $this->assertSame(42, $this->object->hits);
+ $this->assertSame(1, $this->object->published);
+ $this->assertSame(23, $this->object->ordering);
}
/**
@@ -139,10 +140,10 @@ public function testBindOnlyBindsTableFields()
$this->object->bind($data);
- $this->assertEquals('Test Title', $this->object->title);
- $this->assertEquals(42, $this->object->hits);
- $this->assertEquals(1, $this->object->published);
- $this->assertEquals(23, $this->object->ordering);
+ $this->assertSame('Test Title', $this->object->title);
+ $this->assertSame(42, $this->object->hits);
+ $this->assertSame(1, $this->object->published);
+ $this->assertSame(23, $this->object->ordering);
$this->assertNotTrue(isset($this->object->fakefield));
$this->assertNotTrue(isset($this->object->fakefield2));
}
@@ -169,18 +170,18 @@ public function testBindIgnoresFields()
// Check for ignore fields as array
$this->object->bind($data, $ignore);
- $this->assertEquals('Test Title', $this->object->title);
- $this->assertEquals(null, $this->object->hits);
- $this->assertEquals(1, $this->object->published);
- $this->assertEquals(null, $this->object->ordering);
+ $this->assertSame('Test Title', $this->object->title);
+ $this->assertSame(null, $this->object->hits);
+ $this->assertSame(1, $this->object->published);
+ $this->assertSame(null, $this->object->ordering);
// Check for ignore fields as string
$this->object->bind($data, 'hits ordering');
- $this->assertEquals('Test Title', $this->object->title);
- $this->assertEquals(null, $this->object->hits);
- $this->assertEquals(1, $this->object->published);
- $this->assertEquals(null, $this->object->ordering);
+ $this->assertSame('Test Title', $this->object->title);
+ $this->assertSame(null, $this->object->hits);
+ $this->assertSame(1, $this->object->published);
+ $this->assertSame(null, $this->object->ordering);
}
/**
@@ -217,7 +218,7 @@ public function testBindJSONEncodesFields()
$this->object->bind($data);
- $this->assertEquals(json_encode($data['params']), $this->object->params);
+ $this->assertSame(json_encode($data['params']), $this->object->params);
}
/**
@@ -248,13 +249,21 @@ public function testBindFiresEvents()
'ordering' => 23,
];
- $dispatcherMock = $this->getMockBuilder(DispatcherInterface::class)->getMock();
- $dispatcherMock->expects($this->exactly(2))
+ $matcher = $this->exactly(2);
+ $dispatcherMock = $this->createMock(DispatcherInterface::class);
+ $dispatcherMock->expects($matcher)
->method('dispatch')
- ->withConsecutive(
- ['onTableBeforeBind', $this->anything()],
- ['onTableAfterBind', $this->anything()]
- );
+ ->willReturnCallback(function (...$parameters) use ($matcher) {
+ if ($matcher->numberOfInvocations() === 1) {
+ $this->assertSame('onTableBeforeBind', $parameters[0]);
+ $this->assertInstanceOf(EventInterface::class, $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 2) {
+ $this->assertSame('onTableAfterBind', $parameters[0]);
+ $this->assertInstanceOf(EventInterface::class, $parameters[1]);
+ }
+
+ return $parameters[1];
+ });
$this->object->setDispatcher($dispatcherMock);
@@ -269,8 +278,6 @@ public function testBindFiresEvents()
*/
public function testReset()
{
- $nullDate = $this->getDBDriver()->getNullDate();
-
$this->object->id = 25;
$this->object->title = 'My Title';
$this->object->hits = 42;
@@ -278,46 +285,54 @@ public function testReset()
$this->object->params = '{"test":5}';
$this->object->setError('Generic error');
- $dispatcherMock = $this->getMockBuilder(DispatcherInterface::class)->getMock();
- $dispatcherMock->expects($this->exactly(2))
+ $matcher = $this->exactly(2);
+ $dispatcherMock = $this->createMock(DispatcherInterface::class);
+ $dispatcherMock->expects($matcher)
->method('dispatch')
- ->withConsecutive(
- ['onTableBeforeReset', $this->anything()],
- ['onTableAfterReset', $this->anything()]
- );
+ ->willReturnCallback(function (...$parameters) use ($matcher) {
+ if ($matcher->numberOfInvocations() === 1) {
+ $this->assertSame('onTableBeforeReset', $parameters[0]);
+ $this->assertInstanceOf(EventInterface::class, $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 2) {
+ $this->assertSame('onTableAfterReset', $parameters[0]);
+ $this->assertInstanceOf(EventInterface::class, $parameters[1]);
+ }
+
+ return $parameters[1];
+ });
$this->object->setDispatcher($dispatcherMock);
$this->object->reset();
// The primary keys should be left alone.
- $this->assertEquals(
+ $this->assertSame(
25,
$this->object->id
);
// The regular fields should get reset
- $this->assertEquals(
+ $this->assertSame(
'',
$this->object->title
);
- $this->assertEquals(
- 0,
+ $this->assertSame(
+ '0',
$this->object->hits
);
- $this->assertEquals(
+ $this->assertSame(
null,
$this->object->publish_up
);
- $this->assertEquals(
+ $this->assertSame(
null,
$this->object->params
);
- $this->assertEquals(
+ $this->assertSame(
[],
$this->object->getErrors()
);
diff --git a/tests/Integration/Plugin/Authentication/Ldap/LdapPluginTest.php b/tests/Integration/Plugin/Authentication/Ldap/LdapPluginTest.php
index dd391df4dd789..900d5fe4c42a2 100644
--- a/tests/Integration/Plugin/Authentication/Ldap/LdapPluginTest.php
+++ b/tests/Integration/Plugin/Authentication/Ldap/LdapPluginTest.php
@@ -18,6 +18,7 @@
use Joomla\Plugin\Authentication\Ldap\Extension\Ldap as LdapPlugin;
use Joomla\Plugin\Authentication\Ldap\Factory\LdapFactory;
use Joomla\Tests\Integration\IntegrationTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for Ldap plugin
@@ -31,10 +32,9 @@
* @package Joomla.IntegrationTest
* @subpackage Ldap
*
- * @testdox The Ldap plugin
- *
* @since 4.3.0
*/
+#[TestDox('The Ldap plugin')]
class LdapPluginTest extends IntegrationTestCase
{
public const LDAPPORT = JTEST_LDAP_PORT;
@@ -137,12 +137,11 @@ public function tearDown(): void
}
/**
- * @testdox can perform an authentication using bind and search
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using bind and search')]
public function testOnUserAuthenticateBindAndSearch()
{
$options = $this->default_options;
@@ -153,16 +152,15 @@ public function testOnUserAuthenticateBindAndSearch()
$response = new AuthenticationResponse();
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $this->default_credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
/**
- * @testdox can perform an authentication using direct bind
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using direct bind')]
public function testOnUserAuthenticateDirect()
{
$options = $this->default_options;
@@ -173,16 +171,15 @@ public function testOnUserAuthenticateDirect()
$response = new AuthenticationResponse();
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $this->default_credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
/**
- * @testdox can perform an authentication using direct bind with bad credentials
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using direct bind with bad credentials')]
public function testInvalidOnUserAuthenticateDirect()
{
$options = $this->default_options;
@@ -196,16 +193,15 @@ public function testInvalidOnUserAuthenticateDirect()
$response = new AuthenticationResponse();
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can perform an authentication on STARTTLS encrypted connection (using bind and search)
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication on STARTTLS encrypted connection (using bind and search)')]
public function testOnUserAuthenticateBindAndSearchTLS()
{
$options = $this->default_options;
@@ -217,16 +213,15 @@ public function testOnUserAuthenticateBindAndSearchTLS()
$response = new AuthenticationResponse();
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $this->default_credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
/**
- * @testdox can perform an authentication on SSL/TLS encrypted connection (using bind and search)
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication on SSL/TLS encrypted connection (using bind and search)')]
public function testOnUserAuthenticateBindAndSearchSSL()
{
$options = $this->default_options;
@@ -239,6 +234,6 @@ public function testOnUserAuthenticateBindAndSearchSSL()
$response = new AuthenticationResponse();
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $this->default_credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
}
diff --git a/tests/Integration/datasets/pgsql/testtable.sql b/tests/Integration/datasets/pgsql/testtable.sql
index ce28fbd3ed843..53916be697340 100644
--- a/tests/Integration/datasets/pgsql/testtable.sql
+++ b/tests/Integration/datasets/pgsql/testtable.sql
@@ -1,12 +1,12 @@
DROP TABLE IF EXISTS "#__testtable";
CREATE TABLE IF NOT EXISTS "#__testtable" (
"id" serial NOT NULL,
- "title" varchar(100) NOT NULL,
+ "title" varchar(100) NOT NULL DEFAULT '',
"asset_id" bigint NOT NULL DEFAULT 0,
"hits" bigint NOT NULL DEFAULT 0,
"checked_out" integer,
"checked_out_time" timestamp without time zone,
- "published" smallint DEFAULT 0 NOT NULL,
+ "published" smallint NOT NULL DEFAULT 0,
"publish_up" timestamp without time zone,
"publish_down" timestamp without time zone,
"ordering" bigint NOT NULL DEFAULT 0,
diff --git a/tests/System/README.md b/tests/System/README.md
index d837a535c9282..7cb1fba973f1b 100644
--- a/tests/System/README.md
+++ b/tests/System/README.md
@@ -183,6 +183,7 @@ The Joomla System Tests come with some convenient [Cypress Tasks](https://docs.c
- **startMailServer** – Starts the smtp-tester SMTP server
- **getMails** – Get received mails from smtp-tester
- **clearEmails** – Clear all smtp-tester received mails
+- **executeCli** – Executes a CLI command
The following code in a test executes the writing file task with parameters:
```JavaScript
@@ -232,6 +233,9 @@ The following commands are available and are served by the file [tests/System/su
- **db_createUser** – Creates a user entry and returns the id
- **db_createUserGroup** – Creates a user group and returns the id
- **db_createUserLevel** – Creates a user access level and returns the id
+- **db_createWorkflow** – Creates a workflow and returns the inserted record
+- **db_createWorkflowStage** – Creates a workflow stage and returns the inserted record
+- **db_createWorkflowTransition** – Creates a workflow transition and returns the inserted record
- **db_enableExtension** – Sets the enabled status for the given extension
- **db_getUserId** – Returns the id of the currently logged in user
- **db_updateExtensionParameter** – Sets the parameter for the given extension
diff --git a/tests/System/integration/administrator/components/com_content/Workflow.cy.js b/tests/System/integration/administrator/components/com_content/Workflow.cy.js
new file mode 100644
index 0000000000000..4c65b3548b70e
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_content/Workflow.cy.js
@@ -0,0 +1,112 @@
+describe('Test in backend that the content component', () => {
+ beforeEach(() => cy.doAdministratorLogin());
+ afterEach(() => {
+ cy.task('queryDB', "DELETE FROM #__content_frontpage WHERE content_id IN (SELECT id FROM #__content WHERE title = 'Test article')");
+ cy.task('queryDB', "DELETE FROM #__workflow_associations WHERE item_id IN (SELECT id FROM #__content WHERE title = 'Test article') AND extension = 'com_content.article'");
+ cy.task('queryDB', "DELETE FROM #__content WHERE title = 'Test article'");
+ });
+ after(() => cy.db_updateExtensionParameter('workflow_enabled', '0', 'com_content'));
+
+ it('can enable workflow integration', () => {
+ cy.visit('/administrator/index.php?option=com_config&view=component&component=com_content');
+ cy.get('#configTabs div[role="tablist"] button[aria-controls="integration"]').click();
+ cy.get('#jform_workflow_enabled1').check();
+ cy.intercept('index.php?option=com_config*').as('config_save');
+ cy.clickToolbarButton('Save');
+ cy.wait('@config_save');
+ cy.checkForSystemMessage('Configuration saved.');
+ });
+
+ it('can run transition (unpublish)', () => {
+ cy.db_createArticle({ title: 'Test article', state: 1 }).then(() => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter[search]=Test%20article');
+ cy.checkAllResults();
+ cy.get('#toolbar-status-group').click().within(() => {
+ cy.get('joomla-toolbar-button').contains('Unpublish').click();
+ });
+ cy.checkForSystemMessage('New state saved.');
+ cy.get('#articleList tbody td.article-status span.icon-unpublish').should('exist');
+ });
+ });
+
+ it('can run transition (publish)', () => {
+ cy.db_createArticle({ title: 'Test article', state: 0 }).then(() => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter[search]=Test%20article');
+ cy.get('#cb0').check();
+ cy.get('#toolbar-status-group').click().within(() => {
+ cy.get('joomla-toolbar-button').contains('Publish').click();
+ });
+ cy.checkForSystemMessage('New state saved.');
+ cy.get('#articleList tbody td.article-status span.icon-publish').should('exist');
+ });
+ });
+
+ it('can run transition (trash)', () => {
+ cy.db_createArticle({ title: 'Test article', state: 0 }).then(() => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter[search]=Test%20article&filter[published]=*');
+ cy.get('#cb0').check();
+ cy.get('#toolbar-status-group').click().within(() => {
+ cy.get('joomla-toolbar-button').contains('Trash').click();
+ });
+ cy.checkForSystemMessage('New state saved.');
+ cy.get('#articleList tbody td.article-status span.icon-trash').should('exist');
+ });
+ });
+
+ it('can run transition (archive)', () => {
+ cy.db_createArticle({ title: 'Test article', state: 1 }).then(() => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter[search]=Test%20article&filter[published]=*');
+ cy.get('#articleList thead th').contains('Stage');
+ cy.get('#articleList tbody td.article-status span.icon-publish').should('exist');
+ cy.get('td.article-stage button').click();
+ cy.get('td.article-stage select').select('Archive');
+ cy.checkForSystemMessage('New state saved.');
+ cy.get('#articleList tbody td.article-status span.icon-archive').should('exist');
+ });
+ });
+
+ it('can run transition (feature)', () => {
+ cy.db_createArticle({ title: 'Test article', state: 1 }).then(() => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter[search]=Test%20article');
+ cy.get('#articleList thead th').contains('Stage');
+ cy.get('#articleList tbody td span.icon-unfeatured').should('exist');
+ cy.get('td.article-stage button').click();
+ cy.get('td.article-stage select').select('Feature');
+ cy.checkForSystemMessage('New state saved.');
+ cy.get('#articleList tbody td span.icon-color-featured.icon-star').should('exist');
+ });
+ });
+
+ it('can run transition (publish & feature)', () => {
+ cy.db_createArticle({ title: 'Test article', state: 0 }).then(() => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter[search]=Test%20article');
+ cy.get('#articleList thead th').contains('Stage');
+ cy.get('#articleList tbody td.article-status span.icon-unpublish').should('exist');
+ cy.get('#articleList tbody td span.icon-unfeatured').should('exist');
+ cy.get('td.article-stage button').click();
+ cy.get('td.article-stage select').select('Publish & Feature');
+ cy.checkForSystemMessage('New state saved.');
+ cy.get('#articleList tbody td.article-status span.icon-publish').should('exist');
+ cy.get('#articleList tbody td span.icon-color-featured.icon-star').should('exist');
+ });
+ });
+
+ it('can create new article and run transitions', () => {
+ cy.visit('/administrator/index.php?option=com_content&view=articles&filter=');
+ cy.clickToolbarButton('New');
+ cy.get('#jform_title').type('Test article');
+ cy.get('#jform_state-lbl').contains('Unpublished');
+ cy.get('#jform_transition').select('Publish', { force: true });
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Article saved.');
+ cy.get('#jform_state-lbl').contains('Published');
+ cy.get('#jform_featured-lbl').contains('No');
+ cy.get('#jform_transition').select('Feature', { force: true });
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Article saved.');
+ cy.get('#jform_state-lbl').contains('Published');
+ cy.get('#jform_featured-lbl').contains('Yes');
+ });
+});
diff --git a/tests/System/integration/administrator/components/com_contenthistory/Content.cy.js b/tests/System/integration/administrator/components/com_contenthistory/Content.cy.js
index 4ed2aea20d7d6..69deff0c490e2 100644
--- a/tests/System/integration/administrator/components/com_contenthistory/Content.cy.js
+++ b/tests/System/integration/administrator/components/com_contenthistory/Content.cy.js
@@ -24,7 +24,7 @@ describe('Test in backend that the content history list', () => {
const currentDate = new Date();
const formattedDate = `${currentDate.getFullYear()}-${(currentDate.getMonth() + 1).toString().padStart(2, '0')}-${currentDate.getDate().toString().padStart(2, '0')}`;
- cy.get('joomla-dialog[type="iframe"]').as('dialogContent');
+ cy.get('joomla-dialog[type="iframe"] dialog').as('dialogContent');
cy.get('@dialogContent').should('be.visible');
cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', 'Versions');
@@ -42,7 +42,7 @@ describe('Test in backend that the content history list', () => {
cy.clickToolbarButton('Save');
cy.clickToolbarButton('Versions');
- cy.get('joomla-dialog[type="iframe"]').as('dialogContent');
+ cy.get('joomla-dialog[type="iframe"] dialog').as('dialogContent');
cy.get('@dialogContent').should('be.visible');
cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', 'Versions');
@@ -65,7 +65,7 @@ describe('Test in backend that the content history list', () => {
cy.clickToolbarButton('Save');
cy.clickToolbarButton('Versions');
- cy.get('joomla-dialog[type="iframe"]').as('dialogContent');
+ cy.get('joomla-dialog[type="iframe"] dialog').as('dialogContent');
cy.get('@dialogContent').should('be.visible');
cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', 'Versions');
@@ -83,7 +83,7 @@ describe('Test in backend that the content history list', () => {
cy.clickToolbarButton('Save');
cy.clickToolbarButton('Versions');
- cy.get('joomla-dialog[type="iframe"]').as('dialogContent');
+ cy.get('joomla-dialog[type="iframe"] dialog').as('dialogContent');
cy.get('@dialogContent').should('be.visible');
cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', 'Versions');
@@ -108,7 +108,7 @@ describe('Test in backend that the content history list', () => {
cy.clickToolbarButton('Save');
cy.clickToolbarButton('Versions');
- cy.get('joomla-dialog[type="iframe"]').as('dialogContent');
+ cy.get('joomla-dialog[type="iframe"] dialog').as('dialogContent');
cy.get('@dialogContent').should('be.visible');
cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', 'Versions');
@@ -133,7 +133,7 @@ describe('Test in backend that the content history list', () => {
cy.clickToolbarButton('Save');
cy.clickToolbarButton('Versions');
- cy.get('joomla-dialog[type="iframe"]').as('dialogContent');
+ cy.get('joomla-dialog[type="iframe"] dialog').as('dialogContent');
cy.get('@dialogContent').should('be.visible');
cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', 'Versions');
diff --git a/tests/System/integration/administrator/components/com_finder/Index.cy.js b/tests/System/integration/administrator/components/com_finder/Index.cy.js
index f6decc45d1b20..3fcf7836ec6ef 100644
--- a/tests/System/integration/administrator/components/com_finder/Index.cy.js
+++ b/tests/System/integration/administrator/components/com_finder/Index.cy.js
@@ -16,6 +16,23 @@ describe('Test in backend that the Smart Search', () => {
cy.contains('Test article').should('exist');
});
+ it('can index content', () => {
+ // Create a new article
+ cy.visit('/administrator/index.php?option=com_content&task=article.add');
+ cy.get('#jform_title').clear().type('Test article');
+ cy.clickToolbarButton('Save & Close');
+ // Visit the smart search page
+ cy.visit('/administrator/index.php?option=com_finder&view=index');
+ cy.get('#toolbar-indexing-group, #toolbar-index').then(($toolbar) => {
+ if ($toolbar.is('#toolbar-indexing-group')) {
+ // JDEBUG enabled: Index is inside the dropdown
+ cy.get('#toolbar-indexing-group > button').click();
+ }
+ });
+ cy.get('button.button-index').should('be.visible').click();
+ cy.contains('Test article').should('exist');
+ });
+
it('can purge the index', () => {
// Visit the smart search page
cy.visit('/administrator/index.php?option=com_finder&view=index');
diff --git a/tests/System/integration/administrator/components/com_workflow/Stage.cy.js b/tests/System/integration/administrator/components/com_workflow/Stage.cy.js
new file mode 100644
index 0000000000000..127139653abe7
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_workflow/Stage.cy.js
@@ -0,0 +1,67 @@
+describe('Test in backend that the stage form', () => {
+ before(() => cy.task('writeRelativeFile', { path: 'administrator/language/overrides/en-GB.override.ini', content: 'AUTOMATED_TEST_STAGE="Test stage translated"' }));
+ beforeEach(() => cy.doAdministratorLogin());
+ afterEach(() => cy.task('queryDB', "DELETE FROM #__workflow_stages WHERE title = 'AUTOMATED_TEST_STAGE'"));
+ after(() => cy.task('deleteRelativePath', 'administrator/language/overrides/en-GB.override.ini'));
+
+ it('can create a stage', () => {
+ cy.visit('/administrator/index.php?option=com_workflow&task=stage.add&workflow_id=1&extension=com_content.article');
+ cy.title().should('contain', 'Add Stage');
+ cy.get('h1.page-title').should('contain', 'Add Stage');
+ cy.get('#jform_title').clear().type('AUTOMATED_TEST_STAGE');
+ cy.get('#jform_description').clear().type('automated test stage');
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.title().should('contain', 'Edit Stage');
+ cy.get('h1.page-title').should('contain', 'Edit Stage');
+ cy.get('#jform_title').should('have.value', 'AUTOMATED_TEST_STAGE');
+ cy.get('#stage_title_translation').should('have.value', 'Test stage translated');
+
+ cy.clickToolbarButton('Cancel');
+ cy.get('h1.page-title').should('contain', 'Stages: Basic Workflow');
+
+ cy.get('table#stageList').contains('Test stage translated');
+ cy.get('table#stageList').contains('automated test stage');
+ });
+
+ it('can edit a stage', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: 0 }).then((stage) => {
+ cy.visit(`/administrator/index.php?option=com_workflow&task=stage.edit&workflow_id=1&extension=com_content.article&id=${stage.id}`);
+ cy.get('h1.page-title').should('contain', 'Edit Stage');
+ cy.get('#jform_published').find(':selected').should('contain', 'Disabled');
+ cy.get('#jform_published').select('Enabled');
+ cy.get('#jform_description').clear().type('edited stage');
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('#jform_published').find(':selected').should('contain', 'Enabled');
+ cy.clickToolbarButton('Save & Close');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('table#stageList').contains('edited stage');
+ });
+ });
+
+ it('can edit a stage (list view)', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage' });
+ cy.visit('/administrator/index.php?option=com_workflow&view=stages&workflow_id=1&extension=com_content.article');
+ cy.get('table#stageList a').contains('Test stage').click();
+ cy.get('h1.page-title').should('contain', 'Edit Stage');
+ cy.get('#jform_title').clear().type('stage title');
+ cy.get('#toolbar-dropdown-save-group .btn.btn-success.dropdown-toggle-split').click();
+ cy.clickToolbarButton('Save & New');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('h1.page-title').should('contain', 'Add Stage');
+ });
+
+ it('redirects to the correct list view', () => {
+ cy.visit('/administrator/index.php?option=com_workflow&task=stage.add&workflow_id=1&extension=com_content.article');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=stages&workflow_id=1&extension=com_content.article').as('listview');
+ cy.clickToolbarButton('Cancel');
+
+ cy.wait('@listview');
+ cy.title().should('contain', 'Stages: Basic Workflow');
+ });
+});
diff --git a/tests/System/integration/administrator/components/com_workflow/Stages.cy.js b/tests/System/integration/administrator/components/com_workflow/Stages.cy.js
new file mode 100644
index 0000000000000..2941635fdb107
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_workflow/Stages.cy.js
@@ -0,0 +1,154 @@
+describe('Test in backend that the stages list', () => {
+ beforeEach(() => {
+ cy.doAdministratorLogin();
+ cy.visit('/administrator/index.php?option=com_workflow&view=stages&workflow_id=1&extension=com_content.article&filter=');
+ });
+ after(() => cy.task('queryDB', 'UPDATE #__workflow_stages SET `default` = 1 WHERE id = 1'));
+
+ it('can display a list of stages', () => {
+ cy.title().should('contain', 'Stages: Basic Workflow');
+ cy.get('h1.page-title').should('contain', 'Stages: Basic Workflow');
+ cy.contains('Basic Stage');
+ });
+
+ it('can open the stage form', () => {
+ cy.clickToolbarButton('New');
+
+ cy.title().should('contain', 'Add Stage');
+ cy.contains('Add Stage');
+ });
+
+ it('can enable the stage', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: 0 });
+ cy.reload();
+ cy.setFilter('published', 'Unpublished');
+ cy.searchForItem('Test stage');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Publish');
+
+ cy.checkForSystemMessage('Stage enabled.');
+ });
+
+ it('can disable the stage', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: 1 });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('Test stage');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Unpublish');
+
+ cy.checkForSystemMessage('Stage disabled.');
+ });
+
+ it('can trash the stage', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: 1 });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('Test stage');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Trash');
+
+ cy.checkForSystemMessage('Stage trashed.');
+ });
+
+ it('can delete the stage', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: -2 });
+ cy.reload();
+ cy.setFilter('published', 'Trashed');
+ cy.searchForItem('Test stage');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Empty Trash');
+ cy.clickDialogConfirm(true);
+
+ cy.checkForSystemMessage('Stage deleted.');
+ });
+
+ it('can checkin the stage', () => {
+ cy.db_getUserId(Cypress.expose('username')).then((uid) => {
+ cy.db_createWorkflowStage({ title: 'Test stage', checked_out: uid, checked_out_time: '2025-01-01 00:00:00' });
+ cy.reload();
+ cy.searchForItem('Test stage');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Check-In');
+
+ cy.checkForSystemMessage('Stage checked in.');
+ });
+ });
+
+ it('can enable the stage (grid button)', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: 0, description: 'stage1' });
+ cy.reload();
+ cy.setFilter('published', 'Unpublished');
+ cy.searchForItem('stage1');
+ cy.get('table#stageList .icon-unpublish').click();
+
+ cy.checkForSystemMessage('Stage enabled.');
+ });
+
+ it('can disable the stage (grid button)', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', published: 1, description: 'stage2' });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('stage2');
+ cy.get('table#stageList .icon-publish').click();
+
+ cy.checkForSystemMessage('Stage disabled.');
+ });
+
+ it('can checkin the stage (grid button)', () => {
+ cy.db_getUserId(Cypress.expose('username')).then((uid) => {
+ cy.db_createWorkflowStage({ title: 'Test stage', checked_out: uid, checked_out_time: '2025-01-01 00:00:00' });
+ cy.reload();
+ cy.searchForItem('Test stage');
+ cy.get('table#stageList .icon-checkedout').click();
+
+ cy.checkForSystemMessage('Stage checked in.');
+ });
+ });
+
+ it('can set stage as default (grid button)', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage', default: 0 });
+ cy.reload();
+ cy.searchForItem('Test stage');
+ cy.get('table#stageList .icon-unfeatured').click();
+
+ cy.checkForSystemMessage('Stage set as default.');
+ });
+
+ it('can filter state', () => {
+ cy.db_createWorkflowStage({ title: 'Test stage 1', published: 1 });
+ cy.db_createWorkflowStage({ title: 'Test stage 2', published: 0 });
+ cy.db_createWorkflowStage({ title: 'Test stage 3', published: -2 });
+ cy.reload();
+
+ cy.get('#stageList')
+ .should('contain', 'Test stage 1')
+ .should('contain', 'Test stage 2')
+ .should('not.contain', 'Test stage 3');
+
+ cy.setFilter('published', 'Published');
+
+ cy.get('#stageList')
+ .should('contain', 'Test stage 1')
+ .should('not.contain', 'Test stage 2')
+ .should('not.contain', 'Test stage 3');
+
+ cy.setFilter('published', 'Unpublished');
+
+ cy.get('#stageList')
+ .should('not.contain', 'Test stage 1')
+ .should('contain', 'Test stage 2')
+ .should('not.contain', 'Test stage 3');
+
+ cy.setFilter('published', 'Trashed');
+
+ cy.get('#stageList')
+ .should('not.contain', 'Test stage 1')
+ .should('not.contain', 'Test stage 2')
+ .should('contain', 'Test stage 3');
+ });
+});
diff --git a/tests/System/integration/administrator/components/com_workflow/Transition.cy.js b/tests/System/integration/administrator/components/com_workflow/Transition.cy.js
new file mode 100644
index 0000000000000..c93140e819f09
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_workflow/Transition.cy.js
@@ -0,0 +1,67 @@
+describe('Test in backend that the transition form', () => {
+ before(() => cy.task('writeRelativeFile', { path: 'administrator/language/overrides/en-GB.override.ini', content: 'AUTOMATED_TEST_TRANSITION="Test transition translated"' }));
+ beforeEach(() => cy.doAdministratorLogin());
+ afterEach(() => cy.task('queryDB', "DELETE FROM #__workflow_transitions WHERE title = 'AUTOMATED_TEST_TRANSITION'"));
+ after(() => cy.task('deleteRelativePath', 'administrator/language/overrides/en-GB.override.ini'));
+
+ it('can create a transition', () => {
+ cy.visit('/administrator/index.php?option=com_workflow&task=transition.add&workflow_id=1&extension=com_content.article');
+ cy.title().should('contain', 'Add Transition');
+ cy.get('h1.page-title').should('contain', 'Add Transition');
+ cy.get('#jform_title').clear().type('AUTOMATED_TEST_TRANSITION');
+ cy.get('#jform_description').clear().type('automated test transition');
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.title().should('contain', 'Edit Transition');
+ cy.get('h1.page-title').should('contain', 'Edit Transition');
+ cy.get('#jform_title').should('have.value', 'AUTOMATED_TEST_TRANSITION');
+ // cy.get('#transition_title_translation').should('have.value', 'Test transition translated');
+
+ cy.clickToolbarButton('Cancel');
+ cy.get('h1.page-title').should('contain', 'Transitions: Basic Workflow');
+
+ cy.get('table#transitionList').contains('Test transition translated');
+ cy.get('table#transitionList').contains('automated test transition');
+ });
+
+ it('can edit a transition', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: 0 }).then((transition) => {
+ cy.visit(`/administrator/index.php?option=com_workflow&task=transition.edit&workflow_id=1&extension=com_content.article&id=${transition.id}`);
+ cy.get('h1.page-title').should('contain', 'Edit Transition');
+ cy.get('#jform_published').find(':selected').should('contain', 'Disabled');
+ cy.get('#jform_published').select('Enabled');
+ cy.get('#jform_description').clear().type('edited transition');
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('#jform_published').find(':selected').should('contain', 'Enabled');
+ cy.clickToolbarButton('Save & Close');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('table#transitionList').contains('edited transition');
+ });
+ });
+
+ it('can edit a transition (list view)', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition' });
+ cy.visit('/administrator/index.php?option=com_workflow&view=transitions&workflow_id=1&extension=com_content.article');
+ cy.get('table#transitionList a').contains('Test transition').click();
+ cy.get('h1.page-title').should('contain', 'Edit Transition');
+ cy.get('#jform_title').clear().type('transition title');
+ cy.get('#toolbar-dropdown-save-group .btn.btn-success.dropdown-toggle-split').click();
+ cy.clickToolbarButton('Save & New');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('h1.page-title').should('contain', 'Add Transition');
+ });
+
+ it('redirects to the correct list view', () => {
+ cy.visit('/administrator/index.php?option=com_workflow&task=transition.add&workflow_id=1&extension=com_content.article');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=transitions&workflow_id=1&extension=com_content.article').as('listview');
+ cy.clickToolbarButton('Cancel');
+
+ cy.wait('@listview');
+ cy.title().should('contain', 'Transitions: Basic Workflow');
+ });
+});
diff --git a/tests/System/integration/administrator/components/com_workflow/Transitions.cy.js b/tests/System/integration/administrator/components/com_workflow/Transitions.cy.js
new file mode 100644
index 0000000000000..5c4f249e8a32a
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_workflow/Transitions.cy.js
@@ -0,0 +1,196 @@
+describe('Test in backend that the transitions list', () => {
+ beforeEach(() => {
+ cy.doAdministratorLogin();
+ cy.visit('/administrator/index.php?option=com_workflow&view=transitions&workflow_id=1&extension=com_content.article&filter=');
+ });
+
+ it('can display a list of transitions', () => {
+ cy.title().should('contain', 'Transitions: Basic Workflow');
+ cy.get('h1.page-title').should('contain', 'Transitions: Basic Workflow');
+ cy.contains('Publish');
+ });
+
+ it('can open the transition form', () => {
+ cy.clickToolbarButton('New');
+
+ cy.title().should('contain', 'Add Transition');
+ cy.contains('Add Transition');
+ });
+
+ it('can enable the transition', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: 0 });
+ cy.reload();
+ cy.setFilter('published', 'Unpublished');
+ cy.searchForItem('Test transition');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Publish');
+
+ cy.checkForSystemMessage('Transition enabled.');
+ });
+
+ it('can disable the transition', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: 1 });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('Test transition');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Unpublish');
+
+ cy.checkForSystemMessage('Transition disabled.');
+ });
+
+ it('can trash the transition', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: 1 });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('Test transition');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Trash');
+
+ cy.checkForSystemMessage('Transition trashed.');
+ });
+
+ it('can delete the transition', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: -2 });
+ cy.reload();
+ cy.setFilter('published', 'Trashed');
+ cy.searchForItem('Test transition');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Empty Trash');
+ cy.clickDialogConfirm(true);
+
+ cy.checkForSystemMessage('Transition deleted.');
+ });
+
+ it('can checkin the transition', () => {
+ cy.db_getUserId(Cypress.expose('username')).then((uid) => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', checked_out: uid, checked_out_time: '2025-01-01 00:00:00' });
+ cy.reload();
+ cy.searchForItem('Test transition');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Check-In');
+
+ cy.checkForSystemMessage('Transition checked in.');
+ });
+ });
+
+ it('can enable the transition (grid button)', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: 0, description: 'transition1' });
+ cy.reload();
+ cy.setFilter('published', 'Unpublished');
+ cy.searchForItem('transition1');
+ cy.get('table#transitionList .icon-unpublish').click();
+
+ cy.checkForSystemMessage('Transition enabled.');
+ });
+
+ it('can disable the transition (grid button)', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', published: 1, description: 'transition2' });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('transition2');
+ cy.get('table#transitionList .icon-publish').click();
+
+ cy.checkForSystemMessage('Transition disabled.');
+ });
+
+ it('can checkin the transition (grid button)', () => {
+ cy.db_getUserId(Cypress.expose('username')).then((uid) => {
+ cy.db_createWorkflowTransition({ title: 'Test transition', checked_out: uid, checked_out_time: '2025-01-01 00:00:00' });
+ cy.reload();
+ cy.searchForItem('Test transition');
+ cy.get('table#transitionList .icon-checkedout').click();
+
+ cy.checkForSystemMessage('Transition checked in.');
+ });
+ });
+
+ it('can filter state', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition 1', published: 1 });
+ cy.db_createWorkflowTransition({ title: 'Test transition 2', published: 0 });
+ cy.db_createWorkflowTransition({ title: 'Test transition 3', published: -2 });
+ cy.reload();
+
+ cy.get('#transitionList')
+ .should('contain', 'Test transition 1')
+ .should('contain', 'Test transition 2')
+ .should('not.contain', 'Test transition 3');
+
+ cy.setFilter('published', 'Published');
+
+ cy.get('#transitionList')
+ .should('contain', 'Test transition 1')
+ .should('not.contain', 'Test transition 2')
+ .should('not.contain', 'Test transition 3');
+
+ cy.setFilter('published', 'Unpublished');
+
+ cy.get('#transitionList')
+ .should('not.contain', 'Test transition 1')
+ .should('contain', 'Test transition 2')
+ .should('not.contain', 'Test transition 3');
+
+ cy.setFilter('published', 'Trashed');
+
+ cy.get('#transitionList')
+ .should('not.contain', 'Test transition 1')
+ .should('not.contain', 'Test transition 2')
+ .should('contain', 'Test transition 3');
+ });
+
+ it('can filter current stage', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition 1' });
+ cy.db_createWorkflowStage({ title: 'Test stage 2' }).then((stage) => cy.db_createWorkflowTransition({ title: 'Test transition 2', from_stage_id: stage.id }));
+ cy.db_createWorkflowStage({ title: 'Test stage 3' }).then((stage) => cy.db_createWorkflowTransition({ title: 'Test transition 3', from_stage_id: stage.id }));
+ cy.reload();
+
+ cy.get('#transitionList')
+ .should('contain', 'Test transition 1')
+ .should('contain', 'Test transition 2')
+ .should('contain', 'Test transition 3');
+
+ cy.setFilter('from_stage', 'Test stage 2');
+
+ cy.get('#transitionList')
+ .should('not.contain', 'Test transition 1')
+ .should('contain', 'Test transition 2')
+ .should('not.contain', 'Test transition 3');
+
+ cy.setFilter('from_stage', 'Test stage 3');
+
+ cy.get('#transitionList')
+ .should('not.contain', 'Test transition 1')
+ .should('not.contain', 'Test transition 2')
+ .should('contain', 'Test transition 3');
+ });
+
+ it('can filter target stage', () => {
+ cy.db_createWorkflowTransition({ title: 'Test transition 1' });
+ cy.db_createWorkflowStage({ title: 'Test stage 2' }).then((stage) => cy.db_createWorkflowTransition({ title: 'Test transition 2', to_stage_id: stage.id }));
+ cy.db_createWorkflowStage({ title: 'Test stage 3' }).then((stage) => cy.db_createWorkflowTransition({ title: 'Test transition 3', to_stage_id: stage.id }));
+ cy.reload();
+
+ cy.get('#transitionList')
+ .should('contain', 'Test transition 1')
+ .should('contain', 'Test transition 2')
+ .should('contain', 'Test transition 3');
+
+ cy.setFilter('to_stage', 'Test stage 2');
+
+ cy.get('#transitionList')
+ .should('not.contain', 'Test transition 1')
+ .should('contain', 'Test transition 2')
+ .should('not.contain', 'Test transition 3');
+
+ cy.setFilter('to_stage', 'Test stage 3');
+
+ cy.get('#transitionList')
+ .should('not.contain', 'Test transition 1')
+ .should('not.contain', 'Test transition 2')
+ .should('contain', 'Test transition 3');
+ });
+});
diff --git a/tests/System/integration/administrator/components/com_workflow/Workflow.cy.js b/tests/System/integration/administrator/components/com_workflow/Workflow.cy.js
new file mode 100644
index 0000000000000..e4d2ad1813252
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_workflow/Workflow.cy.js
@@ -0,0 +1,70 @@
+describe('Test in backend that the workflow form', () => {
+ before(() => cy.task('writeRelativeFile', { path: 'administrator/language/overrides/en-GB.override.ini', content: 'AUTOMATED_TEST_WORKFLOW="Test workflow translated"' }));
+ beforeEach(() => cy.doAdministratorLogin());
+ afterEach(() => {
+ cy.task('queryDB', "DELETE FROM #__workflow_stages WHERE workflow_id IN (SELECT id FROM #__workflows WHERE title = 'AUTOMATED_TEST_WORKFLOW')");
+ cy.task('queryDB', "DELETE FROM #__workflows WHERE title = 'AUTOMATED_TEST_WORKFLOW'");
+ });
+ after(() => cy.task('deleteRelativePath', 'administrator/language/overrides/en-GB.override.ini'));
+
+ it('can create a workflow', () => {
+ cy.visit('/administrator/index.php?option=com_workflow&task=workflow.add&extension=com_content.article');
+ cy.title().should('contain', 'Add Workflow');
+ cy.get('h1.page-title').should('contain', 'Add Workflow');
+ cy.get('#jform_title').clear().type('AUTOMATED_TEST_WORKFLOW');
+ cy.get('#jform_description').clear().type('automated test workflow');
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.title().should('contain', 'Edit Workflow');
+ cy.get('h1.page-title').should('contain', 'Edit Workflow');
+ cy.get('#jform_title').should('have.value', 'AUTOMATED_TEST_WORKFLOW');
+ cy.get('#workflow_title_translation').should('have.value', 'Test workflow translated');
+
+ cy.clickToolbarButton('Cancel');
+ cy.get('h1.page-title').should('contain', 'Workflows');
+
+ cy.get('table#workflowList').contains('Test workflow translated');
+ cy.get('table#workflowList').contains('automated test workflow');
+ });
+
+ it('can edit a workflow', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article', published: 0 }).then((workflow) => {
+ cy.visit(`/administrator/index.php?option=com_workflow&task=workflow.edit&extension=com_content.article&id=${workflow.id}`);
+ cy.get('h1.page-title').should('contain', 'Edit Workflow');
+ cy.get('#jform_published').find(':selected').should('contain', 'Disabled');
+ cy.get('#jform_published').select('Enabled');
+ cy.get('#jform_description').clear().type('edited workflow');
+ cy.clickToolbarButton('Save');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('#jform_published').find(':selected').should('contain', 'Enabled');
+ cy.clickToolbarButton('Save & Close');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('table#workflowList').contains('edited workflow');
+ });
+ });
+
+ it('can edit a workflow (list view)', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article' });
+ cy.visit('/administrator/index.php?option=com_workflow&view=workflows&extension=com_content.article');
+ cy.get('table#workflowList a').contains('Test workflow').click();
+ cy.get('h1.page-title').should('contain', 'Edit Workflow');
+ cy.get('#jform_title').clear().type('workflow title');
+ cy.get('#toolbar-dropdown-save-group .btn.btn-success.dropdown-toggle-split').click();
+ cy.clickToolbarButton('Save & New');
+
+ cy.checkForSystemMessage('Item saved.');
+ cy.get('h1.page-title').should('contain', 'Add Workflow');
+ });
+
+ it('redirects to the correct list view', () => {
+ cy.visit('/administrator/index.php?option=com_workflow&task=workflow.add&extension=com_content.article');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=workflows&extension=com_content.article').as('listview');
+ cy.clickToolbarButton('Cancel');
+
+ cy.wait('@listview');
+ cy.title().should('contain', 'Workflows');
+ });
+});
diff --git a/tests/System/integration/administrator/components/com_workflow/Workflows.cy.js b/tests/System/integration/administrator/components/com_workflow/Workflows.cy.js
new file mode 100644
index 0000000000000..b6851ca87fd7b
--- /dev/null
+++ b/tests/System/integration/administrator/components/com_workflow/Workflows.cy.js
@@ -0,0 +1,215 @@
+describe('Test in backend that the workflows list', () => {
+ beforeEach(() => {
+ cy.doAdministratorLogin();
+ cy.visit('/administrator/index.php?option=com_workflow&view=workflows&extension=com_content.article&filter=');
+ });
+ after(() => cy.task('queryDB', 'UPDATE #__workflows SET `default` = 1 WHERE id = 1'));
+
+ it('can display a list of workflows', () => {
+ cy.title().should('contain', 'Workflows');
+ cy.get('h1.page-title').should('contain', 'Workflows');
+ cy.contains('Basic Workflow');
+ });
+
+ it('can open the workflow form', () => {
+ cy.clickToolbarButton('New');
+
+ cy.title().should('contain', 'Add Workflow');
+ cy.contains('Add Workflow');
+ });
+
+ it('can enable the workflow', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article', published: 0 });
+ cy.reload();
+ cy.setFilter('published', 'Unpublished');
+ cy.searchForItem('Test workflow');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Publish');
+
+ cy.checkForSystemMessage('Workflow enabled.');
+ });
+
+ it('can disable the workflow', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article', published: 1 });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('Test workflow');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Unpublish');
+
+ cy.checkForSystemMessage('Workflow disabled.');
+ });
+
+ it('can trash the workflow', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article', published: 1 });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('Test workflow');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Trash');
+
+ cy.checkForSystemMessage('Workflow trashed.');
+ });
+
+ it('can delete the workflow', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article', published: -2 });
+ cy.reload();
+ cy.setFilter('published', 'Trashed');
+ cy.searchForItem('Test workflow');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Empty Trash');
+ cy.clickDialogConfirm(true);
+
+ cy.checkForSystemMessage('Workflow deleted.');
+ });
+
+ it('can checkin the workflow', () => {
+ cy.db_getUserId(Cypress.expose('username')).then((uid) => {
+ cy.db_createWorkflow({
+ title: 'Test workflow',
+ extension: 'com_content.article',
+ checked_out: uid,
+ checked_out_time: '2025-01-01 00:00:00',
+ });
+ cy.reload();
+ cy.searchForItem('Test workflow');
+ cy.checkAllResults();
+ cy.clickToolbarButton('Action');
+ cy.clickToolbarButton('Check-In');
+
+ cy.checkForSystemMessage('Workflow checked in.');
+ });
+ });
+
+ it('can enable the workflow (grid button)', () => {
+ cy.db_createWorkflow({
+ title: 'Test workflow',
+ extension: 'com_content.article',
+ published: 0,
+ description: 'workflow1',
+ });
+ cy.reload();
+ cy.setFilter('published', 'Unpublished');
+ cy.searchForItem('workflow1');
+ cy.get('table#workflowList .icon-unpublish').click();
+
+ cy.checkForSystemMessage('Workflow enabled.');
+ });
+
+ it('can disable the workflow (grid button)', () => {
+ cy.db_createWorkflow({
+ title: 'Test workflow',
+ extension: 'com_content.article',
+ published: 1,
+ description: 'workflow2',
+ });
+ cy.reload();
+ cy.setFilter('published', 'Published');
+ cy.searchForItem('workflow2');
+ cy.get('table#workflowList .icon-publish').click();
+
+ cy.checkForSystemMessage('Workflow disabled.');
+ });
+
+ it('can checkin the workflow (grid button)', () => {
+ cy.db_getUserId(Cypress.expose('username')).then((uid) => {
+ cy.db_createWorkflow({
+ title: 'Test workflow',
+ extension: 'com_content.article',
+ checked_out: uid,
+ checked_out_time: '2025-01-01 00:00:00',
+ });
+ cy.reload();
+ cy.searchForItem('Test workflow');
+ cy.get('table#workflowList .icon-checkedout').click();
+
+ cy.checkForSystemMessage('Workflow checked in.');
+ });
+ });
+
+ it('can set workflow as default (grid button)', () => {
+ cy.db_createWorkflow({ title: 'Test workflow', extension: 'com_content.article', default: 0 });
+ cy.reload();
+ cy.searchForItem('Test workflow');
+ cy.get('table#workflowList .icon-unfeatured').click();
+
+ cy.checkForSystemMessage('Workflow set as default.');
+ });
+
+ it('can filter state', () => {
+ cy.db_createWorkflow({ title: 'Test workflow 1', extension: 'com_content.article', published: 1 });
+ cy.db_createWorkflow({ title: 'Test workflow 2', extension: 'com_content.article', published: 0 });
+ cy.db_createWorkflow({ title: 'Test workflow 3', extension: 'com_content.article', published: -2 });
+ cy.reload();
+
+ cy.get('#workflowList')
+ .should('contain', 'Test workflow 1')
+ .should('contain', 'Test workflow 2')
+ .should('not.contain', 'Test workflow 3');
+
+ cy.setFilter('published', 'Published');
+
+ cy.get('#workflowList')
+ .should('contain', 'Test workflow 1')
+ .should('not.contain', 'Test workflow 2')
+ .should('not.contain', 'Test workflow 3');
+
+ cy.setFilter('published', 'Unpublished');
+
+ cy.get('#workflowList')
+ .should('not.contain', 'Test workflow 1')
+ .should('contain', 'Test workflow 2')
+ .should('not.contain', 'Test workflow 3');
+
+ cy.setFilter('published', 'Trashed');
+
+ cy.get('#workflowList')
+ .should('not.contain', 'Test workflow 1')
+ .should('not.contain', 'Test workflow 2')
+ .should('contain', 'Test workflow 3');
+ });
+
+ it('can open list of stages', () => {
+ cy.searchForItem('BASIC WORKFLOW');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=workflow*').as('workflows');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=stages*').as('stages');
+ cy.get('table#workflowList a.btn.btn-warning').click();
+
+ cy.wait('@stages');
+ cy.get('h1.page-title').should('contain', 'Stages: Basic Workflow');
+ cy.get('#toolbar-link').click();
+
+ cy.wait('@workflows');
+ cy.get('h1.page-title').should('contain', 'Workflows');
+ });
+
+ it('can open list of transitions', () => {
+ cy.searchForItem('BASIC WORKFLOW');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=workflow*').as('workflows');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=transitions*').as('transitions');
+ cy.get('table#workflowList a.btn[href*="view=transitions"]').click();
+
+ cy.wait('@transitions');
+ cy.get('h1.page-title').should('contain', 'Transitions: Basic Workflow');
+ cy.get('#toolbar-link').click();
+
+ cy.wait('@workflows');
+ cy.get('h1.page-title').should('contain', 'Workflows');
+ });
+
+ it('can visit options', () => {
+ cy.intercept('**/administrator/index.php?option=com_config&view=component&component=com_content*').as('options');
+ cy.intercept('**/administrator/index.php?option=com_workflow&view=workflow*').as('listview');
+
+ cy.clickToolbarButton('Options');
+ cy.wait('@options');
+ cy.get('h1.page-title').should('contain', 'Articles: Options');
+
+ cy.clickToolbarButton('Cancel');
+ cy.wait('@listview');
+ cy.get('h1.page-title').should('contain', 'Workflows');
+ });
+});
diff --git a/tests/System/integration/cli/Cache.cy.js b/tests/System/integration/cli/Cache.cy.js
index d8ae434ef4766..63486655b80cd 100644
--- a/tests/System/integration/cli/Cache.cy.js
+++ b/tests/System/integration/cli/Cache.cy.js
@@ -2,7 +2,7 @@ describe('Test that console command cache', () => {
it('can clean cache', () => {
const cachedFile = Cypress.expose('cmsPath') + 'administrator/cache/test.txt';
cy.task('writeRelativeFile', { path: 'administrator/cache/test.txt', content: 'test delete file from cache', mode: 0o666 });
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php cache:clean`)
+ cy.task('executeCli', { args: ['cache:clean'] })
.its('stdout')
.should('contain', 'Cache cleaned');
cy.readFile(cachedFile).should('not.exist');
diff --git a/tests/System/integration/cli/CheckExtensionsUpdates.cy.js b/tests/System/integration/cli/CheckExtensionsUpdates.cy.js
index 1855b883c8c39..92573ebf89cac 100644
--- a/tests/System/integration/cli/CheckExtensionsUpdates.cy.js
+++ b/tests/System/integration/cli/CheckExtensionsUpdates.cy.js
@@ -1,6 +1,6 @@
describe('Test that console command check extensions update', () => {
it('can check update', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php update:extensions:check`)
+ cy.task('executeCli', { args: ['update:extensions:check'] })
.its('stdout')
.should('contain', 'There are no updates available');
});
diff --git a/tests/System/integration/cli/Config.cy.js b/tests/System/integration/cli/Config.cy.js
index 7d3aaaa41a89b..3a18d1daa2b20 100644
--- a/tests/System/integration/cli/Config.cy.js
+++ b/tests/System/integration/cli/Config.cy.js
@@ -1,18 +1,18 @@
describe('Test that console command config', () => {
it('can get sitename', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:get sitename`)
+ cy.task('executeCli', { args: ['config:get', 'sitename'] })
.its('stdout')
.should('contain', Cypress.expose('sitename'));
});
it('can set sitename', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:set sitename="${Cypress.expose('sitename')}"`)
+ cy.task('executeCli', { args: ['config:set', `sitename="${Cypress.expose('sitename')}"`] })
.its('stdout')
.should('contain', '[OK] Configuration set');
});
it('can not set invalid database name', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:set db=invalid`, { failOnNonZeroExit: false }).then((result) => {
+ cy.task('executeCli', { args: ['config:set', 'db=invalid'], failOnNonZeroExit: false }).then((result) => {
cy.wrap(result).its('exitCode')
.should('equal', 4);
cy.wrap(result).its('stdout')
diff --git a/tests/System/integration/cli/ConfigGet.cy.js b/tests/System/integration/cli/ConfigGet.cy.js
index 3672488c2e8ae..95a0064a48631 100644
--- a/tests/System/integration/cli/ConfigGet.cy.js
+++ b/tests/System/integration/cli/ConfigGet.cy.js
@@ -1,6 +1,6 @@
describe('Test CLI command config:get', () => {
it('can get all configuration options', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:get`)
+ cy.task('executeCli', { args: ['config:get'] })
.then((result) => {
expect(result.stdout).to.contain('Option');
expect(result.stdout).to.contain('Value');
@@ -10,7 +10,7 @@ describe('Test CLI command config:get', () => {
});
it('can get database configuration group', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:get --group=db`)
+ cy.task('executeCli', { args: ['config:get', '--group=db'] })
.then((result) => {
// Check output contains expected database configuration options
expect(result.stdout).to.contain('Option');
@@ -30,7 +30,7 @@ describe('Test CLI command config:get', () => {
});
it('can get mail configuration group', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:get --group=mail`)
+ cy.task('executeCli', { args: ['config:get', '--group=mail'] })
.then((result) => {
// Check output contains expected mail configuration options
expect(result.stdout).to.contain('Option');
@@ -49,7 +49,7 @@ describe('Test CLI command config:get', () => {
});
it('can get session configuration group', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:get --group=session`)
+ cy.task('executeCli', { args: ['config:get', '--group=session'] })
.then((result) => {
// Check output contains expected session configuration options
expect(result.stdout).to.contain('Option');
@@ -65,8 +65,9 @@ describe('Test CLI command config:get', () => {
});
it('get error for non existent configuration group', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php config:get --group=test`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['config:get', '--group=test'], failOnNonZeroExit: false })
.then((result) => {
+ expect(result.exitCode).to.equal(1);
expect(result.stdout).to.contain('[ERROR] Group *test* not found');
});
});
diff --git a/tests/System/integration/cli/Extensions.cy.js b/tests/System/integration/cli/Extensions.cy.js
index 1e24d429415cd..ba4b617b669f7 100644
--- a/tests/System/integration/cli/Extensions.cy.js
+++ b/tests/System/integration/cli/Extensions.cy.js
@@ -1,24 +1,24 @@
describe('Test that console command extension', () => {
it('can disable an extension', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:disable 1`)
+ cy.task('executeCli', { args: ['extension:disable', '1'] })
.its('stdout')
.should('contain', '[OK] Component with ID of 1 com_wrapper disabled');
});
it('cannot disable a non existent extension', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:disable 2025`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['extension:disable', '2025'], failOnNonZeroExit: false })
.its('stdout')
.should('contain', '[ERROR] Extension with ID of 2025 not found');
});
it('can enable an extension', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:enable 1`)
+ cy.task('executeCli', { args: ['extension:enable', '1'] })
.its('stdout')
.should('contain', '[OK] Component with ID of 1 com_wrapper enabled');
});
it('cannot enable a non existent extension', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:enable 2025`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['extension:enable', '2025'], failOnNonZeroExit: false })
.its('stdout')
.should('contain', '[ERROR] Extension with ID of 2025 not found');
});
diff --git a/tests/System/integration/cli/ExtensionsList.cy.js b/tests/System/integration/cli/ExtensionsList.cy.js
index 6998eec321368..eb9feb4cb93ad 100644
--- a/tests/System/integration/cli/ExtensionsList.cy.js
+++ b/tests/System/integration/cli/ExtensionsList.cy.js
@@ -1,48 +1,48 @@
describe('Test that console command list extensions', () => {
it('can list extensions by type component', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=component`)
+ cy.task('executeCli', { args: ['extension:list', '--type=component'] })
.its('stdout')
.should('contain', 'com_admin');
});
it('can list extensions by type file', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=file`)
+ cy.task('executeCli', { args: ['extension:list', '--type=file'] })
.its('stdout')
.should('contain', 'files_joomla');
});
it('can list extensions by type language', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=language`)
+ cy.task('executeCli', { args: ['extension:list', '--type=language'] })
.its('stdout')
.should('contain', 'English (en-GB)');
});
it('can list extensions by type library', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=library`)
+ cy.task('executeCli', { args: ['extension:list', '--type=library'] })
.its('stdout')
.should('contain', 'lib_joomla');
});
it('can list extensions by type module', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=module`)
+ cy.task('executeCli', { args: ['extension:list', '--type=module'] })
.its('stdout')
.should('contain', 'mod_custom');
});
it('can list extensions by type package', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=package`)
+ cy.task('executeCli', { args: ['extension:list', '--type=package'] })
.its('stdout')
.should('contain', 'English (en-GB) Language Pack');
});
it('can list extensions by type plugin', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=plugin`)
+ cy.task('executeCli', { args: ['extension:list', '--type=plugin'] })
.its('stdout')
.should('contain', 'plg_authentication_joomla');
});
it('can list extensions by type template', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php extension:list --type=template`)
+ cy.task('executeCli', { args: ['extension:list', '--type=template'] })
.its('stdout')
.should('contain', 'cassiopeia');
});
diff --git a/tests/System/integration/cli/Finder.cy.js b/tests/System/integration/cli/Finder.cy.js
index 2feedf76b1f33..10e160b483f6a 100644
--- a/tests/System/integration/cli/Finder.cy.js
+++ b/tests/System/integration/cli/Finder.cy.js
@@ -1,11 +1,11 @@
describe('Test that console command finder', () => {
it('can index content', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php finder:index`)
+ cy.task('executeCli', { args: ['finder:index'] })
.its('stdout')
.should('contain', 'Total Processing Time');
});
it('can purge and index content', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php finder:index purge`)
+ cy.task('executeCli', { args: ['finder:index', 'purge'] })
.its('stdout')
.should('contain', 'Clear index')
.should('contain', 'Total Processing Time');
diff --git a/tests/System/integration/cli/Scheduler.cy.js b/tests/System/integration/cli/Scheduler.cy.js
index 9f39ce67665ab..f859801ed2496 100644
--- a/tests/System/integration/cli/Scheduler.cy.js
+++ b/tests/System/integration/cli/Scheduler.cy.js
@@ -1,42 +1,42 @@
describe('Test that console command scheduler', () => {
it('can list scheduled tasks', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:list`)
+ cy.task('executeCli', { args: ['scheduler:list'] })
.its('stdout')
.should('contain', 'Rotate Logs');
});
it('can update scheduled task state', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:state --id=1 --state=1 -n`)
+ cy.task('executeCli', { args: ['scheduler:state', '--id=1', '--state=1', '-n'] })
.its('stdout')
.should('contain', 'Task ID 1 enabled.');
});
it('cannot update state of non-existent task', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:state --id=123 --state=1 -n`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['scheduler:state', '--id=123', '--state=1', '-n'], failOnNonZeroExit: false })
.its('stdout')
.should('contain', "Task ID '123' does not exist!");
});
it('cannot update to non-existent state for a task', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:state --id=1 --state=123 -n`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['scheduler:state', '--id=1', '--state=123', '-n'], failOnNonZeroExit: false })
.its('stdout')
.should('contain', 'Invalid state passed!');
});
it('can run a task', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:run --id=1`)
+ cy.task('executeCli', { args: ['scheduler:run', '--id=1'] })
.its('stdout')
.should('contain', 'Task#01 \'Rotate Logs\' processed in');
});
it('cannot run a non existent task', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:run --id=123`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['scheduler:run', '--id=123'], failOnNonZeroExit: false })
.its('stdout')
.should('contain', 'No matching task found!');
});
it('cannot run a not due task', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php scheduler:run`, { failOnNonZeroExit: false })
+ cy.task('executeCli', { args: ['scheduler:run'], failOnNonZeroExit: false })
.its('stdout')
.should('contain', 'No tasks due!');
});
diff --git a/tests/System/integration/cli/Session.cy.js b/tests/System/integration/cli/Session.cy.js
index 87ba7ca8d0914..7c68cc67a37e7 100644
--- a/tests/System/integration/cli/Session.cy.js
+++ b/tests/System/integration/cli/Session.cy.js
@@ -1,11 +1,11 @@
describe('Test that console command session', () => {
it('can garbage collection', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php session:gc`)
+ cy.task('executeCli', { args: ['session:gc'] })
.its('stdout')
.should('contain', 'Garbage collection completed');
});
it('can metadata garbage collection', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php session:metadata:gc`)
+ cy.task('executeCli', { args: ['session:metadata:gc'] })
.its('stdout')
.should('contain', 'Metadata garbage collection completed');
});
diff --git a/tests/System/integration/cli/SiteUpDown.cy.js b/tests/System/integration/cli/SiteUpDown.cy.js
index 15880a47909c2..f6f274fe67dff 100644
--- a/tests/System/integration/cli/SiteUpDown.cy.js
+++ b/tests/System/integration/cli/SiteUpDown.cy.js
@@ -1,11 +1,11 @@
describe('Test that console command site', () => {
it('can set the site down', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php site:down`)
+ cy.task('executeCli', { args: ['site:down'] })
.its('stdout')
.should('contain', 'Website is now offline');
});
it('can set the site up', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php site:up`)
+ cy.task('executeCli', { args: ['site:up'] })
.its('stdout')
.should('contain', 'Website is now online');
});
diff --git a/tests/System/integration/cli/User.cy.js b/tests/System/integration/cli/User.cy.js
index 96644be95c04c..8837ae41eeabc 100644
--- a/tests/System/integration/cli/User.cy.js
+++ b/tests/System/integration/cli/User.cy.js
@@ -1,36 +1,36 @@
describe('Test that console command user', () => {
it('can list users', () => {
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php user:list`)
+ cy.task('executeCli', { args: ['user:list'] })
.its('stdout')
.should('contain', `${Cypress.expose('username')}`);
});
it('can add a user', () => {
- const para = '--username=test --name=test --password=123456789012 --email=test@530.test --usergroup=Manager -n';
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php user:add ${para}`)
+ const para = ['--username=test', '--name=test', '--password=123456789012', '--email=test@530.test', '--usergroup=Manager', '-n'];
+ cy.task('executeCli', { args: ['user:add', ...para] })
.its('stdout')
.should('contain', 'User created!');
});
it('can reset password', () => {
- const para = '--username=test --password=abcdefghilmno -n';
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php user:reset-password ${para}`)
+ const para = ['--username=test', '--password=abcdefghilmno', '-n'];
+ cy.task('executeCli', { args: ['user:reset-password', ...para] })
.its('stdout')
.should('contain', 'Password changed!');
});
it('can add a user to user group', () => {
- const para = '--username=test --group=Registered -n';
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php user:addtogroup ${para}`)
+ const para = ['--username=test', '--group=Registered', '-n'];
+ cy.task('executeCli', { args: ['user:addtogroup', ...para] })
.its('stdout')
.should('contain', "Added 'test' to group 'Registered'!");
});
it('can remove a user from user group', () => {
- const para = '--username=test --group=Registered -n';
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php user:removefromgroup ${para}`)
+ const para = ['--username=test', '--group=Registered', '-n'];
+ cy.task('executeCli', { args: ['user:removefromgroup', ...para] })
.its('stdout')
.should('contain', "Removed 'test' from group 'Registered'!");
});
it('can delete a user', () => {
- const para = '--username=test -n';
- cy.exec(`php ${Cypress.expose('cmsPath')}/cli/joomla.php user:delete ${para}`)
+ const para = ['--username=test', '-n'];
+ cy.task('executeCli', { args: ['user:delete', ...para] })
.its('stdout')
.should('contain', 'User test deleted!');
});
diff --git a/tests/System/integration/plugins/system/tasknotification/TaskNotification.cy.js b/tests/System/integration/plugins/system/tasknotification/TaskNotification.cy.js
index 94ec2cde0a9a8..993a71b3f5f9d 100644
--- a/tests/System/integration/plugins/system/tasknotification/TaskNotification.cy.js
+++ b/tests/System/integration/plugins/system/tasknotification/TaskNotification.cy.js
@@ -33,8 +33,9 @@ describe('Test that the task notification system plugin', () => {
expect(interception.response.body.message).to.eq(null);
expect(interception.response.body.success).to.eq(true);
});
- cy.get('joomla-dialog[type="inline"]').should('be.visible');
- cy.get('joomla-dialog[type="inline"]').within(() => {
+ cy.get('joomla-dialog[type="inline"] dialog').as('dialogContent');
+ cy.get('@dialogContent').should('be.visible');
+ cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', `Run Task (ID: ${task.id})`);
cy.get('div.scheduler-status').should('contain', 'Status: Completed');
});
@@ -68,8 +69,9 @@ describe('Test that the task notification system plugin', () => {
expect(interception.response.body.message).to.eq(null);
expect(interception.response.body.success).to.eq(true);
});
- cy.get('joomla-dialog[type="inline"]').should('be.visible');
- cy.get('joomla-dialog[type="inline"]').within(() => {
+ cy.get('joomla-dialog[type="inline"] dialog').as('dialogContent');
+ cy.get('@dialogContent').should('be.visible');
+ cy.get('@dialogContent').within(() => {
cy.get('header.joomla-dialog-header').should('contain', `Run Task (ID: ${task.id})`);
cy.get('div.scheduler-status').should('contain', 'Status: Completed');
});
diff --git a/tests/System/integration/site/components/com_content/Category.cy.js b/tests/System/integration/site/components/com_content/Category.cy.js
index 5ae782476b634..021f90bbad1d8 100644
--- a/tests/System/integration/site/components/com_content/Category.cy.js
+++ b/tests/System/integration/site/components/com_content/Category.cy.js
@@ -1,4 +1,10 @@
describe('Test in frontend that the content category view', () => {
+ afterEach(() => {
+ cy.db_updateExtensionParameter('filter_field', 'hide', 'com_content');
+ cy.db_updateExtensionParameter('list_show_author', '1', 'com_content');
+ cy.db_updateExtensionParameter('list_show_hits', '1', 'com_content');
+ });
+
['default', 'blog'].forEach((layout) => {
it(`can display a list of articles in the ${layout} layout in a menu item`, () => {
cy.db_createArticle({ title: 'article 1' })
@@ -38,6 +44,321 @@ describe('Test in frontend that the content category view', () => {
});
});
+ it('can use the title filter to narrow the article list', () => {
+ cy.db_createArticle({ title: 'article abc 1' })
+ .then((article) => cy.db_createArticle({ title: 'article def 2', catid: article.catid }))
+ .then((article) => cy.db_createArticle({ title: 'article abc 3', catid: article.catid }))
+ .then((article) => cy.db_createArticle({ title: 'article xyz 4', catid: article.catid }))
+ .then((article) => cy.db_createArticle({ title: 'article def 5', catid: article.catid }))
+ .then((article) => cy.db_createMenuItem({
+ title: 'automated test',
+ alias: 'automated-test',
+ path: 'automated-test',
+ link: `index.php?option=com_content&view=category&id=${article.catid}`,
+ params: {
+ filter_field: 'title',
+ list_show_author: '0',
+ },
+ }))
+ .then(() => {
+ cy.visit('/');
+ cy.get('a:contains(automated test)').click();
+ cy.get('main div.com-content-category.category-list').within(() => {
+ cy.get('table.com-content-category__table thead th').should('have.length', 2);
+ cy.get('table.com-content-category__table thead th').eq(0).should('contain.text', 'Title');
+ cy.get('table.com-content-category__table thead th').eq(1).should('contain.text', 'Hits');
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article abc 1')
+ .should('contain.text', 'article def 2')
+ .should('contain.text', 'article abc 3')
+ .should('contain.text', 'article xyz 4')
+ .should('contain.text', 'article def 5');
+
+ cy.get('#filter-search').should('have.attr', 'placeholder', 'Title Filter');
+ cy.get('#filter-search').clear().type('abc');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article abc 1')
+ .should('not.contain.text', 'article def 2')
+ .should('contain.text', 'article abc 3')
+ .should('not.contain.text', 'article xyz 4')
+ .should('not.contain.text', 'article def 5');
+
+ cy.get('#filter-search').clear().type('xyz');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article abc 1')
+ .should('not.contain.text', 'article def 2')
+ .should('not.contain.text', 'article abc 3')
+ .should('contain.text', 'article xyz 4')
+ .should('not.contain.text', 'article def 5');
+
+ cy.get('#filter-search').clear().type('def');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article abc 1')
+ .should('contain.text', 'article def 2')
+ .should('not.contain.text', 'article abc 3')
+ .should('not.contain.text', 'article xyz 4')
+ .should('contain.text', 'article def 5');
+
+ cy.get('.com-content__filter button[type="reset"]').click();
+ cy.get('#filter-search').should('have.value', '');
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article abc 1')
+ .should('contain.text', 'article def 2')
+ .should('contain.text', 'article abc 3')
+ .should('contain.text', 'article xyz 4')
+ .should('contain.text', 'article def 5');
+ });
+ });
+ });
+
+ it('can use the author filter to narrow the article list', () => {
+ cy.db_createArticle({ title: 'article 1', created_by_alias: 'James' })
+ .then((article) => cy.db_createArticle({ title: 'article 2', catid: article.catid, created_by_alias: 'William' }))
+ .then((article) => cy.db_createArticle({ title: 'article 3', catid: article.catid, created_by_alias: 'Emma' }))
+ .then((article) => {
+ cy.db_createUser({ name: 'Emma' }).then((id) => {
+ cy.db_createArticle({ title: 'article 4', catid: article.catid, created_by: id });
+ cy.db_createArticle({ title: 'article 5', catid: article.catid, created_by: id, created_by_alias: 'Charlotte' });
+ });
+ })
+ .then((article) => cy.db_createMenuItem({
+ title: 'automated test',
+ alias: 'automated-test',
+ path: 'automated-test',
+ link: `index.php?option=com_content&view=category&id=${article.catid}`,
+ params: {
+ filter_field: '',
+ list_show_date: 'published',
+ },
+ }))
+ .then(() => {
+ cy.db_updateExtensionParameter('filter_field', 'author', 'com_content');
+ cy.db_updateExtensionParameter('list_show_hits', '0', 'com_content');
+ cy.visit('/');
+ cy.get('a:contains(automated test)').click();
+ cy.get('main div.com-content-category.category-list').within(() => {
+ cy.get('table.com-content-category__table thead th').should('have.length', 3);
+ cy.get('table.com-content-category__table thead th').eq(0).should('contain.text', 'Title');
+ cy.get('table.com-content-category__table thead th').eq(1).should('contain.text', 'Published Date');
+ cy.get('table.com-content-category__table thead th').eq(2).should('contain.text', 'Author');
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+
+ cy.get('#filter-search').should('have.attr', 'placeholder', 'Author Filter');
+ cy.get('#filter-search').clear().type('william');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('not.contain.text', 'article 3')
+ .should('not.contain.text', 'article 4')
+ .should('not.contain.text', 'article 5');
+
+ cy.get('#filter-search').clear().type('James');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('not.contain.text', 'article 2')
+ .should('not.contain.text', 'article 3')
+ .should('not.contain.text', 'article 4')
+ .should('not.contain.text', 'article 5');
+
+ cy.get('#filter-search').clear().type('Charlotte');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('not.contain.text', 'article 2')
+ .should('not.contain.text', 'article 3')
+ .should('not.contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+
+ cy.get('#filter-search').clear().type('emma');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('not.contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('not.contain.text', 'article 5');
+
+ cy.get('.com-content__filter button[type="reset"]').click();
+ cy.get('#filter-search').should('have.value', '');
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+ });
+ });
+ });
+
+ it('can use the tag filter to narrow the article list', () => {
+ cy.db_createArticle({ title: 'article 1' })
+ .then((article) => {
+ cy.db_createTag({ title: 'tag1' }).then((id) => {
+ cy.db_createArticle({ title: 'article 2', catid: article.catid, tags: [id] });
+ cy.db_createArticle({ title: 'article 3', catid: article.catid, tags: [id] });
+ });
+ })
+ .then((article) => {
+ cy.db_createTag({ title: 'tag2' }).then((id) => {
+ cy.db_createArticle({ title: 'article 4', catid: article.catid, tags: [id] });
+ cy.db_createArticle({ title: 'article 5', catid: article.catid, tags: [id] });
+ });
+ })
+ .then((article) => cy.db_createMenuItem({
+ title: 'automated test',
+ alias: 'automated-test',
+ path: 'automated-test',
+ link: `index.php?option=com_content&view=category&id=${article.catid}`,
+ params: {
+ filter_field: 'tag',
+ },
+ }))
+ .then(() => {
+ cy.visit('/');
+ cy.get('a:contains(automated test)').click();
+ cy.get('main div.com-content-category.category-list').within(() => {
+ cy.get('table.com-content-category__table thead th').should('have.length', 3);
+ cy.get('table.com-content-category__table thead th').eq(0).should('contain.text', 'Title');
+ cy.get('table.com-content-category__table thead th').eq(1).should('contain.text', 'Author');
+ cy.get('table.com-content-category__table thead th').eq(2).should('contain.text', 'Hits');
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+
+ cy.get('#filter-search').select('tag1');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('not.contain.text', 'article 4')
+ .should('not.contain.text', 'article 5');
+
+ cy.get('#filter-search').select('tag2');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('not.contain.text', 'article 2')
+ .should('not.contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+
+ cy.get('.com-content__filter button[type="reset"]').click();
+ cy.get('#filter-search').should('have.value', '');
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+ });
+ });
+ });
+
+ it('can use the month filter to narrow the article list', () => {
+ cy.db_createArticle({ title: 'article 1', publish_up: '2026-08-17 20:00:00' })
+ .then((article) => cy.db_createArticle({ title: 'article 2', catid: article.catid, publish_up: '2026-08-28 20:00:00' }))
+ .then((article) => cy.db_createArticle({ title: 'article 3', catid: article.catid, publish_up: '2026-05-20 20:00:00' }))
+ .then((article) => cy.db_createArticle({ title: 'article 4', catid: article.catid, publish_up: '2026-05-25 20:00:00' }))
+ .then((article) => cy.db_createArticle({ title: 'article 5', catid: article.catid, publish_up: '2025-08-17 20:00:00' }))
+ .then((article) => cy.db_createMenuItem({
+ title: 'automated test',
+ alias: 'automated-test',
+ path: 'automated-test',
+ link: `index.php?option=com_content&view=category&id=${article.catid}`,
+ params: {
+ filter_field: 'month',
+ list_show_date: 'modified',
+ list_show_hits: '0',
+ },
+ }))
+ .then(() => {
+ cy.db_updateExtensionParameter('filter_field', 'hits', 'com_content');
+ cy.db_updateExtensionParameter('list_show_author', '0', 'com_content');
+ cy.visit('/');
+ cy.get('a:contains(automated test)').click();
+ cy.get('main div.com-content-category.category-list').within(() => {
+ cy.get('table.com-content-category__table thead th').should('have.length', 2);
+ cy.get('table.com-content-category__table thead th').eq(0).should('contain.text', 'Title');
+ cy.get('table.com-content-category__table thead th').eq(1).should('contain.text', 'Modified Date');
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+
+ cy.get('#filter-search').select('2026-08-01');
+ cy.get('#filter-search option:selected').should('have.text', 'August 2026 [2]');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('not.contain.text', 'article 3')
+ .should('not.contain.text', 'article 4')
+ .should('not.contain.text', 'article 5');
+
+ cy.get('#filter-search').select('2025-08-01');
+ cy.get('#filter-search option:selected').should('have.text', 'August 2025 [1]');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('not.contain.text', 'article 2')
+ .should('not.contain.text', 'article 3')
+ .should('not.contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+
+ cy.get('#filter-search').select('2026-05-01');
+ cy.get('#filter-search option:selected').should('have.text', 'May 2026 [2]');
+ cy.get('.com-content__filter button[type="submit"]').click();
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('not.contain.text', 'article 1')
+ .should('not.contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('not.contain.text', 'article 5');
+
+ cy.get('.com-content__filter button[type="reset"]').click();
+ cy.get('#filter-search').should('have.value', '');
+
+ cy.get('table.com-content-category__table tbody th a')
+ .should('contain.text', 'article 1')
+ .should('contain.text', 'article 2')
+ .should('contain.text', 'article 3')
+ .should('contain.text', 'article 4')
+ .should('contain.text', 'article 5');
+ });
+ });
+ });
+
it('can open the article form in the default layout', () => {
cy.db_createArticle({ title: 'article 1' })
.then((article) => cy.db_createMenuItem({
diff --git a/tests/System/plugins/cli.mjs b/tests/System/plugins/cli.mjs
new file mode 100644
index 0000000000000..a7faca263577b
--- /dev/null
+++ b/tests/System/plugins/cli.mjs
@@ -0,0 +1,49 @@
+import { execFileSync } from 'node:child_process';
+
+/**
+ * Executes the CLI application and returns the command result
+ *
+ * @param {object} [options={}] - The execution options
+ * @param {string[]} [options.args=[]] - Command arguments to pass to the CLI
+ * @param {boolean} [options.failOnNonZeroExit=true] - Whether to throw an error on non-zero exit codes
+ * @param {object} config - The Cypress configuration object
+ *
+ * @returns {object} - An object containing the command output, error output and exit code
+ * @returns {number} returns.exitCode - The exit code of the CLI command
+ * @returns {string} returns.stdout - The standard output of the command
+ * @returns {string|null} returns.stderr - The standard error output of the command, or null on success
+ *
+ * @throws {Error} - If failOnNonZeroExit is true and the command exits with a non-zero code
+ */
+function executeCli(options = {}, config) {
+ const {
+ args = [],
+ failOnNonZeroExit = true,
+ } = options;
+
+ try {
+ const output = execFileSync(
+ 'php',
+ [`${config.expose.cmsPath}/cli/joomla.php`, ...args, '--no-ansi'],
+ { encoding: 'utf8' },
+ );
+
+ return {
+ exitCode: 0,
+ stdout: output,
+ stderr: null,
+ };
+ } catch (error) {
+ if (failOnNonZeroExit) {
+ throw new Error(`CLI command failed with exit code ${error.status}\n${error.stderr.trim()}\n${error.stdout.trim()}`);
+ }
+
+ return {
+ exitCode: error.status,
+ stdout: error.stdout,
+ stderr: error.stderr,
+ };
+ }
+}
+
+export { executeCli };
diff --git a/tests/System/plugins/db.mjs b/tests/System/plugins/db.mjs
index e57200820ebf1..d77a16553a20a 100644
--- a/tests/System/plugins/db.mjs
+++ b/tests/System/plugins/db.mjs
@@ -170,6 +170,7 @@ function deleteInsertedItems(config) {
if (item.table === `${config.expose.db_prefix}content`) {
promises.push(queryTestDB(`DELETE FROM #__content_frontpage WHERE content_id IN (${item.rows.join(',')})`, config));
+ promises.push(queryTestDB(`DELETE FROM #__contentitem_tag_map WHERE content_item_id IN (${item.rows.join(',')}) AND type_alias = 'com_content.article'`, config));
promises.push(queryTestDB(`DELETE FROM #__workflow_associations WHERE item_id IN (${item.rows.join(',')}) AND extension = 'com_content.article'`, config));
}
diff --git a/tests/System/plugins/index.mjs b/tests/System/plugins/index.mjs
index 2b558ec085853..346dc2e23bd92 100644
--- a/tests/System/plugins/index.mjs
+++ b/tests/System/plugins/index.mjs
@@ -2,6 +2,7 @@ import { getMails, clearEmails, startMailServer } from './mail.mjs';
import { writeRelativeFile, deleteRelativePath, copyRelativeFile } from './fs.mjs';
import { queryTestDB, deleteInsertedItems } from './db.mjs';
import { checkForLogs, clearLogs } from './logs.mjs';
+import { executeCli } from './cli.mjs';
/**
* Does the setup of the plugins.
@@ -23,5 +24,6 @@ export default function setupPlugins(on, config) {
getMails: () => getMails(),
clearEmails: () => clearEmails(),
startMailServer: () => startMailServer(config),
+ executeCli: (options) => executeCli(options, config),
});
}
diff --git a/tests/System/support/commands/db.mjs b/tests/System/support/commands/db.mjs
index 0cac699a380f3..e3c9512e8505a 100644
--- a/tests/System/support/commands/db.mjs
+++ b/tests/System/support/commands/db.mjs
@@ -113,6 +113,9 @@ Cypress.Commands.add('db_createArticle', (articleData) => {
metadata: '',
};
+ const tags = articleData.tags ?? [];
+ delete articleData.tags;
+
const article = { ...defaultArticleOptions, ...articleData };
return getDefaultCategoryId('com_content')
@@ -128,6 +131,9 @@ Cypress.Commands.add('db_createArticle', (articleData) => {
if (article.featured === 1) {
await cy.task('queryDB', `INSERT INTO #__content_frontpage (content_id, ordering) VALUES ('${article.id}', '1')`);
}
+ tags.forEach(async (tag) => {
+ await cy.task('queryDB', `INSERT INTO #__contentitem_tag_map (type_alias, core_content_id, content_item_id, tag_id, tag_date, type_id) VALUES ('com_content.article', '0', '${article.id}', '${tag}', '2026-08-29 11:00:00', '1')`);
+ });
await cy.task('queryDB', `INSERT INTO #__workflow_associations (item_id, stage_id, extension) VALUES (${article.id}, 1, 'com_content.article')`);
return article;
@@ -504,6 +510,11 @@ Cypress.Commands.add('db_createMenuItem', (menuItemData) => {
defaultMenuItemOptions.rgt = myrgt[0].rgt + 1;
const menuItem = { ...defaultMenuItemOptions, ...menuItemData };
+ ['params'].forEach((key) => {
+ if (typeof menuItem[key] === 'object') {
+ menuItem[key] = JSON.stringify(menuItem[key]);
+ }
+ });
// Extract the component from the link
const component = (new URLSearchParams(menuItem.link.replace('index.php', ''))).get('option');
return cy.task('queryDB', `SELECT extension_id FROM #__extensions WHERE name = '${component}'`).then((id) => {
@@ -673,6 +684,103 @@ Cypress.Commands.add('db_createSchedulerTask', (taskData) => {
});
});
+/**
+ * Creates a workflow in the database with the given data. The workflow contains some default values when
+ * not all required fields are passed in the given data. The data of the inserted workflow is returned.
+ *
+ * @param {Object} workflowData The workflow data to insert
+ *
+ * @returns Object
+ */
+Cypress.Commands.add('db_createWorkflow', (workflowData) => {
+ const defaultWorkflowOptions = {
+ published: 1,
+ title: 'test workflow',
+ description: '',
+ extension: 'com_content.article',
+ default: 0,
+ created: '2026-01-15 18:00:00',
+ modified: '2026-01-15 18:00:00',
+ };
+ const workflow = { ...defaultWorkflowOptions, ...workflowData };
+
+ return cy.task('queryDB', createInsertQuery('workflows', workflow))
+ .then((info) => {
+ workflow.id = info.insertId;
+
+ if (workflow.default === 1) {
+ return cy.task('queryDB', `UPDATE #__workflows SET \`default\` = 0 WHERE id <> '${workflow.id}'`)
+ .then(() => workflow);
+ }
+
+ return workflow;
+ });
+});
+
+/**
+ * Creates a stage of a workflow in the database with the given data. The stage contains some default values when
+ * not all required fields are passed in the given data. The data of the inserted stage is returned.
+ *
+ * @param {Object} stageData The stage data to insert
+ *
+ * @returns Object
+ */
+Cypress.Commands.add('db_createWorkflowStage', (stageData) => {
+ const defaultStageOptions = {
+ workflow_id: 1,
+ published: 1,
+ title: '',
+ description: '',
+ default: 0,
+ };
+ const stage = { ...defaultStageOptions, ...stageData };
+
+ return cy.task('queryDB', createInsertQuery('workflow_stages', stage))
+ .then((info) => {
+ stage.id = info.insertId;
+
+ if (stage.default === 1) {
+ return cy.task('queryDB', `UPDATE #__workflow_stages SET \`default\` = 0 WHERE id <> '${stage.id}' AND workflow_id = '${stage.workflow_id}'`)
+ .then(() => stage);
+ }
+
+ return stage;
+ });
+});
+
+/**
+ * Creates a transition of a workflow in the database with the given data. The transition contains some default values when
+ * not all required fields are passed in the given data. The data of the inserted transition is returned.
+ *
+ * @param {Object} transitionData The transition data to insert
+ *
+ * @returns Object
+ */
+Cypress.Commands.add('db_createWorkflowTransition', (transitionData) => {
+ const defaultTransitionOptions = {
+ workflow_id: 1,
+ published: 1,
+ title: '',
+ description: '',
+ from_stage_id: -1,
+ to_stage_id: 1,
+ options: '{}',
+ };
+ const transition = { ...defaultTransitionOptions, ...transitionData };
+ ['options'].forEach((key) => {
+ if (typeof transition[key] === 'object') {
+ transition[key] = JSON.stringify(transition[key]);
+ }
+ });
+
+ return cy.task('queryDB', createInsertQuery('workflow_transitions', transition))
+ .then((info) => {
+ transition.id = info.insertId;
+
+ return transition;
+ });
+});
+
/**
* Sets the parameter for the given extension.
*
diff --git a/tests/Unit/Component/Actionlogs/Administrator/Model/ActionlogConfigModelTest.php b/tests/Unit/Component/Actionlogs/Administrator/Model/ActionlogConfigModelTest.php
index b7321d5587b30..842ac961b10e3 100644
--- a/tests/Unit/Component/Actionlogs/Administrator/Model/ActionlogConfigModelTest.php
+++ b/tests/Unit/Component/Actionlogs/Administrator/Model/ActionlogConfigModelTest.php
@@ -14,6 +14,7 @@
use Joomla\Component\Actionlogs\Administrator\Model\ActionlogConfigModel;
use Joomla\Database\DatabaseInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for ActionlogConfigModel
@@ -25,12 +26,11 @@
class ActionlogConfigModelTest extends UnitTestCase
{
/**
- * @testdox Test that getLogContentTypeParams returns the correct params
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('Test that getLogContentTypeParams returns the correct params')]
public function testGetLogContentTypeParams()
{
$config = new \stdClass();
@@ -40,16 +40,15 @@ public function testGetLogContentTypeParams()
$model = new ActionlogConfigModel(['dbo' => $db], $this->createStub(MVCFactoryInterface::class));
- $this->assertEquals($config, $model->getLogContentTypeParams('test'));
+ $this->assertSame($config, $model->getLogContentTypeParams('test'));
}
/**
- * @testdox Test that getLogContentTypeParams returns null when not found
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('Test that getLogContentTypeParams returns null when not found')]
public function testGetNullLogContentTypeParams()
{
$db = $this->createStub(DatabaseInterface::class);
diff --git a/tests/Unit/Component/Finder/Administrator/Indexer/ResultTest.php b/tests/Unit/Component/Finder/Administrator/Indexer/ResultTest.php
index 8964c7357c7f7..ee3013266c836 100644
--- a/tests/Unit/Component/Finder/Administrator/Indexer/ResultTest.php
+++ b/tests/Unit/Component/Finder/Administrator/Indexer/ResultTest.php
@@ -12,12 +12,17 @@
use Joomla\Component\Finder\Administrator\Indexer\Result;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\CoversMethod;
/**
* Test class for \Joomla\Component\Finder\Administrator\Indexer\Result
*
* @since 4.1.3
*/
+#[CoversMethod(Result::class, 'unserialize')]
+#[CoversMethod(Result::class, 'serialize')]
+#[CoversMethod(Result::class, '__serialize')]
+#[CoversMethod(Result::class, '__unserialize')]
class ResultTest extends UnitTestCase
{
/**
@@ -25,11 +30,6 @@ class ResultTest extends UnitTestCase
*
* @throws \ReflectionException
*
- * @covers Result::unserialize
- * @covers Result::serialize
- * @covers Result::__serialize
- * @covers Result::__unserialize
- *
* @since 4.1.3
*/
public function testSerialize(): void
@@ -45,13 +45,13 @@ public function testSerialize(): void
);
// Test PHP `serialize` the object - PHP 8.1+ style (uses magic methods)
- $this->assertEquals(
+ $this->assertSame(
'that',
unserialize(serialize($obj))->getElement('this')
);
$obj->title = 'MyTitle2';
- $this->assertEquals(
+ $this->assertSame(
'MyTitle2',
unserialize(serialize($obj))->title
);
diff --git a/tests/Unit/Libraries/Cms/Access/RuleTest.php b/tests/Unit/Libraries/Cms/Access/RuleTest.php
index 6439f08f8794c..0dec73fada281 100644
--- a/tests/Unit/Libraries/Cms/Access/RuleTest.php
+++ b/tests/Unit/Libraries/Cms/Access/RuleTest.php
@@ -38,7 +38,7 @@ public function testIsConstructableWithString()
// Test constructor with array.
$rule = new Rule(json_encode($ruleData));
- $this->assertEquals($ruleData, $rule->getData());
+ $this->assertSame($ruleData, $rule->getData());
}
/**
@@ -59,7 +59,7 @@ public function testIsConstructableWithArray()
// Test constructor with array.
$rule = new Rule($ruleData);
- $this->assertEquals($ruleData, $rule->getData());
+ $this->assertSame($ruleData, $rule->getData());
}
/**
@@ -76,15 +76,15 @@ public function testMergeIdentity()
// Add the identity with allow.
$rule->mergeIdentity(-42, true);
- $this->assertEquals('{"-42":1}', (string) $rule);
+ $this->assertSame('{"-42":1}', (string) $rule);
// Read the identity, but deny.
$rule->mergeIdentity(-42, false);
- $this->assertEquals('{"-42":0}', (string) $rule);
+ $this->assertSame('{"-42":0}', (string) $rule);
// Read the identity with allow (checking deny wins).
$rule->mergeIdentity(-42, true);
- $this->assertEquals('{"-42":0}', (string) $rule);
+ $this->assertSame('{"-42":0}', (string) $rule);
}
/**
@@ -106,13 +106,13 @@ public function testMergeIdentities()
$rule = new Rule('');
$rule->mergeIdentities($ruleData);
- $this->assertEquals(json_encode($ruleData), (string) $rule);
+ $this->assertSame(json_encode($ruleData), (string) $rule);
$rule2 = new Rule($ruleData);
$rule->mergeIdentities($rule2);
- $this->assertEquals(json_encode($ruleData), (string) $rule);
+ $this->assertSame(json_encode($ruleData), (string) $rule);
- $this->assertEquals((string) $rule2, (string) $rule);
+ $this->assertSame((string) $rule2, (string) $rule);
// Merge a new set, flipping some bits.
$ruleData2 = [
@@ -130,7 +130,7 @@ public function testMergeIdentities()
4 => 1,
];
$rule->mergeIdentities($ruleData2);
- $this->assertEquals(json_encode($expectedResult), (string) $rule);
+ $this->assertSame(json_encode($expectedResult), (string) $rule);
}
/**
@@ -151,13 +151,12 @@ public function testAllow()
// This one should be denied.
$this->assertFalse($rule->allow(-42));
- $this->assertEquals(null, $rule->allow(null));
+ $this->assertSame(null, $rule->allow(null));
$this->assertTrue($rule->allow(2));
$this->assertFalse($rule->allow([-42, 2]));
}
/**
- *
* @return void
* @since 4.0.0
*/
@@ -170,6 +169,6 @@ public function testToString()
$rule = new Rule($ruleData);
- $this->assertEquals(json_encode($ruleData), (string) $rule);
+ $this->assertSame(json_encode($ruleData), (string) $rule);
}
}
diff --git a/tests/Unit/Libraries/Cms/Access/RulesTest.php b/tests/Unit/Libraries/Cms/Access/RulesTest.php
index 8f8266ba27c55..fd4866f7cc0a0 100644
--- a/tests/Unit/Libraries/Cms/Access/RulesTest.php
+++ b/tests/Unit/Libraries/Cms/Access/RulesTest.php
@@ -22,7 +22,6 @@
class RulesTest extends UnitTestCase
{
/**
- *
* @return void
* @since 4.0.0
*/
@@ -43,11 +42,10 @@ public function testIsConstructableWithInputString()
$editRule = $rules->getData()['edit'];
$this->assertInstanceOf(Rule::class, $editRule);
- $this->assertEquals($ruleIdentities, $editRule->getData());
+ $this->assertSame($ruleIdentities, $editRule->getData());
}
/**
- *
* @return void
* @since 4.0.0
*/
@@ -67,7 +65,7 @@ public function testIsConstructableWithArray()
$editRule = $rules->getData()['edit'];
$this->assertInstanceOf(Rule::class, $editRule);
- $this->assertEquals($ruleIdentities, $editRule->getData());
+ $this->assertSame($ruleIdentities, $editRule->getData());
}
/**
@@ -93,7 +91,7 @@ public function testIsConstructableWithObject()
$editRule = $rules->getData()['edit'];
$this->assertInstanceOf(Rule::class, $editRule);
- $this->assertEquals($ruleIdentities, $editRule->getData());
+ $this->assertSame($ruleIdentities, $editRule->getData());
}
/**
@@ -117,7 +115,7 @@ public function testMergeAction()
$editRule = $rules->getData()['edit'];
$this->assertInstanceOf(Rule::class, $editRule);
- $this->assertEquals($ruleIdentities, $editRule->getData());
+ $this->assertSame($ruleIdentities, $editRule->getData());
// Merge a new set, flipping some bits.
// Ident 3 should remain false, 4 should be added.
@@ -130,7 +128,7 @@ public function testMergeAction()
$rules->mergeAction('edit', $newRuleIdentities);
$editRule = $rules->getData()['edit'];
- $this->assertEquals(
+ $this->assertSame(
[
-42 => 0,
2 => 1,
@@ -192,9 +190,9 @@ public function testMerge()
$this->assertInstanceOf(Rule::class, $editRule);
$this->assertInstanceOf(Rule::class, $deleteRule);
$this->assertInstanceOf(Rule::class, $createRule);
- $this->assertEquals($expectedResult['edit'], $editRule->getData());
- $this->assertEquals($expectedResult['delete'], $deleteRule->getData());
- $this->assertEquals($expectedResult['create'], $createRule->getData());
+ $this->assertSame($expectedResult['edit'], $editRule->getData());
+ $this->assertSame($expectedResult['delete'], $deleteRule->getData());
+ $this->assertSame($expectedResult['create'], $createRule->getData());
}
/**
@@ -224,8 +222,8 @@ public function testMergeRulesNull()
$this->assertInstanceOf(Rule::class, $editRule);
$this->assertInstanceOf(Rule::class, $deleteRule);
- $this->assertEquals($ruleData['edit'], $editRule->getData());
- $this->assertEquals($ruleData['delete'], $deleteRule->getData());
+ $this->assertSame($ruleData['edit'], $editRule->getData());
+ $this->assertSame($ruleData['delete'], $deleteRule->getData());
}
/**
@@ -278,9 +276,9 @@ public function testMergeRules()
$this->assertInstanceOf(Rule::class, $editRule);
$this->assertInstanceOf(Rule::class, $deleteRule);
$this->assertInstanceOf(Rule::class, $createRule);
- $this->assertEquals($expectedResult['edit'], $editRule->getData());
- $this->assertEquals($expectedResult['delete'], $deleteRule->getData());
- $this->assertEquals($expectedResult['create'], $createRule->getData());
+ $this->assertSame($expectedResult['edit'], $editRule->getData());
+ $this->assertSame($expectedResult['delete'], $deleteRule->getData());
+ $this->assertSame($expectedResult['create'], $createRule->getData());
}
/**
@@ -346,7 +344,6 @@ public function testGetAllowed()
}
/**
- *
* @return void
* @since 4.0.0
*/
@@ -367,6 +364,6 @@ public function testToString()
$rules = new Rules($ruleData);
- $this->assertEquals(json_encode($ruleData), (string) $rules);
+ $this->assertSame(json_encode($ruleData), (string) $rules);
}
}
diff --git a/tests/Unit/Libraries/Cms/Application/ConsoleApplicationTest.php b/tests/Unit/Libraries/Cms/Application/ConsoleApplicationTest.php
index 9ede0ff0c00d1..f2eeacf16b6aa 100644
--- a/tests/Unit/Libraries/Cms/Application/ConsoleApplicationTest.php
+++ b/tests/Unit/Libraries/Cms/Application/ConsoleApplicationTest.php
@@ -16,23 +16,23 @@
use Joomla\Event\DispatcherInterface;
use Joomla\Registry\Registry;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ConsoleApplicationTest extends UnitTestCase
{
/**
- * @testdox Test that the ConsoleApplication can init and has the right name
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that the ConsoleApplication can init and has the right name')]
public function testAppInitialisesByName()
{
$app = $this->createApplication();
$this->assertSame('cli', $app->getName());
- $this->assertSame(true, $app->isClient('cli'));
+ $this->assertTrue($app->isClient('cli'));
}
/**
@@ -44,12 +44,12 @@ public function testAppInitialisesByName()
*/
protected function createApplication(): ConsoleApplication
{
- $config = $this->createMock(Registry::class);
- $dispatcher = $this->createMock(DispatcherInterface::class);
- $container = $this->createMock(Container::class);
- $language = $this->createMock(Language::class);
- $input = $this->createMock(InputInterface::class);
- $output = $this->createMock(OutputInterface::class);
+ $config = $this->createStub(Registry::class);
+ $dispatcher = $this->createStub(DispatcherInterface::class);
+ $container = $this->createStub(Container::class);
+ $language = $this->createStub(Language::class);
+ $input = $this->createStub(InputInterface::class);
+ $output = $this->createStub(OutputInterface::class);
$object = new ConsoleApplication($config, $dispatcher, $container, $language, $input, $output);
diff --git a/tests/Unit/Libraries/Cms/Cache/CacheControllerFactoryAwareTraitTest.php b/tests/Unit/Libraries/Cms/Cache/CacheControllerFactoryAwareTraitTest.php
index 5f45b2b933f2e..ba0984a2361fb 100644
--- a/tests/Unit/Libraries/Cms/Cache/CacheControllerFactoryAwareTraitTest.php
+++ b/tests/Unit/Libraries/Cms/Cache/CacheControllerFactoryAwareTraitTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Cache\CacheControllerFactory;
use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Cache\CacheControllerFactoryAwareTrait
@@ -20,19 +21,17 @@
* @package Joomla.UnitTest
* @subpackage Cache
*
- * @testdoc The CacheControllerFactoryAwareTrait
- *
* @since 4.2.0
*/
+#[TestDox('The CacheControllerFactoryAwareTrait')]
class CacheControllerFactoryAwareTraitTest extends UnitTestCase
{
/**
- * @testdox can set a cache controller factory
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can set a cache controller factory')]
public function testGetCacheControllerFactory()
{
$cacheControllerFactory = new CacheControllerFactory();
@@ -48,6 +47,6 @@ public function getFactory(): CacheControllerFactory
$trait->setCacheControllerFactory($cacheControllerFactory);
- $this->assertEquals($cacheControllerFactory, $trait->getFactory());
+ $this->assertSame($cacheControllerFactory, $trait->getFactory());
}
}
diff --git a/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverCommandTest.php b/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverCommandTest.php
index e8e4cd59532d9..247f021cc30eb 100644
--- a/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverCommandTest.php
+++ b/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverCommandTest.php
@@ -41,7 +41,7 @@ public function testIsConstructable()
*/
public function testProcessDiscoverReturnIsInt()
{
- $command = $this->createMock(ExtensionDiscoverCommand::class);
+ $command = $this->createStub(ExtensionDiscoverCommand::class);
$countOfDiscoveredExtensions = $command->processDiscover();
diff --git a/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverInstallCommandTest.php b/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverInstallCommandTest.php
index 317f071f9dc96..d7322ed575577 100644
--- a/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverInstallCommandTest.php
+++ b/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverInstallCommandTest.php
@@ -42,7 +42,7 @@ public function testIsConstructable()
*/
public function testProcessDiscoverReturnIsInt()
{
- $command = $this->createMock(ExtensionDiscoverInstallCommand::class);
+ $command = $this->createStub(ExtensionDiscoverInstallCommand::class);
$countOfDiscoveredExtensions1 = $command->processDiscover(-1);
$countOfDiscoveredExtensions0 = $command->processDiscover(0);
@@ -91,7 +91,7 @@ public function testGetNote()
*/
protected function createExtensionDiscoverInstallCommand(): ExtensionDiscoverInstallCommand
{
- $db = $this->createMock(DatabaseInterface::class);
+ $db = $this->createStub(DatabaseInterface::class);
return new ExtensionDiscoverInstallCommand($db);
}
diff --git a/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverListCommandTest.php b/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverListCommandTest.php
index 986ccff241c83..b55998558eb55 100644
--- a/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverListCommandTest.php
+++ b/tests/Unit/Libraries/Cms/Console/ExtensionDiscoverListCommandTest.php
@@ -84,7 +84,7 @@ public function testFilterExtensions()
*/
protected function createExtensionDiscoverListCommand(): ExtensionDiscoverListCommand
{
- $db = $this->createMock(DatabaseInterface::class);
+ $db = $this->createStub(DatabaseInterface::class);
return new ExtensionDiscoverListCommand($db);
}
}
diff --git a/tests/Unit/Libraries/Cms/Console/Loader/WritableContainerLoaderTest.php b/tests/Unit/Libraries/Cms/Console/Loader/WritableContainerLoaderTest.php
index 78a7b0f5f1b43..902c5eadafccc 100644
--- a/tests/Unit/Libraries/Cms/Console/Loader/WritableContainerLoaderTest.php
+++ b/tests/Unit/Libraries/Cms/Console/Loader/WritableContainerLoaderTest.php
@@ -44,13 +44,12 @@ protected function setUp(): void
}
/**
- *
* @return void
* @since 4.0.0
*/
public function testTheLoaderCanBeWrittenTo()
{
- $command = $this->createMock(AbstractCommand::class);
+ $command = $this->createStub(AbstractCommand::class);
$commandName = 'test:command';
$serviceId = 'test.loader';
@@ -67,13 +66,12 @@ public function testTheLoaderCanBeWrittenTo()
}
/**
- *
* @return void
* @since 4.0.0
*/
public function testTheLoaderRetrievesACommand()
{
- $command = $this->createMock(AbstractCommand::class);
+ $command = $this->createStub(AbstractCommand::class);
$commandName = 'test:command';
$serviceId = 'test.loader';
@@ -95,7 +93,6 @@ public function testTheLoaderRetrievesACommand()
}
/**
- *
* @return void
* @since 4.0.0
*/
@@ -118,7 +115,6 @@ public function testTheLoaderDoesNotRetrieveAnUnknownCommand()
}
/**
- *
* @return void
* @since 4.0.0
*/
diff --git a/tests/Unit/Libraries/Cms/Date/DateTest.php b/tests/Unit/Libraries/Cms/Date/DateTest.php
index b0546ad60ad6f..e976410a09407 100644
--- a/tests/Unit/Libraries/Cms/Date/DateTest.php
+++ b/tests/Unit/Libraries/Cms/Date/DateTest.php
@@ -12,15 +12,15 @@
use Joomla\CMS\Date\Date;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
class DateTest extends UnitTestCase
{
/**
- * @testdox Test that the Date class can init and has the right timezones
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that the Date class can init and has the right timezones')]
public function testConstruct()
{
// Test passing timezone as a DateTimeZone instance
@@ -45,11 +45,10 @@ public function testConstruct()
}
/**
- * @testdox Test that the date is cast correctly to ISO8601
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that the date is cast correctly to ISO8601')]
public function testtoISO8601()
{
$date = new Date("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -58,11 +57,10 @@ public function testtoISO8601()
}
/**
- * @testdox Test that the date is cast correctly to RFC822
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that the date is cast correctly to RFC822')]
public function testtoRFC822()
{
$date = new Date("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -71,11 +69,10 @@ public function testtoRFC822()
}
/**
- * @testdox Test that the date is cast correctly for use in SQL
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that the date is cast correctly for use in SQL')]
public function testtoSql()
{
$date = new Date("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -84,11 +81,10 @@ public function testtoSql()
}
/**
- * @testdox Test that the date is cast correctly to a unix timestamp
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that the date is cast correctly to a unix timestamp')]
public function testtoUnix()
{
$date = new Date("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -97,11 +93,10 @@ public function testtoUnix()
}
/**
- * @testdox Test that timezones can be changed on the fly
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that timezones can be changed on the fly')]
public function testTzChange()
{
$date = new Date("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -115,11 +110,10 @@ public function testTzChange()
}
/**
- * @testdox Test that timezones can be cast to string
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that timezones can be cast to string')]
public function testCastToString()
{
$date = new Date("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -128,11 +122,10 @@ public function testCastToString()
}
/**
- * @testdox Test that Sunday is zero - because it should be
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that Sunday is zero - because it should be')]
public function testdayToString()
{
$date = Date::getInstance("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -142,11 +135,10 @@ public function testdayToString()
}
/**
- * @testdox Test magic getter
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test magic getter')]
public function testMagicGetter()
{
$date = Date::getInstance("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
@@ -154,7 +146,7 @@ public function testMagicGetter()
$this->assertSame('31', $date->daysinmonth);
$this->assertSame('3', $date->dayofweek);
$this->assertSame('66', $date->dayofyear);
- $this->assertSame(false, $date->isleapyear);
+ $this->assertFalse($date->isleapyear);
$this->assertSame('08', $date->day);
$this->assertSame('18', $date->hour);
$this->assertSame('06', $date->minute);
@@ -166,11 +158,10 @@ public function testMagicGetter()
}
/**
- * @testdox Test getting an instance
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test getting an instance')]
public function testGetInstance()
{
$date = Date::getInstance("8th March 1978 6:06pm", new \DateTimeZone('UTC'));
diff --git a/tests/Unit/Libraries/Cms/Document/DocumentAwareTraitTest.php b/tests/Unit/Libraries/Cms/Document/DocumentAwareTraitTest.php
index a41ada99319e0..98b14f87fb0af 100644
--- a/tests/Unit/Libraries/Cms/Document/DocumentAwareTraitTest.php
+++ b/tests/Unit/Libraries/Cms/Document/DocumentAwareTraitTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Document\Document;
use Joomla\CMS\Document\DocumentAwareTrait;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Document\DocumentAwareTrait
@@ -24,12 +25,11 @@
class DocumentAwareTraitTest extends UnitTestCase
{
/**
- * @testdox The user document can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The user document can be set and accessed by the trait')]
public function testGetSetDocument()
{
$document = new Document();
@@ -44,16 +44,15 @@ public function get(): Document
$trait->setDocument($document);
- $this->assertEquals($document, $trait->get());
+ $this->assertSame($document, $trait->get());
}
/**
- * @testdox The user document can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The user document can be set and accessed by the trait')]
public function testGetDocumentThrowsException()
{
$this->expectException(\UnexpectedValueException::class);
diff --git a/tests/Unit/Libraries/Cms/Document/DocumentTest.php b/tests/Unit/Libraries/Cms/Document/DocumentTest.php
index aed4834a4a754..244693a175a40 100644
--- a/tests/Unit/Libraries/Cms/Document/DocumentTest.php
+++ b/tests/Unit/Libraries/Cms/Document/DocumentTest.php
@@ -16,12 +16,18 @@
use Joomla\CMS\Document\RawDocument;
use Joomla\CMS\WebAsset\WebAssetManager;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\TestDox;
+use PHPUnit\Framework\Attributes\UsesMethod;
/**
* Test class for Document.
*
* @since 4.0.0
*/
+#[CoversMethod(Document::class, 'loadRenderer')]
+#[UsesMethod(Document::class, 'setType')]
class DocumentTest extends UnitTestCase
{
/**
@@ -31,7 +37,7 @@ class DocumentTest extends UnitTestCase
*
* @since 4.0.0
*/
- public function constructData(): array
+ public static function constructData(): array
{
return [
[
@@ -82,30 +88,28 @@ public function constructData(): array
* @param array $options Options array to inject
* @param array $expects Expected data values
*
- * @dataProvider constructData
- *
* @return void
* @since 4.0.0
*/
+ #[DataProvider('constructData')]
public function testInjectingOptionsIntoTheObjectConstructor($options, $expects)
{
$document = $this->createDocument($options);
- $this->assertEquals($expects['lineend'], $document->_getLineEnd());
- $this->assertEquals($expects['charset'], $document->getCharset());
- $this->assertEquals($expects['language'], $document->getLanguage());
- $this->assertEquals($expects['direction'], $document->getDirection());
- $this->assertEquals($expects['tab'], $document->_getTab());
- $this->assertEquals($expects['link'], $document->getLink());
- $this->assertEquals($expects['base'], $document->getBase());
+ $this->assertSame($expects['lineend'], $document->_getLineEnd());
+ $this->assertSame($expects['charset'], $document->getCharset());
+ $this->assertSame($expects['language'], $document->getLanguage());
+ $this->assertSame($expects['direction'], $document->getDirection());
+ $this->assertSame($expects['tab'], $document->_getTab());
+ $this->assertSame($expects['link'], $document->getLink());
+ $this->assertSame($expects['base'], $document->getBase());
}
/**
- * @testdox Test retrieving an instance of JDocumentHtml
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test retrieving an instance of JDocumentHtml')]
public function testRetrievingAnInstanceOfTheHtmlDocument()
{
$this->assertInstanceOf(
@@ -115,11 +119,10 @@ public function testRetrievingAnInstanceOfTheHtmlDocument()
}
/**
- * @testdox Test retrieving non-existing JDocument type returns a JDocumentRaw instance
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test retrieving non-existing JDocument type returns a JDocumentRaw instance')]
public function testRetrievingANonExistentTypeFetchesARawDocument()
{
$type = 'does-not-exist';
@@ -127,15 +130,14 @@ public function testRetrievingANonExistentTypeFetchesARawDocument()
$document = Document::getInstance($type, $this->getDocumentDependencyMocks());
$this->assertInstanceOf(RawDocument::class, $document);
- $this->assertEquals($type, $document->getType());
+ $this->assertSame($type, $document->getType());
}
/**
- * @testdox Test that setType returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setType returns an instance of $this')]
public function testEnsureSetTypeReturnsThisObject()
{
$document = $this->createDocument();
@@ -144,22 +146,20 @@ public function testEnsureSetTypeReturnsThisObject()
}
/**
- * @testdox Test the default return for getType is null
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getType is null')]
public function testTheDefaultReturnForGetTypeIsNull()
{
$this->assertNull($this->createDocument()->getType());
}
/**
- * @testdox Test that setBuffer returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setBuffer returns an instance of $this')]
public function testEnsureSetBufferReturnsThisObject()
{
$document = $this->createDocument();
@@ -171,23 +171,20 @@ public function testEnsureSetBufferReturnsThisObject()
}
/**
- * @testdox Test the default return for getBuffer is null
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getBuffer is null')]
public function testTheDefaultReturnForGetBufferIsNull()
{
$this->assertNull($this->createDocument()->getBuffer());
}
/**
- * @testdox Test that setMetadata with the 'generator' param returns an instance of $this
- *
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test that setMetadata with the 'generator' param returns an instance of \$this")]
public function testEnsureSetMetadataForGeneratorReturnsThisObject()
{
$document = $this->createDocument();
@@ -196,22 +193,20 @@ public function testEnsureSetMetadataForGeneratorReturnsThisObject()
}
/**
- * @testdox Test the default return for getMetaData with 'generator' param
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test the default return for getMetaData with 'generator' param")]
public function testTheDefaultReturnForGetMetaDataWithGenerator()
{
$this->assertSame('Joomla! - Open Source Content Management', $this->createDocument()->getMetaData('generator'));
}
/**
- * @testdox Test that setMetadata with the 'description' param returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test that setMetadata with the 'description' param returns an instance of \$this")]
public function testEnsureSetMetadataForDescriptionReturnsThisObject()
{
$document = $this->createDocument();
@@ -220,22 +215,20 @@ public function testEnsureSetMetadataForDescriptionReturnsThisObject()
}
/**
- * @testdox Test the default return for getMetaData with 'description' param
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test the default return for getMetaData with 'description' param")]
public function testTheDefaultReturnForGetMetaDataWithDescription()
{
$this->assertEmpty($this->createDocument()->getMetaData('description'));
}
/**
- * @testdox Test that setMetadata with a custom param returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setMetadata with a custom param returns an instance of $this')]
public function testEnsureSetMetadataForCustomParamsReturnsThisObject()
{
$document = $this->createDocument();
@@ -244,11 +237,10 @@ public function testEnsureSetMetadataForCustomParamsReturnsThisObject()
}
/**
- * @testdox Test the return for getMetaData with a custom param and HTTP-Equiv flag true with data not set to HTTP-Equiv
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the return for getMetaData with a custom param and HTTP-Equiv flag true with data not set to HTTP-Equiv')]
public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivTrueAndDataNotSet()
{
$document = $this->createDocument();
@@ -259,11 +251,10 @@ public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivTrueAndDat
}
/**
- * @testdox Test the return for getMetaData with a custom param and HTTP-Equiv flag true with data set to HTTP-Equiv
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the return for getMetaData with a custom param and HTTP-Equiv flag true with data set to HTTP-Equiv')]
public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivTrueAndDataSet()
{
$document = $this->createDocument();
@@ -274,11 +265,10 @@ public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivTrueAndDat
}
/**
- * @testdox Test the return for getMetaData with a custom param and HTTP-Equiv flag false with data set to HTTP-Equiv
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the return for getMetaData with a custom param and HTTP-Equiv flag false with data set to HTTP-Equiv')]
public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivFalseAndDataNotSet()
{
$document = $this->createDocument();
@@ -289,11 +279,10 @@ public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivFalseAndDa
}
/**
- * @testdox Test the return for getMetaData with a custom param and HTTP-Equiv flag false with data not set to HTTP-Equiv
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the return for getMetaData with a custom param and HTTP-Equiv flag false with data not set to HTTP-Equiv')]
public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivFalseAndDataSet()
{
$document = $this->createDocument();
@@ -304,11 +293,10 @@ public function testTheReturnForGetMetaDataWithCustomParamAndHttpEquivFalseAndDa
}
/**
- * @testdox Test that addScript returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that addScript returns an instance of $this')]
public function testEnsureAddScriptReturnsThisObject()
{
$document = $this->createDocument();
@@ -317,11 +305,10 @@ public function testEnsureAddScriptReturnsThisObject()
}
/**
- * @testdox Test that addScriptDeclaration returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that addScriptDeclaration returns an instance of $this')]
public function testEnsureAddScriptDeclarationReturnsThisObject()
{
$document = $this->createDocument();
@@ -330,11 +317,10 @@ public function testEnsureAddScriptDeclarationReturnsThisObject()
}
/**
- * @testdox Test that calling addScriptDeclaration twice returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that calling addScriptDeclaration twice returns an instance of $this')]
public function testEnsureTwoAddScriptDeclarationCallsReturnsThisObject()
{
$document = $this->createDocument();
@@ -344,11 +330,10 @@ public function testEnsureTwoAddScriptDeclarationCallsReturnsThisObject()
}
/**
- * @testdox Test that addStyleSheet returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that addStyleSheet returns an instance of $this')]
public function testEnsureAddStylesheetReturnsThisObject()
{
$document = $this->createDocument();
@@ -357,11 +342,10 @@ public function testEnsureAddStylesheetReturnsThisObject()
}
/**
- * @testdox Test that addStyleDeclaration returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that addStyleDeclaration returns an instance of $this')]
public function testEnsureAddStyleDeclarationReturnsThisObject()
{
$document = $this->createDocument();
@@ -370,11 +354,10 @@ public function testEnsureAddStyleDeclarationReturnsThisObject()
}
/**
- * @testdox Test that calling addStyleDeclaration twice returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that calling addStyleDeclaration twice returns an instance of $this')]
public function testEnsureTwoAddStyleDeclarationCallsReturnsThisObject()
{
$document = $this->createDocument();
@@ -384,11 +367,10 @@ public function testEnsureTwoAddStyleDeclarationCallsReturnsThisObject()
}
/**
- * @testdox Test that setCharset returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setCharset returns an instance of $this')]
public function testEnsureSetCharsetReturnsThisObject()
{
$document = $this->createDocument();
@@ -397,22 +379,20 @@ public function testEnsureSetCharsetReturnsThisObject()
}
/**
- * @testdox Test the default return for getCharset
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getCharset')]
public function testTheDefaultReturnForGetCharset()
{
$this->assertSame('utf-8', $this->createDocument()->getCharset());
}
/**
- * @testdox Test that setLanguage returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setLanguage returns an instance of $this')]
public function testEnsureSetLanguageReturnsThisObject()
{
$document = $this->createDocument();
@@ -421,22 +401,20 @@ public function testEnsureSetLanguageReturnsThisObject()
}
/**
- * @testdox Test the default return for getLanguage
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getLanguage')]
public function testTheDefaultReturnForGetLanguage()
{
$this->assertSame('en-gb', $this->createDocument()->getLanguage());
}
/**
- * @testdox Test that setDirection returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setDirection returns an instance of $this')]
public function testEnsureSetDirectionReturnsThisObject()
{
$document = $this->createDocument();
@@ -445,22 +423,20 @@ public function testEnsureSetDirectionReturnsThisObject()
}
/**
- * @testdox Test the default return for getDirection
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getDirection')]
public function testTheDefaultReturnForGetDirection()
{
$this->assertSame('ltr', $this->createDocument()->getDirection());
}
/**
- * @testdox Test that setTitle returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setTitle returns an instance of $this')]
public function testEnsureSetTitleReturnsThisObject()
{
$document = $this->createDocument();
@@ -469,22 +445,20 @@ public function testEnsureSetTitleReturnsThisObject()
}
/**
- * @testdox Test the default return for getTitle
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getTitle')]
public function testTheDefaultReturnForGetTitle()
{
$this->assertEmpty($this->createDocument()->getTitle());
}
/**
- * @testdox Test that setBase returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setBase returns an instance of $this')]
public function testEnsureSetBaseReturnsThisObject()
{
$document = $this->createDocument();
@@ -493,22 +467,20 @@ public function testEnsureSetBaseReturnsThisObject()
}
/**
- * @testdox Test the default return for getBase
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getBase')]
public function testTheDefaultReturnForGetBase()
{
$this->assertEmpty($this->createDocument()->getBase());
}
/**
- * @testdox Test that setDescription returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setDescription returns an instance of $this')]
public function testEnsureSetDescriptionReturnsThisObject()
{
$document = $this->createDocument();
@@ -517,22 +489,20 @@ public function testEnsureSetDescriptionReturnsThisObject()
}
/**
- * @testdox Test the default return for getDescription
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getDescription')]
public function testTheDefaultReturnForGetDescription()
{
$this->assertEmpty($this->createDocument()->getDescription());
}
/**
- * @testdox Test that setLink returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setLink returns an instance of $this')]
public function testEnsureSetLinkReturnsThisObject()
{
$document = $this->createDocument();
@@ -541,22 +511,20 @@ public function testEnsureSetLinkReturnsThisObject()
}
/**
- * @testdox Test the default return for getLink
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getLink')]
public function testTheDefaultReturnForGetLink()
{
$this->assertEmpty($this->createDocument()->getLink());
}
/**
- * @testdox Test that setGenerator returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setGenerator returns an instance of $this')]
public function testEnsureSetGeneratorReturnsThisObject()
{
$document = $this->createDocument();
@@ -565,22 +533,20 @@ public function testEnsureSetGeneratorReturnsThisObject()
}
/**
- * @testdox Test the default return for getGenerator
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getGenerator')]
public function testTheDefaultReturnForGetGenerator()
{
$this->assertSame('Joomla! - Open Source Content Management', $this->createDocument()->getGenerator());
}
/**
- * @testdox Test that setModifiedDate returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setModifiedDate returns an instance of $this')]
public function testEnsureSetModifiedDateReturnsThisObject()
{
$document = $this->createDocument();
@@ -589,22 +555,20 @@ public function testEnsureSetModifiedDateReturnsThisObject()
}
/**
- * @testdox Test the default return for getModifiedDate
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getModifiedDate')]
public function testTheDefaultReturnForGetModifiedDate()
{
$this->assertEmpty($this->createDocument()->getModifiedDate());
}
/**
- * @testdox Test that setMimeEncoding returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setMimeEncoding returns an instance of $this')]
public function testEnsureSetMimeEncodingReturnsThisObject()
{
$document = $this->createDocument();
@@ -613,22 +577,20 @@ public function testEnsureSetMimeEncodingReturnsThisObject()
}
/**
- * @testdox Test the default return for getMimeEncoding
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for getMimeEncoding')]
public function testTheDefaultReturnForGetMimeEncoding()
{
$this->assertEmpty($this->createDocument()->getMimeEncoding());
}
/**
- * @testdox Test that setLineEnd with param 'win' returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test that setLineEnd with param 'win' returns an instance of \$this")]
public function testEnsureSetLineEndWinReturnsThisObject()
{
$document = $this->createDocument();
@@ -637,11 +599,10 @@ public function testEnsureSetLineEndWinReturnsThisObject()
}
/**
- * @testdox Test that setLineEnd with param 'unix' returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test that setLineEnd with param 'unix' returns an instance of \$this")]
public function testEnsureSetLineEndUnixReturnsThisObject()
{
$document = $this->createDocument();
@@ -650,11 +611,10 @@ public function testEnsureSetLineEndUnixReturnsThisObject()
}
/**
- * @testdox Test that setLineEnd with param 'mac' returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox("Test that setLineEnd with param 'mac' returns an instance of \$this")]
public function testEnsureSetLineEndMacReturnsThisObject()
{
$document = $this->createDocument();
@@ -663,11 +623,10 @@ public function testEnsureSetLineEndMacReturnsThisObject()
}
/**
- * @testdox Test that setLineEnd with a custom param returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setLineEnd with a custom param returns an instance of $this')]
public function testEnsureSetLineEndCustomReturnsThisObject()
{
$document = $this->createDocument();
@@ -676,22 +635,20 @@ public function testEnsureSetLineEndCustomReturnsThisObject()
}
/**
- * @testdox Test the default return for _getLineEnd
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for _getLineEnd')]
public function testTheDefaultReturnForGetLineEnd()
{
$this->assertSame("\12", $this->createDocument()->_getLineEnd());
}
/**
- * @testdox Test that setTab with a custom param returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that setTab with a custom param returns an instance of $this')]
public function testEnsureSetTabReturnsThisObject()
{
$document = $this->createDocument();
@@ -700,28 +657,24 @@ public function testEnsureSetTabReturnsThisObject()
}
/**
- * @testdox Test the default return for _getTab
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test the default return for _getTab')]
public function testTheDefaultReturnForGetTab()
{
$this->assertSame("\11", $this->createDocument()->_getTab());
}
/**
- * @testdox Test that loadRenderer returns the intended object
- *
- * @covers JDocument::loadRenderer
- * @uses JDocument::setType
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that loadRenderer returns the intended object')]
public function testEnsureLoadRendererReturnsCorrectObjectFromFactory()
{
- $documentDependencyMocks = $this->getDocumentDependencyMocks();
+ $documentDependencyMocks = $this->getDocumentDependencyMocks();
+ $documentDependencyMocks['factory'] = $this->createMock(FactoryInterface::class);
$documentDependencyMocks['factory']
->expects($this->once())
->method('createRenderer');
@@ -732,11 +685,10 @@ public function testEnsureLoadRendererReturnsCorrectObjectFromFactory()
}
/**
- * @testdox Test that parse returns an instance of $this
- *
* @return void
* @since 4.0.0
*/
+ #[TestDox('Test that parse returns an instance of $this')]
public function testEnsureParseReturnsThisObject()
{
$document = $this->createDocument();
@@ -772,8 +724,8 @@ protected function createDocument(array $options = []): Document
protected function getDocumentDependencyMocks(): array
{
return [
- 'factory' => $this->createMock(FactoryInterface::class),
- 'webAssetManager' => $this->createMock(WebAssetManager::class),
+ 'factory' => $this->createStub(FactoryInterface::class),
+ 'webAssetManager' => $this->createStub(WebAssetManager::class),
];
}
}
diff --git a/tests/Unit/Libraries/Cms/Encrypt/TotpTest.php b/tests/Unit/Libraries/Cms/Encrypt/TotpTest.php
new file mode 100644
index 0000000000000..820647f19345e
--- /dev/null
+++ b/tests/Unit/Libraries/Cms/Encrypt/TotpTest.php
@@ -0,0 +1,52 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\Tests\Unit\Libraries\Cms\Encrypt;
+
+use Joomla\CMS\Encrypt\Totp;
+use Joomla\Tests\Unit\UnitTestCase;
+
+/**
+ * Test class for \Joomla\CMS\Encrypt\Totp
+ *
+ * @since 6.2.0
+ */
+class TotpTest extends UnitTestCase
+{
+ /**
+ * The currently valid passcode is accepted.
+ *
+ * @return void
+ * @since 6.2.0
+ */
+ public function testCheckCodeAcceptsValidPasscode()
+ {
+ $totp = new Totp();
+ $secret = $totp->generateSecret();
+
+ $this->assertTrue($totp->checkCode($secret, $totp->getCode($secret)));
+ }
+
+ /**
+ * A numeric string that only equals the passcode under type juggling must be rejected.
+ *
+ * @return void
+ * @since 6.2.0
+ */
+ public function testCheckCodeRejectsTypeJuggledPasscode()
+ {
+ $totp = new Totp();
+ $secret = $totp->generateSecret();
+ $code = $totp->getCode($secret);
+
+ $this->assertFalse($totp->checkCode($secret, '+' . $code));
+ $this->assertFalse($totp->checkCode($secret, ' ' . $code));
+ }
+}
diff --git a/tests/Unit/Libraries/Cms/Environment/BrowserTest.php b/tests/Unit/Libraries/Cms/Environment/BrowserTest.php
index 2f1751afdcad7..2e7b861fb3725 100644
--- a/tests/Unit/Libraries/Cms/Environment/BrowserTest.php
+++ b/tests/Unit/Libraries/Cms/Environment/BrowserTest.php
@@ -12,14 +12,18 @@
use Joomla\CMS\Environment\Browser;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\BackupGlobals;
+use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for JBrowser.
*
* @since 4.0.0
- *
- * @backupGlobals enabled
*/
+#[BackupGlobals(true)]
+#[CoversMethod(Browser::class, 'match')]
class BrowserTest extends UnitTestCase
{
/**
@@ -66,7 +70,7 @@ protected function tearDown(): void
*
* @since 4.0.0
*/
- public function dataMatch(): array
+ public static function dataMatch(): array
{
return [
'Edge 75' => [
@@ -151,11 +155,6 @@ public function dataMatch(): array
}
/**
- * @testdox A browser with a given user agent is correctly detected
- *
- * @covers JBrowser::match
- * @dataProvider dataMatch
- *
* @param string $userAgent The user agent to test
* @param string $expectedBrowser The expected browser value
* @param string $expectedPlatform The expected platform value
@@ -165,6 +164,8 @@ public function dataMatch(): array
* @return void
* @since 4.0.0
*/
+ #[DataProvider('dataMatch')]
+ #[TestDox('A browser with a given user agent is correctly detected')]
public function testBrowserMatching($userAgent, $expectedBrowser, $expectedPlatform, $expectedMajorVersion, $expectedMobile)
{
$this->browser->match($userAgent);
diff --git a/tests/Unit/Libraries/Cms/Feed/FeedEntryTest.php b/tests/Unit/Libraries/Cms/Feed/FeedEntryTest.php
index 37bec5bf2d0b7..1dfd8b53ba2fd 100644
--- a/tests/Unit/Libraries/Cms/Feed/FeedEntryTest.php
+++ b/tests/Unit/Libraries/Cms/Feed/FeedEntryTest.php
@@ -71,7 +71,7 @@ protected function tearDown(): void
*/
public function testMagicGetterWithDefaultProperty()
{
- $this->assertEquals('', $this->feedEntry->uri);
+ $this->assertSame('', $this->feedEntry->uri);
}
/**
@@ -83,7 +83,7 @@ public function testMagicGetterWithDefaultProperty()
*/
public function testMagicGetterWithUnknownProperty()
{
- $this->assertEquals(null, $this->feedEntry->unknown);
+ $this->assertSame(null, $this->feedEntry->unknown);
}
/**
@@ -134,8 +134,8 @@ public function testSetAuthorWithPerson()
$author = $this->feedEntry->author;
$this->assertInstanceOf(FeedPerson::class, $author);
- $this->assertEquals($name, $author->name);
- $this->assertEquals($email, $author->email);
+ $this->assertSame($name, $author->name);
+ $this->assertSame($email, $author->email);
}
/**
@@ -189,7 +189,7 @@ public function testMagicSetter()
$value = 'test';
$this->feedEntry->testValue = $value;
- $this->assertEquals($value, $this->feedEntry->testValue);
+ $this->assertSame($value, $this->feedEntry->testValue);
}
/**
@@ -208,7 +208,7 @@ public function testAddSingleCategory()
$categories = $this->feedEntry->categories;
$this->assertCount(1, $categories);
$this->assertArrayHasKey($name, $categories);
- $this->assertEquals($uri, $categories[$name]);
+ $this->assertSame($uri, $categories[$name]);
}
/**
@@ -235,7 +235,7 @@ public function testAddMultipleCategories()
foreach ($categories as $category) {
$this->assertArrayHasKey($category['name'], $feedCategories);
- $this->assertEquals($category['uri'], $feedCategories[$category['name']]);
+ $this->assertSame($category['uri'], $feedCategories[$category['name']]);
}
}
@@ -255,8 +255,8 @@ public function testAddNewContributor()
$contributors = $this->feedEntry->contributors;
$this->assertCount(1, $contributors);
- $this->assertEquals($name, $contributors[0]->name);
- $this->assertEquals($email, $contributors[0]->email);
+ $this->assertSame($name, $contributors[0]->name);
+ $this->assertSame($email, $contributors[0]->email);
}
/**
@@ -276,8 +276,8 @@ public function testAddExistingContributor()
$contributors = $this->feedEntry->contributors;
$this->assertCount(1, $contributors);
- $this->assertEquals($name, $contributors[0]->name);
- $this->assertEquals($email, $contributors[0]->email);
+ $this->assertSame($name, $contributors[0]->name);
+ $this->assertSame($email, $contributors[0]->email);
}
/**
@@ -303,8 +303,8 @@ public function testAddMultipleContributors()
$this->assertCount(3, $feedContributors);
foreach ($contributors as $index => $contributor) {
- $this->assertEquals($contributor['name'], $feedContributors[$index]->name);
- $this->assertEquals($contributor['email'], $feedContributors[$index]->email);
+ $this->assertSame($contributor['name'], $feedContributors[$index]->name);
+ $this->assertSame($contributor['email'], $feedContributors[$index]->email);
}
}
@@ -324,7 +324,7 @@ public function testAddNewLink()
$feedLinks = $this->feedEntry->links;
$this->assertCount(1, $feedLinks);
- $this->assertEquals($link, $feedLinks[0]->uri);
+ $this->assertSame($link, $feedLinks[0]->uri);
}
/**
@@ -344,7 +344,7 @@ public function testAddExistingLink()
$feedLinks = $this->feedEntry->links;
$this->assertCount(1, $feedLinks);
- $this->assertEquals($link, $feedLinks[0]->uri);
+ $this->assertSame($link, $feedLinks[0]->uri);
}
/**
@@ -423,9 +423,9 @@ public function testSetAuthor()
$author = $this->feedEntry->author;
$this->assertInstanceOf(FeedPerson::class, $author);
- $this->assertEquals($name, $author->name);
- $this->assertEquals($email, $author->email);
- $this->assertEquals($uri, $author->uri);
- $this->assertEquals($type, $author->type);
+ $this->assertSame($name, $author->name);
+ $this->assertSame($email, $author->email);
+ $this->assertSame($uri, $author->uri);
+ $this->assertSame($type, $author->type);
}
}
diff --git a/tests/Unit/Libraries/Cms/Feed/FeedFactoryTest.php b/tests/Unit/Libraries/Cms/Feed/FeedFactoryTest.php
index 7f178affa3089..0f11c1c3136a4 100644
--- a/tests/Unit/Libraries/Cms/Feed/FeedFactoryTest.php
+++ b/tests/Unit/Libraries/Cms/Feed/FeedFactoryTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Feed\FeedFactory;
use Joomla\CMS\Feed\FeedParser;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
/**
@@ -94,7 +95,7 @@ public function testGetDefaultParsers()
public function testRegisterParser()
{
$tagName = 'parser-mock';
- $parseMock = $this->createMock(FeedParser::class);
+ $parseMock = $this->createStub(FeedParser::class);
$defaultParserCount = \count($this->feedFactory->getParsers());
$this->feedFactory->registerParser($tagName, \get_class($parseMock));
@@ -125,7 +126,7 @@ public function testRegisterParserWithInvalidClass()
public function testRegisterParserWithInvalidTag()
{
$this->expectException(\InvalidArgumentException::class);
- $parseMock = $this->createMock(FeedParser::class);
+ $parseMock = $this->createStub(FeedParser::class);
$this->feedFactory->registerParser('42tag', \get_class($parseMock));
}
@@ -134,18 +135,15 @@ public function testRegisterParserWithInvalidTag()
*
* @return void
* @since 4.0.0
- * @throws \ReflectionException
*/
public function testFetchFeedParser()
{
$tagName = 'parser-mock';
- $parseMock = $this->createMock(FeedParser::class);
+ $parseMock = $this->createStub(FeedParser::class);
$this->feedFactory->registerParser($tagName, \get_class($parseMock));
// Use reflection to test private method
- $reflectionClass = new \ReflectionClass($this->feedFactory);
- $method = $reflectionClass->getMethod('_fetchFeedParser');
- $parser = $method->invoke($this->feedFactory, $tagName, new \XMLReader());
+ $parser = TestHelper::invoke($this->feedFactory, '_fetchFeedParser', $tagName, new \XMLReader());
$this->assertInstanceOf(FeedParser::class, $parser);
$this->assertSame(\get_class($parseMock), \get_class($parser));
@@ -156,15 +154,12 @@ public function testFetchFeedParser()
*
* @return void
* @since 4.0.0
- * @throws \ReflectionException
*/
public function testFetchFeedParserWithInvalidTag()
{
$this->expectException(\LogicException::class);
// Use reflection to test private method
- $reflectionClass = new \ReflectionClass($this->feedFactory);
- $method = $reflectionClass->getMethod('_fetchFeedParser');
- $method->invoke($this->feedFactory, 'not-existing', new \XMLReader());
+ TestHelper::invoke($this->feedFactory, '_fetchFeedParser', 'not-existing', new \XMLReader());
}
}
diff --git a/tests/Unit/Libraries/Cms/Feed/FeedParserTest.php b/tests/Unit/Libraries/Cms/Feed/FeedParserTest.php
index 4df78f23b211b..2dbb2a738a682 100644
--- a/tests/Unit/Libraries/Cms/Feed/FeedParserTest.php
+++ b/tests/Unit/Libraries/Cms/Feed/FeedParserTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\Feed\FeedEntry;
use Joomla\CMS\Feed\FeedParser;
use Joomla\CMS\Feed\Parser\NamespaceParserInterface;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
use SimpleXMLElement;
@@ -43,7 +44,7 @@ public function testParse()
$feed = $parser->parse();
$this->assertInstanceOf(Feed::class, $feed);
- $this->assertEquals(1, $parser->getInitializeCalledCounter());
+ $this->assertSame(1, $parser->getInitializeCalledCounter());
// Cleanup
$xmlReader->close();
@@ -94,8 +95,10 @@ public function testParseNamespaceElement()
->with(
$this->isInstanceOf(Feed::class),
$this->callback(
- function ($value) use ($content) {
- return $value instanceof \SimpleXMLElement && (string) $value[0] === $content;
+ function ($value) use ($content): bool {
+ $this->assertInstanceOf(\SimpleXMLElement::class, $value);
+ $this->assertSame($content, (string) $value[0]);
+ return true;
}
)
);
@@ -149,7 +152,7 @@ public function testParseElementWithEntry()
$feed = $parser->parse();
$this->assertInstanceOf(Feed::class, $feed);
- $this->assertEquals(1, $feed->count());
+ $this->assertCount(1, $feed);
$processFeedEntryCalledWith = $parser->getProcessFeedEntryCalledWith();
$this->assertCount(1, $processFeedEntryCalledWith);
$this->assertInstanceOf(FeedEntry::class, $processFeedEntryCalledWith[0]['entry']);
@@ -179,8 +182,10 @@ public function testParseElementWithNamespaceEntry()
->with(
$this->isInstanceOf(FeedEntry::class),
$this->callback(
- function ($value) use ($content) {
- return $value instanceof \SimpleXMLElement && (string) $value[0] === '';
+ function ($value) use ($content): bool {
+ $this->assertInstanceOf(\SimpleXMLElement::class, $value);
+ $this->assertSame('', (string) $value[0]);
+ return true;
}
)
);
@@ -200,13 +205,13 @@ function ($value) use ($content) {
public function testRegisterNamespace()
{
$prefix = 'my-namespace';
- $namespaceMock = $this->createMock(NamespaceParserInterface::class);
+ $namespaceMock = $this->createStub(NamespaceParserInterface::class);
$parser = new FeedParserStub(new \XMLReader());
$returnedParser = $parser->registerNamespace($prefix, $namespaceMock);
$this->assertInstanceOf(FeedParserStub::class, $returnedParser);
- $this->assertEquals([$prefix => $namespaceMock], $parser->getNamespaces());
+ $this->assertSame([$prefix => $namespaceMock], $parser->getNamespaces());
}
/**
@@ -215,7 +220,6 @@ public function testRegisterNamespace()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testMoveToNextElement()
{
@@ -224,33 +228,29 @@ public function testMoveToNextElement()
$parser = new FeedParserStub($xmlReader);
- // Use reflection to test protected method (it's easier than testing this using the public interface)
- $reflectionClass = new \ReflectionClass($parser);
- $method = $reflectionClass->getMethod('moveToNextElement');
-
// Move to next element
- $method->invoke($parser);
+ TestHelper::invoke($parser, 'moveToNextElement');
// Move to the next element, which should be
.
- $this->assertEquals('node', $xmlReader->name);
- $this->assertEquals('first', $xmlReader->getAttribute('test'));
+ $this->assertSame('node', $xmlReader->name);
+ $this->assertSame('first', $xmlReader->getAttribute('test'));
// Move to next element
- $method->invoke($parser);
+ TestHelper::invoke($parser, 'moveToNextElement');
// Move to the next element, which should be with a data value of "foobar".
- $this->assertEquals('child', $xmlReader->name);
- $this->assertEquals('foobar', $xmlReader->readString());
+ $this->assertSame('child', $xmlReader->name);
+ $this->assertSame('foobar', $xmlReader->readString());
// Move to next element
- $method->invoke($parser);
+ TestHelper::invoke($parser, 'moveToNextElement');
// Move to the next element, which should be .
- $this->assertEquals('node', $xmlReader->name);
- $this->assertEquals('second', $xmlReader->getAttribute('test'));
+ $this->assertSame('node', $xmlReader->name);
+ $this->assertSame('second', $xmlReader->getAttribute('test'));
// Move to next element and assert that it returns false
- $this->assertFalse($method->invoke($parser));
+ $this->assertFalse(TestHelper::invoke($parser, 'moveToNextElement'));
}
/**
@@ -259,7 +259,6 @@ public function testMoveToNextElement()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testMoveToNextElementByName()
{
@@ -268,21 +267,17 @@ public function testMoveToNextElementByName()
$parser = new FeedParserStub($xmlReader);
- // Use reflection to test protected method (it's easier than testing this using the public interface)
- $reflectionClass = new \ReflectionClass($parser);
- $method = $reflectionClass->getMethod('moveToNextElement');
-
// Move to next element
- $method->invoke($parser, 'node');
+ TestHelper::invoke($parser, 'moveToNextElement', 'node');
// Move to the next element, which should be .
- $this->assertEquals('node', $xmlReader->name);
- $this->assertEquals('first', $xmlReader->getAttribute('test'));
+ $this->assertSame('node', $xmlReader->name);
+ $this->assertSame('first', $xmlReader->getAttribute('test'));
// Move to the next element, which should be .
- $method->invoke($parser, 'node');
- $this->assertEquals('node', $xmlReader->name);
- $this->assertEquals('second', $xmlReader->getAttribute('test'));
+ TestHelper::invoke($parser, 'moveToNextElement', 'node');
+ $this->assertSame('node', $xmlReader->name);
+ $this->assertSame('second', $xmlReader->getAttribute('test'));
}
/**
@@ -291,7 +286,6 @@ public function testMoveToNextElementByName()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testMoveToClosingElement()
{
@@ -300,16 +294,12 @@ public function testMoveToClosingElement()
$parser = new FeedParserStub($xmlReader);
- // Use reflection to test protected method (it's easier than testing this using the public interface)
- $reflectionClass = new \ReflectionClass($parser);
- $method = $reflectionClass->getMethod('moveToClosingElement');
-
// Move to next element
- $method->invoke($parser);
+ TestHelper::invoke($parser, 'moveToClosingElement');
// Move to the closing element, which should be .
- $this->assertEquals(\XMLReader::END_ELEMENT, $xmlReader->nodeType);
- $this->assertEquals('root', $xmlReader->name);
+ $this->assertSame(\XMLReader::END_ELEMENT, $xmlReader->nodeType);
+ $this->assertSame('root', $xmlReader->name);
}
/**
@@ -318,7 +308,6 @@ public function testMoveToClosingElement()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testMoveToClosingElementWithInternalElements()
{
@@ -328,16 +317,12 @@ public function testMoveToClosingElementWithInternalElements()
$parser = new FeedParserStub($xmlReader);
- // Use reflection to test protected method (it's easier than testing this using the public interface)
- $reflectionClass = new \ReflectionClass($parser);
- $method = $reflectionClass->getMethod('moveToClosingElement');
-
// Move to next element
- $method->invoke($parser);
+ TestHelper::invoke($parser, 'moveToClosingElement');
// Ensure that the current node is closing element
- $this->assertEquals(\XMLReader::END_ELEMENT, $xmlReader->nodeType);
- $this->assertEquals('node', $xmlReader->name);
+ $this->assertSame(\XMLReader::END_ELEMENT, $xmlReader->nodeType);
+ $this->assertSame('node', $xmlReader->name);
}
/**
@@ -346,7 +331,6 @@ public function testMoveToClosingElementWithInternalElements()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testMoveToClosingElementWithSelfClosingTag()
{
@@ -356,16 +340,12 @@ public function testMoveToClosingElementWithSelfClosingTag()
$parser = new FeedParserStub($xmlReader);
- // Use reflection to test protected method (it's easier than testing this using the public interface)
- $reflectionClass = new \ReflectionClass($parser);
- $method = $reflectionClass->getMethod('moveToClosingElement');
-
// Move to closing element
- $method->invoke($parser);
+ TestHelper::invoke($parser, 'moveToClosingElement');
// Move to the closing element, which should be .
- $this->assertEquals(true, $xmlReader->isEmptyElement);
- $this->assertEquals('node', $xmlReader->name);
+ $this->assertSame(true, $xmlReader->isEmptyElement);
+ $this->assertSame('node', $xmlReader->name);
}
/**
diff --git a/tests/Unit/Libraries/Cms/Feed/FeedTest.php b/tests/Unit/Libraries/Cms/Feed/FeedTest.php
index 927d52249985d..0d5ed7f9fe5b4 100644
--- a/tests/Unit/Libraries/Cms/Feed/FeedTest.php
+++ b/tests/Unit/Libraries/Cms/Feed/FeedTest.php
@@ -68,7 +68,7 @@ protected function tearDown(): void
*/
public function testMagicGetterWithDefaultProperty()
{
- $this->assertEquals('', $this->feed->uri);
+ $this->assertSame('', $this->feed->uri);
}
@@ -81,7 +81,7 @@ public function testMagicGetterWithDefaultProperty()
*/
public function testMagicGetterWithUnknownProperty()
{
- $this->assertEquals(null, $this->feed->unknown);
+ $this->assertSame(null, $this->feed->unknown);
}
/**
@@ -96,7 +96,7 @@ public function testMagicGetterWithValue()
$value = 'test';
$this->feed->testValue = $value;
- $this->assertEquals($value, $this->feed->testValue);
+ $this->assertSame($value, $this->feed->testValue);
}
/**
@@ -146,8 +146,8 @@ public function testSetAuthorWithNameAndEmail()
$author = $this->feed->author;
$this->assertInstanceOf(FeedPerson::class, $author);
- $this->assertEquals($name, $author->name);
- $this->assertEquals($email, $author->email);
+ $this->assertSame($name, $author->name);
+ $this->assertSame($email, $author->email);
}
/**
@@ -167,8 +167,8 @@ public function testSetAuthorWithPerson()
$author = $this->feed->author;
$this->assertInstanceOf(FeedPerson::class, $author);
- $this->assertEquals($name, $author->name);
- $this->assertEquals($email, $author->email);
+ $this->assertSame($name, $author->name);
+ $this->assertSame($email, $author->email);
}
/**
@@ -222,7 +222,7 @@ public function testMagicSetter()
$value = 'test';
$this->feed->testValue = $value;
- $this->assertEquals($value, $this->feed->testValue);
+ $this->assertSame($value, $this->feed->testValue);
}
/**
@@ -241,7 +241,7 @@ public function testAddSingleCategory()
$categories = $this->feed->categories;
$this->assertCount(1, $categories);
$this->assertArrayHasKey($name, $categories);
- $this->assertEquals($uri, $categories[$name]);
+ $this->assertSame($uri, $categories[$name]);
}
/**
@@ -268,7 +268,7 @@ public function testAddMultipleCategories()
foreach ($categories as $category) {
$this->assertArrayHasKey($category['name'], $feedCategories);
- $this->assertEquals($category['uri'], $feedCategories[$category['name']]);
+ $this->assertSame($category['uri'], $feedCategories[$category['name']]);
}
}
@@ -288,8 +288,8 @@ public function testAddNewContributor()
$contributors = $this->feed->contributors;
$this->assertCount(1, $contributors);
- $this->assertEquals($name, $contributors[0]->name);
- $this->assertEquals($email, $contributors[0]->email);
+ $this->assertSame($name, $contributors[0]->name);
+ $this->assertSame($email, $contributors[0]->email);
}
/**
@@ -309,8 +309,8 @@ public function testAddExistingContributor()
$contributors = $this->feed->contributors;
$this->assertCount(1, $contributors);
- $this->assertEquals($name, $contributors[0]->name);
- $this->assertEquals($email, $contributors[0]->email);
+ $this->assertSame($name, $contributors[0]->name);
+ $this->assertSame($email, $contributors[0]->email);
}
/**
@@ -336,8 +336,8 @@ public function testAddMultipleContributors()
$this->assertCount(3, $feedContributors);
foreach ($contributors as $index => $contributor) {
- $this->assertEquals($contributor['name'], $feedContributors[$index]->name);
- $this->assertEquals($contributor['email'], $feedContributors[$index]->email);
+ $this->assertSame($contributor['name'], $feedContributors[$index]->name);
+ $this->assertSame($contributor['email'], $feedContributors[$index]->email);
}
}
@@ -350,12 +350,12 @@ public function testAddMultipleContributors()
*/
public function testAddNewEntry()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->addEntry($feedEntry);
- $this->assertEquals(1, $this->feed->count());
- $this->assertEquals($feedEntry, $this->feed[0]);
+ $this->assertCount(1, $this->feed);
+ $this->assertSame($feedEntry, $this->feed[0]);
}
/**
@@ -367,13 +367,13 @@ public function testAddNewEntry()
*/
public function testAddExistingEntry()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->addEntry($feedEntry);
$this->feed->addEntry($feedEntry);
- $this->assertEquals(1, $this->feed->count());
- $this->assertEquals($feedEntry, $this->feed[0]);
+ $this->assertCount(1, $this->feed);
+ $this->assertSame($feedEntry, $this->feed[0]);
}
/**
@@ -385,16 +385,16 @@ public function testAddExistingEntry()
*/
public function testAddMultipleEntries()
{
- $feedEntry1 = $this->createMock(FeedEntry::class);
- $feedEntry2 = $this->createMock(FeedEntry::class);
+ $feedEntry1 = $this->createStub(FeedEntry::class);
+ $feedEntry2 = $this->createStub(FeedEntry::class);
$feedEntry2->name = 'name2';
$this->feed->addEntry($feedEntry1);
$this->feed->addEntry($feedEntry2);
- $this->assertEquals(2, $this->feed->count());
- $this->assertEquals($feedEntry1, $this->feed[0]);
- $this->assertEquals($feedEntry2, $this->feed[1]);
+ $this->assertCount(2, $this->feed);
+ $this->assertSame($feedEntry1, $this->feed[0]);
+ $this->assertSame($feedEntry2, $this->feed[1]);
}
/**
@@ -406,7 +406,7 @@ public function testAddMultipleEntries()
*/
public function testOffsetExists()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->addEntry($feedEntry);
@@ -422,11 +422,11 @@ public function testOffsetExists()
*/
public function testOffsetGet()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->addEntry($feedEntry);
- $this->assertEquals($feedEntry, $this->feed->offsetGet(0));
+ $this->assertSame($feedEntry, $this->feed->offsetGet(0));
}
/**
@@ -451,12 +451,12 @@ public function testOffsetSetWithString()
*/
public function testOffsetSet()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->offsetSet(1, $feedEntry);
- $this->assertEquals(1, $this->feed->count());
- $this->assertEquals($feedEntry, $this->feed->offsetGet(1));
+ $this->assertCount(1, $this->feed);
+ $this->assertSame($feedEntry, $this->feed->offsetGet(1));
}
/**
@@ -468,12 +468,12 @@ public function testOffsetSet()
*/
public function testOffsetUnset()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->offsetSet(10, $feedEntry);
$this->feed->offsetUnset(10);
- $this->assertEquals(0, $this->feed->count());
+ $this->assertCount(0, $this->feed);
}
/**
@@ -525,11 +525,11 @@ public function testRemoveContributor()
*/
public function testRemoveEntry()
{
- $feedEntry = $this->createMock(FeedEntry::class);
+ $feedEntry = $this->createStub(FeedEntry::class);
$this->feed->addEntry($feedEntry);
$this->feed->removeEntry($feedEntry);
- $this->assertEquals(0, $this->feed->count());
+ $this->assertCount(0, $this->feed);
}
}
diff --git a/tests/Unit/Libraries/Cms/Feed/Parser/AtomParserTest.php b/tests/Unit/Libraries/Cms/Feed/Parser/AtomParserTest.php
index d47d48904a0d9..7f7cacaa290af 100644
--- a/tests/Unit/Libraries/Cms/Feed/Parser/AtomParserTest.php
+++ b/tests/Unit/Libraries/Cms/Feed/Parser/AtomParserTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\Feed\FeedEntry;
use Joomla\CMS\Feed\FeedLink;
use Joomla\CMS\Feed\Parser\AtomParser;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
/**
@@ -31,7 +32,6 @@ class AtomParserTest extends UnitTestCase
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleAuthor()
{
@@ -55,10 +55,8 @@ public function testHandleAuthor()
->with($author['name'], $author['email'], $author['uri']);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleAuthor');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleAuthor', $feedMock, $xmlElement);
}
/**
@@ -67,7 +65,6 @@ public function testHandleAuthor()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleContributor()
{
@@ -91,10 +88,8 @@ public function testHandleContributor()
->with($contributor['name'], $contributor['email'], $contributor['uri']);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleContributor');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleContributor', $feedMock, $xmlElement);
}
/**
@@ -103,7 +98,6 @@ public function testHandleContributor()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleGenerator()
{
@@ -120,10 +114,8 @@ public function testHandleGenerator()
->with('generator', $generator);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleGenerator');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleGenerator', $feedMock, $xmlElement);
}
/**
@@ -132,7 +124,6 @@ public function testHandleGenerator()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleId()
{
@@ -149,10 +140,8 @@ public function testHandleId()
->with('uri', $id);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleId');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleId', $feedMock, $xmlElement);
}
/**
@@ -161,7 +150,6 @@ public function testHandleId()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleLink()
{
@@ -178,17 +166,17 @@ public function testHandleLink()
->with(
'link',
$this->callback(
- function ($param) use ($href) {
- return $param instanceof FeedLink && $param->uri === $href;
+ function ($param) use ($href): bool {
+ $this->assertInstanceOf(FeedLink::class, $param);
+ $this->assertSame($href, $param->uri);
+ return true;
}
)
);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleLink');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleLink', $feedMock, $xmlElement);
}
/**
@@ -197,7 +185,6 @@ function ($param) use ($href) {
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleRights()
{
@@ -214,10 +201,8 @@ public function testHandleRights()
->with('copyright', $copyright);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleRights');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleRights', $feedMock, $xmlElement);
}
/**
@@ -226,7 +211,6 @@ public function testHandleRights()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleSubtitle()
{
@@ -243,10 +227,8 @@ public function testHandleSubtitle()
->with('description', $subtitle);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleSubtitle');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleSubtitle', $feedMock, $xmlElement);
}
/**
@@ -255,7 +237,6 @@ public function testHandleSubtitle()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleTitle()
{
@@ -272,10 +253,8 @@ public function testHandleTitle()
->with('title', $title);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleTitle');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleTitle', $feedMock, $xmlElement);
}
/**
@@ -284,7 +263,6 @@ public function testHandleTitle()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleUpdated()
{
@@ -301,10 +279,8 @@ public function testHandleUpdated()
->with('updatedDate', $date);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('handleUpdated');
- $method->invoke($atomParser, $feedMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'handleUpdated', $feedMock, $xmlElement);
}
/**
@@ -312,7 +288,6 @@ public function testHandleUpdated()
*
* @return void
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testInitialiseSetsDefaultVersionWithXmlDocType()
{
@@ -323,11 +298,7 @@ public function testInitialiseSetsDefaultVersionWithXmlDocType()
$atomParser = new AtomParser($reader);
$atomParser->parse();
- // Use reflection to check the value
- $reflectionClass = new \ReflectionClass($atomParser);
- $attribute = $reflectionClass->getProperty('version');
-
- $this->assertEquals('1.0', $attribute->getValue($atomParser));
+ $this->assertSame('1.0', TestHelper::getValue($atomParser, 'version'));
}
/**
@@ -335,7 +306,6 @@ public function testInitialiseSetsDefaultVersionWithXmlDocType()
*
* @return void
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testInitialiseSetsDefaultVersion()
{
@@ -362,11 +332,7 @@ public function testInitialiseSetsDefaultVersion()
$atomParser->parse();
- // Use reflection to check the value
- $reflectionClass = new \ReflectionClass($atomParser);
- $attribute = $reflectionClass->getProperty('version');
-
- $this->assertEquals('1.0', $attribute->getValue($atomParser));
+ $this->assertSame('1.0', TestHelper::getValue($atomParser, 'version'));
}
/**
@@ -374,7 +340,6 @@ public function testInitialiseSetsDefaultVersion()
*
* @return void
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testInitialiseSetsOldVersion()
{
@@ -401,11 +366,7 @@ public function testInitialiseSetsOldVersion()
$atomParser->parse();
- // Use reflection to check the value
- $reflectionClass = new \ReflectionClass($atomParser);
- $attribute = $reflectionClass->getProperty('version');
-
- $this->assertEquals('0.3', $attribute->getValue($atomParser));
+ $this->assertSame('0.3', TestHelper::getValue($atomParser, 'version'));
}
/**
@@ -414,7 +375,6 @@ public function testInitialiseSetsOldVersion()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testProcessFeedEntry()
{
@@ -424,15 +384,25 @@ public function testProcessFeedEntry()
titleAugust 25, 1991summary');
$feedEntryMock = $this->createMock(FeedEntry::class);
+ $matcher = $this->exactly(4);
$feedEntryMock
- ->expects($this->exactly(4))
+ ->expects($matcher)
->method('__set')
- ->withConsecutive(
- ['uri', 'http://example.com/id'],
- ['title', 'title'],
- ['updatedDate', 'August 25, 1991'],
- ['content', 'summary']
- );
+ ->willReturnCallback(function (...$parameters) use ($matcher) {
+ if ($matcher->numberOfInvocations() === 1) {
+ $this->assertSame('uri', $parameters[0]);
+ $this->assertSame('http://example.com/id', $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 2) {
+ $this->assertSame('title', $parameters[0]);
+ $this->assertSame('title', $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 3) {
+ $this->assertSame('updatedDate', $parameters[0]);
+ $this->assertSame('August 25, 1991', $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 4) {
+ $this->assertSame('content', $parameters[0]);
+ $this->assertSame('summary', $parameters[1]);
+ }
+ });
/**
* Ensure that for the test to work we correctly return the content element (as a normal class would do
@@ -443,14 +413,12 @@ public function testProcessFeedEntry()
];
$feedEntryMock
- ->expects($this->any())
+ ->expects($this->exactly(2))
->method('__get')
- ->will($this->returnValueMap($map));
+ ->willReturnMap($map);
// Use reflection to test protected method
- $atomParser = new AtomParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($atomParser);
- $method = $reflectionClass->getMethod('processFeedEntry');
- $method->invoke($atomParser, $feedEntryMock, $xmlElement);
+ $atomParser = new AtomParser(new \XMLReader());
+ TestHelper::invoke($atomParser, 'processFeedEntry', $feedEntryMock, $xmlElement);
}
}
diff --git a/tests/Unit/Libraries/Cms/Feed/Parser/RssParserTest.php b/tests/Unit/Libraries/Cms/Feed/Parser/RssParserTest.php
index 987062cbb6635..ed0a75a3223d4 100644
--- a/tests/Unit/Libraries/Cms/Feed/Parser/RssParserTest.php
+++ b/tests/Unit/Libraries/Cms/Feed/Parser/RssParserTest.php
@@ -15,6 +15,7 @@
use Joomla\CMS\Feed\FeedLink;
use Joomla\CMS\Feed\FeedPerson;
use Joomla\CMS\Feed\Parser\RssParser;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
/**
@@ -32,7 +33,6 @@ class RssParserTest extends UnitTestCase
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleCategory()
{
@@ -49,10 +49,8 @@ public function testHandleCategory()
->with($category, '');
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleCategory');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleCategory', $feedMock, $xmlElement);
}
/**
@@ -61,7 +59,6 @@ public function testHandleCategory()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleCloud()
{
@@ -86,22 +83,21 @@ public function testHandleCloud()
->with(
'cloud',
$this->callback(
- function ($value) use ($cloud) {
- return \is_object($value)
- && $value->domain === $cloud['domain']
- && $value->port === $cloud['port']
- && $value->path === $cloud['path']
- && $value->registerProcedure === $cloud['registerProcedure']
- && $value->protocol === $cloud['protocol'];
+ function ($value) use ($cloud): bool {
+ $this->assertInstanceOf(\stdClass::class, $value);
+ $this->assertSame($cloud['domain'], $value->domain);
+ $this->assertSame($cloud['port'], $value->port);
+ $this->assertSame($cloud['path'], $value->path);
+ $this->assertSame($cloud['registerProcedure'], $value->registerProcedure);
+ $this->assertSame($cloud['protocol'], $value->protocol);
+ return true;
}
)
);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleCloud');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleCloud', $feedMock, $xmlElement);
}
/**
@@ -110,7 +106,6 @@ function ($value) use ($cloud) {
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleCopyright()
{
@@ -127,10 +122,8 @@ public function testHandleCopyright()
->with('copyright', $copyright);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleCopyright');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleCopyright', $feedMock, $xmlElement);
}
/**
@@ -139,7 +132,6 @@ public function testHandleCopyright()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleDescription()
{
@@ -156,10 +148,8 @@ public function testHandleDescription()
->with('description', $subtitle);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleDescription');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleDescription', $feedMock, $xmlElement);
}
/**
@@ -168,7 +158,6 @@ public function testHandleDescription()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleGenerator()
{
@@ -185,10 +174,8 @@ public function testHandleGenerator()
->with('generator', $generator);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleGenerator');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleGenerator', $feedMock, $xmlElement);
}
/**
@@ -197,7 +184,6 @@ public function testHandleGenerator()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleImage()
{
@@ -221,25 +207,24 @@ public function testHandleImage()
->with(
'image',
$this->callback(
- function ($value) use ($image) {
- return $value instanceof FeedLink
- && $value->uri === $image['url']
- && $value->relation === null
- && $value->type === 'logo'
- && $value->language === null
- && $value->title === $image['title']
- && $value->description === $image['description']
- && $value->height === ''
- && $value->width === '';
+ function ($value) use ($image): bool {
+ $this->assertInstanceOf(FeedLink::class, $value);
+ $this->assertSame($image['url'], $value->uri);
+ $this->assertNull($value->relation);
+ $this->assertSame('logo', $value->type);
+ $this->assertNull($value->language);
+ $this->assertSame($image['title'], $value->title);
+ $this->assertSame($image['description'], $value->description);
+ $this->assertSame('', $value->height);
+ $this->assertSame('', $value->width);
+ return true;
}
)
);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleImage');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleImage', $feedMock, $xmlElement);
}
/**
@@ -248,7 +233,6 @@ function ($value) use ($image) {
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleLanguage()
{
@@ -265,10 +249,8 @@ public function testHandleLanguage()
->with('language', $language);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleLanguage');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleLanguage', $feedMock, $xmlElement);
}
/**
@@ -277,7 +259,6 @@ public function testHandleLanguage()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleLastBuildDate()
{
@@ -294,10 +275,8 @@ public function testHandleLastBuildDate()
->with('updatedDate', $buildDate);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleLastBuildDate');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleLastBuildDate', $feedMock, $xmlElement);
}
/**
@@ -306,7 +285,6 @@ public function testHandleLastBuildDate()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleLink()
{
@@ -323,17 +301,17 @@ public function testHandleLink()
->with(
'link',
$this->callback(
- function ($value) use ($link) {
- return $value instanceof FeedLink && $value->uri === $link;
+ function ($value) use ($link): bool {
+ $this->assertInstanceOf(FeedLink::class, $value);
+ $this->assertSame($link, $value->uri);
+ return true;
}
)
);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleLink');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleLink', $feedMock, $xmlElement);
}
/**
@@ -342,7 +320,6 @@ function ($value) use ($link) {
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleManagingEditor()
{
@@ -362,19 +339,18 @@ public function testHandleManagingEditor()
->with(
'author',
$this->callback(
- function ($value) use ($editor) {
- return $value instanceof FeedPerson
- && $value->name === $editor['name']
- && $value->email === $editor['email'];
+ function ($value) use ($editor): bool {
+ $this->assertInstanceOf(FeedPerson::class, $value);
+ $this->assertSame($editor['name'], $value->name);
+ $this->assertSame($editor['email'], $value->email);
+ return true;
}
)
);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleManagingEditor');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleManagingEditor', $feedMock, $xmlElement);
}
/**
@@ -383,7 +359,6 @@ function ($value) use ($editor) {
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandlePubDate()
{
@@ -400,10 +375,8 @@ public function testHandlePubDate()
->with('publishedDate', $pubDate);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handlePubDate');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handlePubDate', $feedMock, $xmlElement);
}
/**
@@ -412,7 +385,6 @@ public function testHandlePubDate()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleSkipDays()
{
@@ -429,10 +401,8 @@ public function testHandleSkipDays()
->with('skipDays', $skipDays);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleSkipDays');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleSkipDays', $feedMock, $xmlElement);
}
/**
@@ -441,7 +411,6 @@ public function testHandleSkipDays()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleSkipHours()
{
@@ -458,10 +427,8 @@ public function testHandleSkipHours()
->with('skipHours', $skipHours);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleSkipHours');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleSkipHours', $feedMock, $xmlElement);
}
/**
@@ -470,7 +437,6 @@ public function testHandleSkipHours()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleTitle()
{
@@ -487,10 +453,8 @@ public function testHandleTitle()
->with('title', $title);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleTitle');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleTitle', $feedMock, $xmlElement);
}
/**
@@ -499,7 +463,6 @@ public function testHandleTitle()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleTtl()
{
@@ -516,10 +479,8 @@ public function testHandleTtl()
->with('ttl', (int) $ttl);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleTtl');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleTtl', $feedMock, $xmlElement);
}
/**
@@ -528,7 +489,6 @@ public function testHandleTtl()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testHandleWebmaster()
{
@@ -548,10 +508,8 @@ public function testHandleWebmaster()
->with($webmaster['name'], $webmaster['email'], null, 'webmaster');
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('handleWebmaster');
- $method->invoke($rssParser, $feedMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'handleWebmaster', $feedMock, $xmlElement);
}
/**
@@ -559,7 +517,6 @@ public function testHandleWebmaster()
*
* @return void
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testParseSetsVersion()
{
@@ -588,11 +545,7 @@ public function testParseSetsVersion()
$rssParser->parse();
- // Use reflection to check the value
- $reflectionClass = new \ReflectionClass($rssParser);
- $attribute = $reflectionClass->getProperty('version');
-
- $this->assertEquals('2.0', $attribute->getValue($rssParser));
+ $this->assertSame('2.0', TestHelper::getValue($rssParser, 'version'));
}
/**
@@ -601,7 +554,6 @@ public function testParseSetsVersion()
* @return void
*
* @since 3.1.4
- * @throws \ReflectionException
*/
public function testProcessFeedEntry()
{
@@ -634,28 +586,43 @@ public function testProcessFeedEntry()
);
$feedEntryMock = $this->createMock(FeedEntry::class);
+ $matcher = $this->exactly(9);
$feedEntryMock
- ->expects($this->any())
+ ->expects($matcher)
->method('__set')
- ->withConsecutive(
- ['uri', $entry['link']],
- ['title', $entry['title']],
- ['publishedDate', $entry['pubDate']],
- ['updatedDate', $entry['pubDate']],
- ['content', $entry['description']],
- ['guid', ''],
- ['isPermaLink', true],
- ['comments', ''],
- ['author', $this->callback(
- function ($value) use ($entry) {
- return $value instanceof FeedPerson
- && $value->name === $entry['authorName']
- && $value->email === $entry['authorEmail'];
- }
- ),
- ]
- );
+ ->willReturnCallback(function (...$parameters) use ($matcher, $entry) {
+ if ($matcher->numberOfInvocations() === 1) {
+ $this->assertSame('uri', $parameters[0]);
+ $this->assertSame($entry['link'], $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 2) {
+ $this->assertSame('title', $parameters[0]);
+ $this->assertSame($entry['title'], $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 3) {
+ $this->assertSame('publishedDate', $parameters[0]);
+ $this->assertSame($entry['pubDate'], $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 4) {
+ $this->assertSame('updatedDate', $parameters[0]);
+ $this->assertSame($entry['pubDate'], $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 5) {
+ $this->assertSame('content', $parameters[0]);
+ $this->assertSame($entry['description'], $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 6) {
+ $this->assertSame('guid', $parameters[0]);
+ $this->assertSame('', $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 7) {
+ $this->assertSame('isPermaLink', $parameters[0]);
+ $this->assertTrue($parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 8) {
+ $this->assertSame('comments', $parameters[0]);
+ $this->assertSame('', $parameters[1]);
+ } elseif ($matcher->numberOfInvocations() === 9) {
+ $this->assertSame('author', $parameters[0]);
+ $this->assertInstanceOf(FeedPerson::class, $parameters[1]);
+ $this->assertSame($entry['authorName'], $parameters[1]->name);
+ $this->assertSame($entry['authorEmail'], $parameters[1]->email);
+ }
+ });
$feedEntryMock
->expects($this->once())
@@ -667,19 +634,18 @@ function ($value) use ($entry) {
->method('addLink')
->with(
$this->callback(
- function ($value) use ($entry) {
- return $value instanceof FeedLink
- && $value->uri === $entry['enclosureUrl']
- && $value->type === $entry['enclosureType']
- && $value->length === (int) $entry['enclosureLength'];
+ function ($value) use ($entry): bool {
+ $this->assertInstanceOf(FeedLink::class, $value);
+ $this->assertSame($entry['enclosureUrl'], $value->uri);
+ $this->assertSame($entry['enclosureType'], $value->type);
+ $this->assertSame((int) $entry['enclosureLength'], $value->length);
+ return true;
}
)
);
// Use reflection to test protected method
- $rssParser = new RssParser(new \XMLReader());
- $reflectionClass = new \ReflectionClass($rssParser);
- $method = $reflectionClass->getMethod('processFeedEntry');
- $method->invoke($rssParser, $feedEntryMock, $xmlElement);
+ $rssParser = new RssParser(new \XMLReader());
+ TestHelper::invoke($rssParser, 'processFeedEntry', $feedEntryMock, $xmlElement);
}
}
diff --git a/tests/Unit/Libraries/Cms/Filter/OutputFilterTest.php b/tests/Unit/Libraries/Cms/Filter/OutputFilterTest.php
index b47e19faaeda1..465c4fb3b77dc 100644
--- a/tests/Unit/Libraries/Cms/Filter/OutputFilterTest.php
+++ b/tests/Unit/Libraries/Cms/Filter/OutputFilterTest.php
@@ -28,7 +28,7 @@ class OutputFilterTest extends UnitTestCase
*/
public function testLinkXHTMLSafe()
{
- $this->assertEquals(
+ $this->assertSame(
'This & That',
OutputFilter::linkXHTMLSafe('This & That'),
'Should clean ampersands only out of link, not out of link text'
@@ -43,7 +43,7 @@ public function testLinkXHTMLSafe()
*/
public function testStringJSSafe()
{
- $this->assertEquals(
+ $this->assertSame(
'\u0054\u0065\u0073\u0074\u0022\u003e\u0027\u0020\u00e4\u00f6\u0020\u6d4b\u8bd5\u{28207}',
OutputFilter::stringJSSafe('Test">\' äö 测试𨈇'),
'Should convert all input to escaped unicode notation'
@@ -58,13 +58,13 @@ public function testStringJSSafe()
*/
public function testStringURLSafe()
{
- $this->assertEquals(
+ $this->assertSame(
'1234567890-qwertyuiop-qwertyuiop-asdfghjkl-asdfghjkl-zxcvbnm-zxcvbnm',
OutputFilter::stringURLSafe('`1234567890-=~!@#$%^&*()_+ qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;\'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?'),
'Should clean keyboard string down to ASCII-7'
);
- $this->assertEquals(
+ $this->assertSame(
'joomlas-version',
OutputFilter::stringURLSafe('joomla\'s version'),
'Should remove apostrophe from the string'
@@ -80,31 +80,31 @@ public function testStringURLSafe()
*/
public function testAmpReplace()
{
- $this->assertEquals(
+ $this->assertSame(
'&&george&maryson',
OutputFilter::ampReplace('&&george&maryson'),
'Should replace single ampersands with HTML entity'
);
- $this->assertEquals(
+ $this->assertSame(
'index.php?&&george&maryson&this=that',
OutputFilter::ampReplace('index.php?&&george&maryson&this=that'),
'Should replace single ampersands with HTML entity'
);
- $this->assertEquals(
+ $this->assertSame(
'index.php?&&george&maryson&&&this=that',
OutputFilter::ampReplace('index.php?&&george&maryson&&&this=that'),
'Should replace single ampersands with HTML entity'
);
- $this->assertEquals(
+ $this->assertSame(
'index.php?&this="this & and that"',
OutputFilter::ampReplace('index.php?&this="this & and that"'),
'Should replace single ampersands with HTML entity'
);
- $this->assertEquals(
+ $this->assertSame(
'index.php?&this="this & & && and that"',
OutputFilter::ampReplace('index.php?&this="this & & && and that"'),
'Should replace single ampersands with HTML entity'
diff --git a/tests/Unit/Libraries/Cms/Form/Field/AccessiblemediaFieldTest.php b/tests/Unit/Libraries/Cms/Form/Field/AccessiblemediaFieldTest.php
index 5a5bc311be038..952b9d96279fe 100644
--- a/tests/Unit/Libraries/Cms/Form/Field/AccessiblemediaFieldTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Field/AccessiblemediaFieldTest.php
@@ -54,7 +54,7 @@ public function testGetWithDefaultValues()
];
foreach ($properties as $property => $propertyvalue) {
- $this->assertEquals($propertyvalue, $accessiblemediafield->__get($property));
+ $this->assertSame($propertyvalue, $accessiblemediafield->__get($property));
}
}
@@ -72,14 +72,14 @@ public function testSetAndGetShouldBeEquals()
$properties = [
"directory" => 'mydirectory',
"preview" => 'tooltip',
- "previewWidth" => "300",
- "previewHeight" => "300",
+ "previewWidth" => 300,
+ "previewHeight" => 300,
"layout" => 'joomla.form.field.media.accessiblemedia',
];
foreach ($properties as $property => $propertyvalue) {
$accessiblemediafield->__set($property, $propertyvalue);
- $this->assertEquals($propertyvalue, $accessiblemediafield->__get($property));
+ $this->assertSame($propertyvalue, $accessiblemediafield->__get($property));
}
}
@@ -98,7 +98,7 @@ public function testSetupWithEmptyValue()
$element = new \SimpleXMLElement('');
$this->assertTrue($accessiblemediafield->setup($element, '', null));
- $this->assertEquals('', $accessiblemediafield->__get('value'));
+ $this->assertSame('', $accessiblemediafield->__get('value'));
}
/**
@@ -121,7 +121,7 @@ public function testSetupWithValueThatIsValidButNotAccessible()
];
$this->assertTrue($accessiblemediafield->setup($element, '/images/joomla_black.png', null));
- $this->assertEquals($fieldvalue, $accessiblemediafield->__get('value'));
+ $this->assertSame($fieldvalue, $accessiblemediafield->__get('value'));
}
/**
@@ -144,7 +144,7 @@ public function testSetupWithValueThatIsValid()
];
$this->assertTrue($accessiblemediafield->setup($element, '{"imagefile":"pathtofile","alt_text":"alt text"}', null));
- $this->assertEquals($fieldvalue, $accessiblemediafield->__get('value'));
+ $this->assertSame($fieldvalue, $accessiblemediafield->__get('value'));
}
/**
@@ -163,7 +163,7 @@ public function testSetupWithValueThatIsNotValid()
$element = new \SimpleXMLElement('');
$this->assertTrue($accessiblemediafield->setup($element, 'jfsdkl', null));
- $this->assertEquals('', $accessiblemediafield->__get('value'));
+ $this->assertSame('', $accessiblemediafield->__get('value'));
}
/**
@@ -186,7 +186,7 @@ public function testSetupWithValueThatIsValidStdclass()
$element = new \SimpleXMLElement('');
$this->assertTrue($accessiblemediafield->setup($element, $obj, null));
- $this->assertEquals($obj, $accessiblemediafield->__get('value'));
+ $this->assertSame($obj, $accessiblemediafield->__get('value'));
}
/**
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/BooleanRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/BooleanRuleTest.php
index 72a0b4b661b0e..19b31983a53e5 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/BooleanRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/BooleanRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\BooleanRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for BooleanRule.
@@ -27,7 +28,7 @@ class BooleanRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new BooleanRule())->test($element, $value));
+ $this->assertSame($expected, (new BooleanRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/CalendarRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/CalendarRuleTest.php
index ceeef31ab9391..bc1509dbb4d24 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/CalendarRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/CalendarRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\CalendarRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for CalendarRule.
@@ -27,7 +28,7 @@ class CalendarRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new CalendarRule())->test($element, $value));
+ $this->assertSame($expected, (new CalendarRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/ColorRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/ColorRuleTest.php
index 1f993b8ce2076..8922c00d2122a 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/ColorRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/ColorRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\ColorRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for ColorRule.
@@ -27,7 +28,7 @@ class ColorRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new ColorRule())->test($element, $value));
+ $this->assertSame($expected, (new ColorRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/CssIdentifierRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/CssIdentifierRuleTest.php
index e37fd319625c5..6b4479a7f5e98 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/CssIdentifierRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/CssIdentifierRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\CssIdentifierRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for CssIdentifierRule.
@@ -27,7 +28,7 @@ class CssIdentifierRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new CssIdentifierRule())->test($element, $value));
+ $this->assertSame($expected, (new CssIdentifierRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/EmailRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/EmailRuleTest.php
index 14cde0a4a5129..b15c43629a4ee 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/EmailRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/EmailRuleTest.php
@@ -13,6 +13,7 @@
use Algo26\IdnaConvert\Exception\InvalidCharacterException;
use Joomla\CMS\Form\Rule\EmailRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for EmailRule.
@@ -28,7 +29,7 @@ class EmailRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('');
- $form = $this->createMock(Form::class);
return [
- [true, $xml, 'testvalue', null, new Registry(['testfield' => 'testvalue']), $form],
- [true, $xml, 'testvalue', '', new Registry(['testfield' => 'testvalue']), $form],
- [true, $xml, 'testvaluegroup', 'user', new Registry(['user' => ['testfield' => 'testvaluegroup']]), $form],
- [true, $xml, '', null, new Registry(), $form],
- [true, $xml, '1', null, new Registry(['testfield' => '1']), $form],
- [true, $xml, '2', null, new Registry(['testfield' => '02']), $form],
- [true, $xml, '3', null, new Registry(['testfield' => 3]), $form],
- [true, $xml, '04', null, new Registry(['testfield' => '4']), $form],
- [true, $xml, '5', null, new Registry(['testfield' => 5]), $form],
- [true, $xml, 6, null, new Registry(['testfield' => '6']), $form],
- [true, $xml, '0', null, new Registry(['testfield' => false]), $form],
- [true, $xml, 0, null, new Registry(['testfield' => false]), $form],
- [true, $xml, 4, null, new Registry(['testfield' => true]), $form],
- [false, $xml, 'testvalue', null, new Registry(), $form],
- [false, $xml, 'testvalue', null, new Registry(['testfield' => '']), $form],
- [false, $xml, 'TESTVALUE', null, new Registry(['testfield' => 'testvalue']), $form],
- [false, $xml, 'testvalue2', null, new Registry(['testfield' => 'testvalue']), $form],
- [false, $xml, '', null, new Registry(['testfield' => 'testvalue']), $form],
- [false, $xml, 'testvaluegroup', 'a', new Registry(['user' => ['testfield' => 'testvaluegroup']]), $form],
- [false, $xml, 'a', null, new Registry(['testfield' => 0]), $form],
+ [true, $xml, 'testvalue', null, new Registry(['testfield' => 'testvalue']), Form::class],
+ [true, $xml, 'testvalue', '', new Registry(['testfield' => 'testvalue']), Form::class],
+ [true, $xml, 'testvaluegroup', 'user', new Registry(['user' => ['testfield' => 'testvaluegroup']]), Form::class],
+ [true, $xml, '', null, new Registry(), Form::class],
+ [true, $xml, '1', null, new Registry(['testfield' => '1']), Form::class],
+ [true, $xml, '2', null, new Registry(['testfield' => '02']), Form::class],
+ [true, $xml, '3', null, new Registry(['testfield' => 3]), Form::class],
+ [true, $xml, '04', null, new Registry(['testfield' => '4']), Form::class],
+ [true, $xml, '5', null, new Registry(['testfield' => 5]), Form::class],
+ [true, $xml, 6, null, new Registry(['testfield' => '6']), Form::class],
+ [true, $xml, '0', null, new Registry(['testfield' => false]), Form::class],
+ [true, $xml, 0, null, new Registry(['testfield' => false]), Form::class],
+ [true, $xml, 4, null, new Registry(['testfield' => true]), Form::class],
+ [false, $xml, 'testvalue', null, new Registry(), Form::class],
+ [false, $xml, 'testvalue', null, new Registry(['testfield' => '']), Form::class],
+ [false, $xml, 'TESTVALUE', null, new Registry(['testfield' => 'testvalue']), Form::class],
+ [false, $xml, 'testvalue2', null, new Registry(['testfield' => 'testvalue']), Form::class],
+ [false, $xml, '', null, new Registry(['testfield' => 'testvalue']), Form::class],
+ [false, $xml, 'testvaluegroup', 'a', new Registry(['user' => ['testfield' => 'testvaluegroup']]), Form::class],
+ [false, $xml, 'a', null, new Registry(['testfield' => 0]), Form::class],
[\InvalidArgumentException::class, $xml, '', null, null, null],
[\InvalidArgumentException::class, $xml, '', null, new Registry(), null],
- [\InvalidArgumentException::class, $xml, '', null, null, $form],
+ [\InvalidArgumentException::class, $xml, '', null, null, Form::class],
[\UnexpectedValueException::class, $xml2, '', null, null, null],
];
}
@@ -80,20 +80,24 @@ public function dataTest(): array
* @param string|int $value The form field value to validate.
* @param ?string $group Group name
* @param ?Registry $input Input registry
- * @param ?Form $form Form object
+ * @param ?string $form Class name of form object
*
* @return void
*
* @since 5.4.3
- * @dataProvider dataTest
*/
- public function testRule(bool|string $expected, \SimpleXMLElement $element, string|int $value, ?string $group, ?Registry $input, ?Form $form): void
+ #[DataProvider('dataTest')]
+ public function testRule(bool|string $expected, \SimpleXMLElement $element, string|int $value, ?string $group, ?Registry $input, ?string $form): void
{
+ if (\is_string($form) && class_exists($form)) {
+ $form = $this->createStub($form);
+ }
+
if (\is_string($expected) && class_exists($expected)) {
$this->expectException($expected);
(new EqualsRule())->test($element, $value, $group, $input, $form);
}
- $this->assertEquals($expected, (new EqualsRule())->test($element, $value, $group, $input, $form));
+ $this->assertSame($expected, (new EqualsRule())->test($element, $value, $group, $input, $form));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/FilePathRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/FilePathRuleTest.php
index ec2298c139382..6650a2ad1ab3d 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/FilePathRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/FilePathRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\FilePathRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for FilePathRule.
@@ -29,7 +30,7 @@ class FilePathRuleTest extends UnitTestCase
*
* @since 3.9.26
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new FilePathRule())->test($element, $value));
+ $this->assertSame($expected, (new FilePathRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/FolderPathExistsRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/FolderPathExistsRuleTest.php
index 44e87a186df19..43a2ea100d6cb 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/FolderPathExistsRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/FolderPathExistsRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\FolderPathExistsRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for FolderPathExistsRule.
@@ -29,7 +30,7 @@ class FolderPathExistsRuleTest extends UnitTestCase
*
* @since 4.0.0
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new FolderPathExistsRule())->test($element, $value));
+ $this->assertSame($expected, (new FolderPathExistsRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/ModuleLayoutRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/ModuleLayoutRuleTest.php
index b2ffcdc651d9e..ffd9323b36950 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/ModuleLayoutRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/ModuleLayoutRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\ModuleLayoutRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for ModuleLayoutRule.
@@ -27,7 +28,7 @@ class ModuleLayoutRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new ModuleLayoutRule())->test($element, $value));
+ $this->assertSame($expected, (new ModuleLayoutRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/NotequalsRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/NotequalsRuleTest.php
index 21205250c2bc3..ace87389cdfc1 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/NotequalsRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/NotequalsRuleTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\Form\Rule\NotequalsRule;
use Joomla\Registry\Registry;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for NotequalsRule.
@@ -29,7 +30,7 @@ class NotequalsRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('test($element, $value, $group, $input, $form);
}
- $this->assertEquals($expected, (new NotequalsRule())->test($element, $value, $group, $input, $form));
+ $this->assertSame($expected, (new NotequalsRule())->test($element, $value, $group, $input, $form));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/NumberRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/NumberRuleTest.php
index 0d352f4f7da79..771711838a99b 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/NumberRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/NumberRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\NumberRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for NumberRule.
@@ -27,7 +28,7 @@ class NumberRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new NumberRule())->test($element, $value));
+ $this->assertSame($expected, (new NumberRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/OptionsRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/OptionsRuleTest.php
index 6fde3cdcb0d77..db242d9f7d8cf 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/OptionsRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/OptionsRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\OptionsRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for OptionsRule.
@@ -27,7 +28,7 @@ class OptionsRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new OptionsRule())->test($element, $value));
+ $this->assertSame($expected, (new OptionsRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/ShowOnRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/ShowOnRuleTest.php
index 34d9223e9ac72..ca0d25a6a337c 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/ShowOnRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/ShowOnRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\ShowOnRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for ShowOnRule.
@@ -29,7 +30,7 @@ class ShowOnRuleTest extends UnitTestCase
*
* @since 5.0.0
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new ShowOnRule())->test($element, $value));
+ $this->assertSame($expected, (new ShowOnRule())->test($element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Form/Rule/UrlRuleTest.php b/tests/Unit/Libraries/Cms/Form/Rule/UrlRuleTest.php
index e5ae584e3c929..38db2b31b318b 100644
--- a/tests/Unit/Libraries/Cms/Form/Rule/UrlRuleTest.php
+++ b/tests/Unit/Libraries/Cms/Form/Rule/UrlRuleTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\Form\Rule\UrlRule;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for UrlRule.
@@ -27,7 +28,7 @@ class UrlRuleTest extends UnitTestCase
*
* @since 5.4.3
*/
- public function dataTest(): array
+ public static function dataTest(): array
{
$xml = new \SimpleXMLElement('assertEquals($expected, (new UrlRule())->test(clone $element, $value));
+ $this->assertSame($expected, (new UrlRule())->test(clone $element, $value));
}
}
diff --git a/tests/Unit/Libraries/Cms/Html/HtmlDateTest.php b/tests/Unit/Libraries/Cms/Html/HtmlDateTest.php
index 89b0eafb8791b..02d679e5380c1 100644
--- a/tests/Unit/Libraries/Cms/Html/HtmlDateTest.php
+++ b/tests/Unit/Libraries/Cms/Html/HtmlDateTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Date\Date;
use Joomla\CMS\HTML\Helpers\Date as HtmlDate;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for HtmlDate.
@@ -30,7 +31,7 @@ class HtmlDateTest extends UnitTestCase
*
* @since 3.1
*/
- public function dataTestRelative(): array
+ public static function dataTestRelative(): array
{
$now1 = new Date('now');
usleep(1);
@@ -88,10 +89,10 @@ public function dataTestRelative(): array
* @return void
*
* @since 3.1
- * @dataProvider dataTestRelative
*/
+ #[DataProvider('dataTestRelative')]
public function testRelative($result, $date, $unit = null, $time = null)
{
- $this->assertEquals($result, HtmlDate::relative($date, $unit, $time));
+ $this->assertSame($result, HtmlDate::relative($date, $unit, $time));
}
}
diff --git a/tests/Unit/Libraries/Cms/Html/HtmlNumberTest.php b/tests/Unit/Libraries/Cms/Html/HtmlNumberTest.php
index e78fd6b9b156a..a36ae10164150 100644
--- a/tests/Unit/Libraries/Cms/Html/HtmlNumberTest.php
+++ b/tests/Unit/Libraries/Cms/Html/HtmlNumberTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\HTML\Helpers\Number as HtmlNumber;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for HtmlNumberTest.
@@ -29,7 +30,7 @@ class HtmlNumberTest extends UnitTestCase
*
* @since 3.1
*/
- public function dataTestBytes(): array
+ public static function dataTestBytes(): array
{
return [
// Element order: result, bytes, unit, precision
@@ -58,7 +59,7 @@ public function dataTestBytes(): array
1024 * 1024 * 1024 * 1024 * 1024,
],
[
- '0',
+ 0,
0,
],
@@ -241,10 +242,10 @@ public function dataTestBytes(): array
* @return void
*
* @since 3.1
- * @dataProvider dataTestBytes
*/
+ #[DataProvider('dataTestBytes')]
public function testBytes($result, $bytes, $unit = 'auto', $precision = 2, $iec = false)
{
- $this->assertEquals($result, HtmlNumber::bytes($bytes, $unit, $precision, $iec));
+ $this->assertSame($result, HtmlNumber::bytes($bytes, $unit, $precision, $iec));
}
}
diff --git a/tests/Unit/Libraries/Cms/Html/HtmlStringTest.php b/tests/Unit/Libraries/Cms/Html/HtmlStringTest.php
index 4d41bbace1714..368463e56d58f 100644
--- a/tests/Unit/Libraries/Cms/Html/HtmlStringTest.php
+++ b/tests/Unit/Libraries/Cms/Html/HtmlStringTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\HTML\Helpers\StringHelper as HtmlString;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Tests for HtmlString.
@@ -29,7 +30,7 @@ class HtmlStringTest extends UnitTestCase
*
* @since 3.1
*/
- public function getTestAbridgeData(): array
+ public static function getTestAbridgeData(): array
{
return [
'No change case' => [
@@ -54,7 +55,7 @@ public function getTestAbridgeData(): array
*
* @since 3.1
*/
- public function getTestTruncateData(): array
+ public static function getTestTruncateData(): array
{
return [
'No change case' => [
@@ -241,7 +242,7 @@ public function getTestTruncateData(): array
*
* @since 3.1
*/
- public function getTestTruncateComplexData(): array
+ public static function getTestTruncateComplexData(): array
{
return [
@@ -427,11 +428,11 @@ public function getTestTruncateComplexData(): array
* @return void
*
* @since 3.1
- * @dataProvider getTestAbridgeData
*/
+ #[DataProvider('getTestAbridgeData')]
public function testAbridge($text, $length, $intro, $expected)
{
- $this->assertEquals($expected, HtmlString::abridge($text, $length, $intro));
+ $this->assertSame($expected, HtmlString::abridge($text, $length, $intro));
}
/**
@@ -446,11 +447,11 @@ public function testAbridge($text, $length, $intro, $expected)
* @return void
*
* @since 3.1
- * @dataProvider getTestTruncateData
*/
+ #[DataProvider('getTestTruncateData')]
public function testTruncate($text, $length, $noSplit, $allowedHtml, $expected)
{
- $this->assertEquals($expected, HtmlString::truncate($text, $length, $noSplit, $allowedHtml));
+ $this->assertSame($expected, HtmlString::truncate($text, $length, $noSplit, $allowedHtml));
}
/**
@@ -464,10 +465,10 @@ public function testTruncate($text, $length, $noSplit, $allowedHtml, $expected)
* @return void
*
* @since 3.1
- * @dataProvider getTestTruncateComplexData
*/
+ #[DataProvider('getTestTruncateComplexData')]
public function testTruncateComplex($html, $maxLength, $noSplit, $expected)
{
- $this->assertEquals($expected, HtmlString::truncateComplex($html, $maxLength, $noSplit));
+ $this->assertSame($expected, HtmlString::truncateComplex($html, $maxLength, $noSplit));
}
}
diff --git a/tests/Unit/Libraries/Cms/Html/HtmlTelephoneTest.php b/tests/Unit/Libraries/Cms/Html/HtmlTelephoneTest.php
index 3d087a758803e..b45abf09bea2c 100644
--- a/tests/Unit/Libraries/Cms/Html/HtmlTelephoneTest.php
+++ b/tests/Unit/Libraries/Cms/Html/HtmlTelephoneTest.php
@@ -31,27 +31,27 @@ class HtmlTelephoneTest extends UnitTestCase
*/
public function testTel()
{
- $this->assertThat(
+ $this->assertSame(
+ '(941) 955-5555',
HtmlTelephone::tel('1.9419555555', 'US'),
- $this->stringContains('(941) 955-5555'),
'Testing for US format'
);
- $this->assertThat(
+ $this->assertSame(
+ '+49.15123456789',
HtmlTelephone::tel('49.15123456789', 'EPP'),
- $this->stringContains('+49.15123456789'),
'Testing for EPP format'
);
- $this->assertThat(
+ $this->assertSame(
+ '+82 12 34 56 78',
HtmlTelephone::tel('82.12345678', 'ITU-T'),
- $this->stringContains('+82 12 34 56 78'),
'Testing for ITU-T format'
);
- $this->assertThat(
+ $this->assertSame(
+ '+9.8.7.6.1.2.3.1.4.9.1.e164.arpa',
HtmlTelephone::tel('1.9413216789', 'ARPA'),
- $this->stringContains('+9.8.7.6.1.2.3.1.4.9.1.e164.arpa'),
'Testing for ARPA format'
);
}
diff --git a/tests/Unit/Libraries/Cms/Image/Filter/FilterBackgroundfillTest.php b/tests/Unit/Libraries/Cms/Image/Filter/FilterBackgroundfillTest.php
index 97992d4b25d19..e008e2c367879 100644
--- a/tests/Unit/Libraries/Cms/Image/Filter/FilterBackgroundfillTest.php
+++ b/tests/Unit/Libraries/Cms/Image/Filter/FilterBackgroundfillTest.php
@@ -10,12 +10,16 @@
use Joomla\CMS\Image\Filter\Backgroundfill as FilterBackgroundfill;
use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for Image.
*
* @since 4.0.0
*/
+#[CoversMethod(FilterBackgroundfill::class, 'execute')]
+#[CoversMethod(FilterBackgroundfill::class, 'sanitizeColor')]
class FilterBackgroundfillTest extends UnitTestCase
{
/**
@@ -55,7 +59,6 @@ protected function tearDown(): void
*
* @return void
*
- * @covers Joomla\CMS\Image\Filter\Backgroundfill::execute
* @since 4.0.0
*
* @note Because GD2 uses 7bit alpha channel, results differ slightly
@@ -82,14 +85,14 @@ public function testExecute()
// Compare left part
$color = imagecolorat($imageHandle, 25, 25);
- $this->assertEquals(
+ $this->assertSame(
[171, 45, 45],
[$color >> 16 & 0xFF, $color >> 8 & 0xFF, $color & 0xFF]
);
// Compare right part
$color = imagecolorat($imageHandle, 51, 25);
- $this->assertEquals(
+ $this->assertSame(
[186, 60, 60], // GD
[$color >> 16 & 0xFF, $color >> 8 & 0xFF, $color & 0xFF]
);
@@ -102,7 +105,6 @@ public function testExecute()
*
* @return void
*
- * @covers Joomla\CMS\Image\Filter\Backgroundfill::execute
* @since 4.0.0
*/
public function testExecuteInvalidArgument()
@@ -130,7 +132,7 @@ public function testExecuteInvalidArgument()
*
* @since 1.1.3
*/
- public function dataSanitizeColor()
+ public static function dataSanitizeColor()
{
return [
[0, 0, 0, 0, 0],
@@ -166,16 +168,15 @@ public function dataSanitizeColor()
*
* @return void
*
- * @covers Joomla\CMS\Image\Filter\Backgroundfill::sanitizeColor
- * @dataProvider dataSanitizeColor
* @since 1.1.3
*/
+ #[DataProvider('dataSanitizeColor')]
public function testSanitizeColor($color, $red, $green, $blue, $alpha)
{
$imageHandle = imagecreatetruecolor(100, 100);
$filter = new FilterBackgroundfill($imageHandle);
- $this->assertEquals(
+ $this->assertSame(
[
'red' => $red,
'green' => $green,
diff --git a/tests/Unit/Libraries/Cms/Image/Filter/FilterBrightnessTest.php b/tests/Unit/Libraries/Cms/Image/Filter/FilterBrightnessTest.php
index e5dab233818b3..27415832bdbf1 100644
--- a/tests/Unit/Libraries/Cms/Image/Filter/FilterBrightnessTest.php
+++ b/tests/Unit/Libraries/Cms/Image/Filter/FilterBrightnessTest.php
@@ -71,7 +71,7 @@ public function testExecute()
$filter->execute([IMG_FILTER_BRIGHTNESS => 10]);
- $this->assertEquals(
+ $this->assertSame(
137,
imagecolorat($imageHandle, 50, 50) >> 16 & 0xFF
);
diff --git a/tests/Unit/Libraries/Cms/Image/Filter/FilterContrastTest.php b/tests/Unit/Libraries/Cms/Image/Filter/FilterContrastTest.php
index 914b13be924f2..09f4cd6af3533 100644
--- a/tests/Unit/Libraries/Cms/Image/Filter/FilterContrastTest.php
+++ b/tests/Unit/Libraries/Cms/Image/Filter/FilterContrastTest.php
@@ -72,7 +72,7 @@ public function testExecute()
$filter->execute([IMG_FILTER_CONTRAST => -10]);
- $this->assertEquals(
+ $this->assertSame(
82,
imagecolorat($imageHandle, 25, 25) >> 16 & 0xFF
);
diff --git a/tests/Unit/Libraries/Cms/Image/Filter/FilterEdgedetectTest.php b/tests/Unit/Libraries/Cms/Image/Filter/FilterEdgedetectTest.php
index e4e3d960d1d08..4cbad5e5b9529 100644
--- a/tests/Unit/Libraries/Cms/Image/Filter/FilterEdgedetectTest.php
+++ b/tests/Unit/Libraries/Cms/Image/Filter/FilterEdgedetectTest.php
@@ -72,7 +72,7 @@ public function testExecute()
$filter->execute([]);
- $this->assertEquals(
+ $this->assertSame(
187,
imagecolorat($imageHandle, 51, 25) >> 16 & 0xFF
);
diff --git a/tests/Unit/Libraries/Cms/Image/ImageFilterTest.php b/tests/Unit/Libraries/Cms/Image/ImageFilterTest.php
index abe1b3ea65d20..3ab556f0280e1 100644
--- a/tests/Unit/Libraries/Cms/Image/ImageFilterTest.php
+++ b/tests/Unit/Libraries/Cms/Image/ImageFilterTest.php
@@ -63,7 +63,7 @@ public function testConstructor()
$filter = new FilterBrightness($imageHandle);
- $this->assertEquals(
+ $this->assertSame(
$imageHandle,
TestHelper::getValue($filter, 'handle')
);
diff --git a/tests/Unit/Libraries/Cms/Image/ImageTest.php b/tests/Unit/Libraries/Cms/Image/ImageTest.php
index a7edbda6288cf..1ae4c329383f0 100644
--- a/tests/Unit/Libraries/Cms/Image/ImageTest.php
+++ b/tests/Unit/Libraries/Cms/Image/ImageTest.php
@@ -8,14 +8,36 @@
namespace Joomla\Tests\Unit\Libraries\Cms\Image;
use Joomla\CMS\Image\Image;
+use Joomla\CMS\Image\ImageFilter;
use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for Image.
*
* @since 4.0.0
*/
+#[CoversMethod(Image::class, '__construct')]
+#[CoversMethod(Image::class, 'loadFile')]
+#[CoversMethod(Image::class, 'resize')]
+#[CoversMethod(Image::class, 'toFile')]
+#[CoversMethod(Image::class, 'getFilterInstance')]
+#[CoversMethod(Image::class, 'getHeight')]
+#[CoversMethod(Image::class, 'getWidth')]
+#[CoversMethod(Image::class, 'getImageFileProperties')]
+#[CoversMethod(Image::class, 'generateThumbs')]
+#[CoversMethod(Image::class, 'createThumbnails')]
+#[CoversMethod(Image::class, 'isTransparent')]
+#[CoversMethod(Image::class, 'crop')]
+#[CoversMethod(Image::class, 'rotate')]
+#[CoversMethod(Image::class, 'filter')]
+#[CoversMethod(Image::class, 'prepareDimensions')]
+#[CoversMethod(Image::class, 'sanitizeHeight')]
+#[CoversMethod(Image::class, 'sanitizeWidth')]
+#[CoversMethod(Image::class, 'sanitizeOffset')]
+#[CoversMethod(Image::class, 'destroy')]
class ImageTest extends UnitTestCase
{
/**
@@ -126,7 +148,7 @@ protected function tearDown(): void
*
* @since 4.0.0
*/
- public function getPrepareDimensionsData()
+ public static function getPrepareDimensionsData()
{
return [
// Note: inputHeight, inputWidth, inputScale, imageHeight, imageWidth, expectedHeight, expectedWidth
@@ -147,7 +169,7 @@ public function getPrepareDimensionsData()
*
* @since 4.0.0
*/
- public function getSanitizeDimensionData()
+ public static function getSanitizeDimensionData()
{
return [
// Note: inputHeight, inputWidth, imageHeight, imageWidth, expectedHeight, expectedWidth
@@ -171,7 +193,7 @@ public function getSanitizeDimensionData()
*
* @since 4.0.0
*/
- public function getCropData()
+ public static function getCropData()
{
return [
// Note: startHeight, startWidth, cropHeight, cropWidth, cropTop, cropLeft, transparency
@@ -190,7 +212,7 @@ public function getCropData()
*
* @since 4.0.0
*/
- public function getSanitizeOffsetData()
+ public static function getSanitizeOffsetData()
{
return [
// Note: input, expected
@@ -204,8 +226,6 @@ public function getSanitizeOffsetData()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::__construct
- *
* @since 4.0.0
*/
public function testConstructor()
@@ -236,8 +256,6 @@ public function testConstructor()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::loadFile
- *
* @since 4.0.0
*/
public function testloadFile()
@@ -245,10 +263,10 @@ public function testloadFile()
$this->instance->loadFile($this->testFile);
// Verify that the cropped image is the correct size.
- $this->assertEquals(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals($this->testFile, $this->instance->getPath());
+ $this->assertSame($this->testFile, $this->instance->getPath());
}
/**
@@ -261,8 +279,6 @@ public function testloadFile()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::loadFile
- *
* @since 4.0.0
*/
public function testloadFileGif()
@@ -270,10 +286,10 @@ public function testloadFileGif()
$this->instance->loadFile($this->testFileGif);
// Verify that the cropped image is the correct size.
- $this->assertEquals(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals($this->testFileGif, $this->instance->getPath());
+ $this->assertSame($this->testFileGif, $this->instance->getPath());
}
/**
@@ -286,8 +302,6 @@ public function testloadFileGif()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::loadFile
- *
* @since 4.0.0
*/
public function testloadFilePng()
@@ -295,10 +309,10 @@ public function testloadFilePng()
$this->instance->loadFile($this->testFilePng);
// Verify that the cropped image is the correct size.
- $this->assertEquals(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals($this->testFilePng, $this->instance->getPath());
+ $this->assertSame($this->testFilePng, $this->instance->getPath());
}
/**
@@ -311,8 +325,6 @@ public function testloadFilePng()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::loadFile
- *
* @since 4.0.0
*/
public function testloadFileWebp()
@@ -320,10 +332,10 @@ public function testloadFileWebp()
$this->instance->loadFile($this->testFileWebp);
// Verify that the cropped image is the correct size.
- $this->assertEquals(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(341, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(500, imagesx(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals($this->testFileWebp, $this->instance->getPath());
+ $this->assertSame($this->testFileWebp, $this->instance->getPath());
}
/**
@@ -333,7 +345,6 @@ public function testloadFileWebp()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::loadFile
* @since 4.0.0
*/
public function testloadFileBmp()
@@ -350,7 +361,6 @@ public function testloadFileBmp()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::loadFile
* @since 4.0.0
*/
public function testloadFileWithInvalidFile()
@@ -367,8 +377,6 @@ public function testloadFileWithInvalidFile()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::resize
- *
* @since 4.0.0
*/
public function testResize()
@@ -379,14 +387,14 @@ public function testResize()
$this->instance->resize(1000, 682, false);
// Verify that the resized image is the correct size.
- $this->assertEquals(682, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(1000, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(682, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(1000, imagesx(TestHelper::getValue($this->instance, 'handle')));
$this->instance->resize(1000, 682, false, Image::SCALE_FIT);
// Verify that the resized image is the correct size.
- $this->assertEquals(682, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(1000, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(682, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(1000, imagesx(TestHelper::getValue($this->instance, 'handle')));
}
/**
@@ -397,8 +405,6 @@ public function testResize()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::resize
- *
* @since 4.0.0
*/
public function testResizeTransparent()
@@ -414,8 +420,8 @@ public function testResizeTransparent()
$image->resize(5, 5, false);
// Verify that the resized image is the correct size.
- $this->assertEquals(5, imagesy(TestHelper::getValue($image, 'handle')));
- $this->assertEquals(5, imagesx(TestHelper::getValue($image, 'handle')));
+ $this->assertSame(5, imagesy(TestHelper::getValue($image, 'handle')));
+ $this->assertSame(5, imagesx(TestHelper::getValue($image, 'handle')));
$this->assertTrue($image->isTransparent());
}
@@ -427,8 +433,6 @@ public function testResizeTransparent()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::resize
- *
* @since 4.0.0
*/
public function testResizeNoFile()
@@ -452,14 +456,14 @@ public function testCropResize()
$this->instance->cropResize(500 * 2, 341 * 2, false);
// Verify that the cropped resized image is the correct size.
- $this->assertEquals(341 * 2, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(500 * 2, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(341 * 2, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(500 * 2, imagesx(TestHelper::getValue($this->instance, 'handle')));
$this->instance->cropResize(500 * 3, 341 * 2, false);
// Verify that the cropped resized image is the correct size.
- $this->assertEquals(341 * 2, imagesy(TestHelper::getValue($this->instance, 'handle')));
- $this->assertEquals(500 * 3, imagesx(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(341 * 2, imagesy(TestHelper::getValue($this->instance, 'handle')));
+ $this->assertSame(500 * 3, imagesx(TestHelper::getValue($this->instance, 'handle')));
}
/**
@@ -468,8 +472,6 @@ public function testCropResize()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::toFile
- *
* @since 4.0.0
*/
public function testToFileInvalid()
@@ -492,8 +494,6 @@ public function testToFileInvalid()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::toFile
- *
* @since 4.0.0
*/
public function testToFileGif()
@@ -507,15 +507,15 @@ public function testToFileGif()
$b = Image::getImageFileProperties($outFileGif);
// Assert that properties that should be equal are equal.
- $this->assertEquals($a->width, $b->width);
- $this->assertEquals($a->height, $b->height);
- $this->assertEquals($a->attributes, $b->attributes);
- $this->assertEquals($a->bits, $b->bits);
- $this->assertEquals($a->channels, $b->channels);
+ $this->assertSame($a->width, $b->width);
+ $this->assertSame($a->height, $b->height);
+ $this->assertSame($a->attributes, $b->attributes);
+ $this->assertSame($a->bits, $b->bits);
+ $this->assertSame($a->channels, $b->channels);
// Assert that the properties that should be different are different.
- $this->assertEquals('image/gif', $b->mime);
- $this->assertEquals(IMAGETYPE_GIF, $b->type);
+ $this->assertSame('image/gif', $b->mime);
+ $this->assertSame(IMAGETYPE_GIF, $b->type);
// Clean up after ourselves.
unlink($outFileGif);
@@ -532,8 +532,6 @@ public function testToFileGif()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::toFile
- *
* @since 4.0.0
*/
public function testToFilePng()
@@ -547,14 +545,14 @@ public function testToFilePng()
$b = Image::getImageFileProperties($outFilePng);
// Assert that properties that should be equal are equal.
- $this->assertEquals($a->width, $b->width);
- $this->assertEquals($a->height, $b->height);
- $this->assertEquals($a->attributes, $b->attributes);
- $this->assertEquals($a->bits, $b->bits);
+ $this->assertSame($a->width, $b->width);
+ $this->assertSame($a->height, $b->height);
+ $this->assertSame($a->attributes, $b->attributes);
+ $this->assertSame($a->bits, $b->bits);
// Assert that the properties that should be different are different.
- $this->assertEquals('image/png', $b->mime);
- $this->assertEquals(IMAGETYPE_PNG, $b->type);
+ $this->assertSame('image/png', $b->mime);
+ $this->assertSame(IMAGETYPE_PNG, $b->type);
$this->assertNull($b->channels);
// Clean up after ourselves.
@@ -572,8 +570,6 @@ public function testToFilePng()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::toFile
- *
* @since 4.0.0
*/
public function testToFileJpg()
@@ -589,13 +585,13 @@ public function testToFileJpg()
$b = Image::getImageFileProperties($outFileJpg);
// Assert that properties that should be equal are equal.
- $this->assertEquals($a->width, $b->width);
- $this->assertEquals($a->height, $b->height);
- $this->assertEquals($a->attributes, $b->attributes);
- $this->assertEquals($a->bits, $b->bits);
- $this->assertEquals($a->mime, $b->mime);
- $this->assertEquals($a->type, $b->type);
- $this->assertEquals($a->channels, $b->channels);
+ $this->assertSame($a->width, $b->width);
+ $this->assertSame($a->height, $b->height);
+ $this->assertSame($a->attributes, $b->attributes);
+ $this->assertSame($a->bits, $b->bits);
+ $this->assertSame($a->mime, $b->mime);
+ $this->assertSame($a->type, $b->type);
+ $this->assertSame($a->channels, $b->channels);
// Clean up after ourselves.
unlink($outFileJpg);
@@ -612,8 +608,6 @@ public function testToFileJpg()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::toFile
- *
* @since 4.0.0
*/
public function testToFileWebp()
@@ -627,14 +621,14 @@ public function testToFileWebp()
$b = Image::getImageFileProperties($outFileWebp);
// Assert that properties that should be equal are equal.
- $this->assertEquals($a->width, $b->width);
- $this->assertEquals($a->height, $b->height);
- $this->assertEquals($a->attributes, $b->attributes);
- $this->assertEquals($a->bits, $b->bits);
+ $this->assertSame($a->width, $b->width);
+ $this->assertSame($a->height, $b->height);
+ $this->assertSame($a->attributes, $b->attributes);
+ $this->assertSame($a->bits, $b->bits);
// Assert that properties that should be different are different.
- $this->assertEquals('image/webp', $b->mime);
- $this->assertEquals(IMAGETYPE_WEBP, $b->type);
+ $this->assertSame('image/webp', $b->mime);
+ $this->assertSame(IMAGETYPE_WEBP, $b->type);
$this->assertNull($b->channels);
// Clean up after ourselves.
@@ -652,8 +646,6 @@ public function testToFileWebp()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::toFile
- *
* @since 4.0.0
*/
public function testToFileDefault()
@@ -669,13 +661,13 @@ public function testToFileDefault()
$b = Image::getImageFileProperties($outFileDefault);
// Assert that properties that should be equal are equal.
- $this->assertEquals($a->width, $b->width);
- $this->assertEquals($a->height, $b->height);
- $this->assertEquals($a->attributes, $b->attributes);
- $this->assertEquals($a->bits, $b->bits);
- $this->assertEquals($a->mime, $b->mime);
- $this->assertEquals($a->type, $b->type);
- $this->assertEquals($a->channels, $b->channels);
+ $this->assertSame($a->width, $b->width);
+ $this->assertSame($a->height, $b->height);
+ $this->assertSame($a->attributes, $b->attributes);
+ $this->assertSame($a->bits, $b->bits);
+ $this->assertSame($a->mime, $b->mime);
+ $this->assertSame($a->type, $b->type);
+ $this->assertSame($a->channels, $b->channels);
// Clean up after ourselves.
unlink($outFileDefault);
@@ -686,8 +678,6 @@ public function testToFileDefault()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::getFilterInstance
- *
* @since 4.0.0
*/
public function testGetFilterInstance()
@@ -708,8 +698,6 @@ public function testGetFilterInstance()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::getHeight
- *
* @since 4.0.0
*/
public function testGetHeight()
@@ -720,7 +708,7 @@ public function testGetHeight()
// Create a new Image object from the image handle.
$image = new Image($imageHandle);
- $this->assertEquals(
+ $this->assertSame(
42,
$image->getHeight()
);
@@ -731,8 +719,6 @@ public function testGetHeight()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::getHeight
- *
* @since 4.0.0
*/
public function testGetHeightWithoutLoadedImage()
@@ -749,8 +735,6 @@ public function testGetHeightWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::getWidth
- *
* @since 4.0.0
*/
public function testGetWidth()
@@ -761,7 +745,7 @@ public function testGetWidth()
// Create a new Image object from the image handle.
$image = new Image($imageHandle);
- $this->assertEquals(
+ $this->assertSame(
108,
$image->getWidth()
);
@@ -772,8 +756,6 @@ public function testGetWidth()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::getWidth
- *
* @since 4.0.0
*/
public function testGetWidthWithoutLoadedImage()
@@ -788,8 +770,6 @@ public function testGetWidthWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::getImageFileProperties
- *
* @since 4.0.0
*/
public function testGetImageFilePropertiesWithInvalidFile()
@@ -804,8 +784,6 @@ public function testGetImageFilePropertiesWithInvalidFile()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::generateThumbs
- *
* @since 1.1.3
*/
public function testGenerateThumbsWithoutLoadedImage()
@@ -820,8 +798,6 @@ public function testGenerateThumbsWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::generateThumbs
- *
* @since 1.1.3
*/
public function testGenerateThumbsWithInvalidSize()
@@ -838,8 +814,6 @@ public function testGenerateThumbsWithInvalidSize()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::generateThumbs
- *
* @since 1.1.3
*/
public function testGenerateThumbs()
@@ -849,11 +823,11 @@ public function testGenerateThumbs()
$thumbs = $this->instance->generateThumbs('50x38');
// Verify that the resized image is the correct size.
- $this->assertEquals(
+ $this->assertSame(
34,
imagesy(TestHelper::getValue($thumbs[0], 'handle'))
);
- $this->assertEquals(
+ $this->assertSame(
50,
imagesx(TestHelper::getValue($thumbs[0], 'handle'))
);
@@ -861,11 +835,11 @@ public function testGenerateThumbs()
$thumbs = $this->instance->generateThumbs('50x38', Image::CROP);
// Verify that the resized image is the correct size.
- $this->assertEquals(
+ $this->assertSame(
38,
imagesy(TestHelper::getValue($thumbs[0], 'handle'))
);
- $this->assertEquals(
+ $this->assertSame(
50,
imagesx(TestHelper::getValue($thumbs[0], 'handle'))
);
@@ -873,11 +847,11 @@ public function testGenerateThumbs()
$thumbs = $this->instance->generateThumbs('50x38', Image::CROP_RESIZE);
// Verify that the resized image is the correct size.
- $this->assertEquals(
+ $this->assertSame(
38,
imagesy(TestHelper::getValue($thumbs[0], 'handle'))
);
- $this->assertEquals(
+ $this->assertSame(
50,
imagesx(TestHelper::getValue($thumbs[0], 'handle'))
);
@@ -888,8 +862,6 @@ public function testGenerateThumbs()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::createThumbnails
- *
* @since 1.1.3
*/
public function testcreateThumbnailsWithoutLoadedImage()
@@ -904,8 +876,6 @@ public function testcreateThumbnailsWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::createThumbnails
- *
* @since 1.1.3
*/
public function testGenerateThumbsWithInvalidFolder()
@@ -921,8 +891,6 @@ public function testGenerateThumbsWithInvalidFolder()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::createThumbnails
- *
* @since 1.1.3
*/
public function testcreateThumbnails()
@@ -936,13 +904,13 @@ public function testcreateThumbnails()
$b = Image::getImageFileProperties($outFileGif);
// Assert that properties that should be equal are equal.
- $this->assertEquals(50, $b->width);
- $this->assertEquals(38, $b->height);
- $this->assertEquals($a->bits, $b->bits);
- $this->assertEquals($a->channels, $b->channels);
- $this->assertEquals($a->mime, $b->mime);
- $this->assertEquals($a->type, $b->type);
- $this->assertEquals($a->channels, $b->channels);
+ $this->assertSame(50, $b->width);
+ $this->assertSame(38, $b->height);
+ $this->assertSame($a->bits, $b->bits);
+ $this->assertSame($a->channels, $b->channels);
+ $this->assertSame($a->mime, $b->mime);
+ $this->assertSame($a->type, $b->type);
+ $this->assertSame($a->channels, $b->channels);
unlink($outFileGif);
}
@@ -952,8 +920,6 @@ public function testcreateThumbnails()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::isTransparent
- *
* @since 4.0.0
*/
public function testIsTransparentWithoutLoadedImage()
@@ -970,8 +936,6 @@ public function testIsTransparentWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::isTransparent
- *
* @since 4.0.0
*/
public function testTransparentIsTransparent()
@@ -996,8 +960,6 @@ public function testTransparentIsTransparent()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::isTransparent
- *
* @since 4.0.0
*/
public function testOpaqueIsNotTransparent()
@@ -1017,8 +979,6 @@ public function testOpaqueIsNotTransparent()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::crop
- *
* @since 4.0.0
*/
public function testCropWithoutLoadedImage()
@@ -1051,12 +1011,9 @@ public function testCropWithoutLoadedImage()
*
* @return void
*
- * @dataProvider getCropData
- *
- * @covers \Joomla\CMS\Image\Image::crop
- *
* @since 4.0.0
*/
+ #[DataProvider('getCropData')]
public function testCrop($startHeight, $startWidth, $cropHeight, $cropWidth, $cropTop, $cropLeft, $transparent = false)
{
// Create a image handle of the correct size.
@@ -1096,52 +1053,52 @@ public function testCrop($startHeight, $startWidth, $cropHeight, $cropWidth, $cr
$image->crop($cropWidth, $cropHeight, $actualCropLeft, $actualCropTop, false);
// Verify that the cropped image is the correct size.
- $this->assertEquals(
+ $this->assertSame(
$cropHeight,
imagesy(TestHelper::getValue($image, 'handle'))
);
- $this->assertEquals(
+ $this->assertSame(
$cropWidth,
imagesx(TestHelper::getValue($image, 'handle'))
);
// Validate the correct pixels for the corners.
// Top/Left
- $this->assertEquals(
+ $this->assertSame(
$red,
imagecolorat(TestHelper::getValue($image, 'handle'), 0, 0)
);
- $this->assertEquals(
+ $this->assertSame(
$white,
imagecolorat(TestHelper::getValue($image, 'handle'), 1, 1)
);
// Top/Right
- $this->assertEquals(
+ $this->assertSame(
$red,
imagecolorat(TestHelper::getValue($image, 'handle'), 0, ($cropHeight - 1))
);
- $this->assertEquals(
+ $this->assertSame(
$white,
imagecolorat(TestHelper::getValue($image, 'handle'), 1, ($cropHeight - 2))
);
// Bottom/Left
- $this->assertEquals(
+ $this->assertSame(
$red,
imagecolorat(TestHelper::getValue($image, 'handle'), ($cropWidth - 1), 0)
);
- $this->assertEquals(
+ $this->assertSame(
$white,
imagecolorat(TestHelper::getValue($image, 'handle'), ($cropWidth - 2), 1)
);
// Bottom/Right
- $this->assertEquals(
+ $this->assertSame(
$red,
imagecolorat(TestHelper::getValue($image, 'handle'), ($cropWidth - 1), ($cropHeight - 1))
);
- $this->assertEquals(
+ $this->assertSame(
$white,
imagecolorat(TestHelper::getValue($image, 'handle'), ($cropWidth - 2), ($cropHeight - 2))
);
@@ -1152,8 +1109,6 @@ public function testCrop($startHeight, $startWidth, $cropHeight, $cropWidth, $cr
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::rotate
- *
* @since 4.0.0
*/
public function testRotateWithoutLoadedImage()
@@ -1172,8 +1127,6 @@ public function testRotateWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::rotate
- *
* @since 4.0.0
*/
public function testRotate()
@@ -1199,21 +1152,21 @@ public function testRotate()
// Validate the correct pixels for the ends of the lines.
// Red line.
- $this->assertEquals(
+ $this->assertSame(
$red,
imagecolorat(TestHelper::getValue($image, 'handle'), 50, 5)
);
- $this->assertEquals(
+ $this->assertSame(
$red,
imagecolorat(TestHelper::getValue($image, 'handle'), 50, 95)
);
// White line.
- $this->assertEquals(
+ $this->assertSame(
$white,
imagecolorat(TestHelper::getValue($image, 'handle'), 5, 50)
);
- $this->assertEquals(
+ $this->assertSame(
$white,
imagecolorat(TestHelper::getValue($image, 'handle'), 95, 50)
);
@@ -1224,8 +1177,6 @@ public function testRotate()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::filter
- *
* @since 4.0.0
*/
public function testFilter()
@@ -1233,14 +1184,20 @@ public function testFilter()
$handle = imagecreatetruecolor(1, 1);
// Create the mock filter.
- $mockFilter = $this->getMockForAbstractClass('\\Joomla\\CMS\\Image\\ImageFilter', [$handle], 'ImageFilterMock', true, false, true);
+ $mockFilter = $this->getMockBuilder(ImageFilter::class)
+ ->setConstructorArgs([$handle])
+ ->onlyMethods(['execute'])
+ ->getMock();
// Setup the mock method call expectation.
$mockFilter->expects($this->once())
->method('execute');
// Create a new Image mock
- $mockImage = $this->getMockForAbstractClass('\\Joomla\\CMS\\Image\\Image', [$handle], 'ImageMock', true, false, true, ['getFilterInstance']);
+ $mockImage = $this->getMockBuilder(Image::class)
+ ->setConstructorArgs([$handle])
+ ->onlyMethods(['getFilterInstance'])
+ ->getMock();
$mockImage->expects($this->once())
->method('getFilterInstance')
->willReturn($mockFilter);
@@ -1254,8 +1211,6 @@ public function testFilter()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::filter
- *
* @since 4.0.0
*/
public function testFilterWithoutLoadedImage()
@@ -1273,8 +1228,6 @@ public function testFilterWithoutLoadedImage()
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::filter
- *
* @since 4.0.0
*/
public function testFilterWithInvalidFilterType()
@@ -1299,12 +1252,9 @@ public function testFilterWithInvalidFilterType()
*
* @return void
*
- * @dataProvider getPrepareDimensionsData
- *
- * @covers \Joomla\CMS\Image\Image::prepareDimensions
- *
* @since 4.0.0
*/
+ #[DataProvider('getPrepareDimensionsData')]
public function testPrepareDimensions($inputHeight, $inputWidth, $inputScale, $imageHeight, $imageWidth, $expectedHeight, $expectedWidth)
{
// Create a image handle of the correct size.
@@ -1316,8 +1266,8 @@ public function testPrepareDimensions($inputHeight, $inputWidth, $inputScale, $i
$dimensions = TestHelper::invoke($image, 'prepareDimensions', $inputWidth, $inputHeight, $inputScale);
// Validate the correct response.
- $this->assertEquals($expectedHeight, $dimensions->height);
- $this->assertEquals($expectedWidth, $dimensions->width);
+ $this->assertSame($expectedHeight, $dimensions->height);
+ $this->assertSame($expectedWidth, $dimensions->width);
}
/**
@@ -1325,8 +1275,6 @@ public function testPrepareDimensions($inputHeight, $inputWidth, $inputScale, $i
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::prepareDimensions
- *
* @since 4.0.0
*/
public function testPrepareDimensionsWithInvalidScale()
@@ -1353,12 +1301,9 @@ public function testPrepareDimensionsWithInvalidScale()
*
* @return void
*
- * @dataProvider getSanitizeDimensionData
- *
- * @covers \Joomla\CMS\Image\Image::sanitizeHeight
- *
* @since 4.0.0
*/
+ #[DataProvider('getSanitizeDimensionData')]
public function testSanitizeHeight($inputHeight, $inputWidth, $imageHeight, $imageWidth, $expectedHeight, $expectedWidth)
{
// Create a image handle of the correct size.
@@ -1367,7 +1312,7 @@ public function testSanitizeHeight($inputHeight, $inputWidth, $imageHeight, $ima
$image = new Image($imageHandle);
// Validate the correct response.
- $this->assertEquals(
+ $this->assertSame(
$expectedHeight,
TestHelper::invoke($image, 'sanitizeHeight', $inputHeight, $inputWidth)
);
@@ -1385,12 +1330,9 @@ public function testSanitizeHeight($inputHeight, $inputWidth, $imageHeight, $ima
*
* @return void
*
- * @dataProvider getSanitizeDimensionData
- *
- * @covers \Joomla\CMS\Image\Image::sanitizeWidth
- *
* @since 4.0.0
*/
+ #[DataProvider('getSanitizeDimensionData')]
public function testSanitizeWidth($inputHeight, $inputWidth, $imageHeight, $imageWidth, $expectedHeight, $expectedWidth)
{
// Create a image handle of the correct size.
@@ -1399,7 +1341,7 @@ public function testSanitizeWidth($inputHeight, $inputWidth, $imageHeight, $imag
$image = new Image($imageHandle);
// Validate the correct response.
- $this->assertEquals(
+ $this->assertSame(
$expectedWidth,
TestHelper::invoke($image, 'sanitizeWidth', $inputWidth, $inputHeight)
);
@@ -1413,16 +1355,13 @@ public function testSanitizeWidth($inputHeight, $inputWidth, $imageHeight, $imag
*
* @return void
*
- * @dataProvider getSanitizeOffsetData
- *
- * @covers \Joomla\CMS\Image\Image::sanitizeOffset
- *
* @since 4.0.0
*/
+ #[DataProvider('getSanitizeOffsetData')]
public function testSanitizeOffset($input, $expected)
{
// Validate the correct response.
- $this->assertEquals(
+ $this->assertSame(
$expected,
TestHelper::invoke($this->instance, 'sanitizeOffset', $input)
);
@@ -1433,8 +1372,6 @@ public function testSanitizeOffset($input, $expected)
*
* @return void
*
- * @covers \Joomla\CMS\Image\Image::destroy
- *
* @since 4.0.0
*/
public function testDestroy()
diff --git a/tests/Unit/Libraries/Cms/Installer/Adapter/ModuleAdapterTest.php b/tests/Unit/Libraries/Cms/Installer/Adapter/ModuleAdapterTest.php
index 1964c8a55bf1c..12d087c5d8dcc 100644
--- a/tests/Unit/Libraries/Cms/Installer/Adapter/ModuleAdapterTest.php
+++ b/tests/Unit/Libraries/Cms/Installer/Adapter/ModuleAdapterTest.php
@@ -33,10 +33,11 @@ class ModuleAdapterTest extends UnitTestCase
*/
protected function setUp(): void
{
- $this->moduleAdapter = $this->getMockBuilder(ModuleAdapter::class)
- ->onlyMethods([])
- ->disableOriginalConstructor()
- ->getMock();
+ $this->moduleAdapter = new class () extends ModuleAdapter {
+ public function __construct()
+ {
+ }
+ };
parent::setUp();
}
@@ -78,8 +79,8 @@ public function testgetElement1()
$this->assertNotNull($this->moduleAdapter->manifest);
- $this->assertEquals('mod_quickicon', $this->moduleAdapter->getElement());
- $this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
+ $this->assertSame('mod_quickicon', $this->moduleAdapter->getElement());
+ $this->assertSame('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
}
/**
@@ -96,8 +97,8 @@ public function testgetElement2()
$this->assertNotNull($this->moduleAdapter->manifest);
- $this->assertEquals('mod_sampledata', $this->moduleAdapter->getElement());
- $this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
+ $this->assertSame('mod_sampledata', $this->moduleAdapter->getElement());
+ $this->assertSame('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
}
/**
@@ -119,7 +120,7 @@ public function testgetElementFromElementTag()
$this->assertNotNull($this->moduleAdapter->manifest);
- $this->assertEquals('mod_quickicon', $this->moduleAdapter->getElement());
- $this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
+ $this->assertSame('mod_quickicon', $this->moduleAdapter->getElement());
+ $this->assertSame('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
}
}
diff --git a/tests/Unit/Libraries/Cms/Language/LanguageAwareTraitTest.php b/tests/Unit/Libraries/Cms/Language/LanguageAwareTraitTest.php
index 379029c6b683b..8171aca7c6b92 100644
--- a/tests/Unit/Libraries/Cms/Language/LanguageAwareTraitTest.php
+++ b/tests/Unit/Libraries/Cms/Language/LanguageAwareTraitTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Language\Language;
use Joomla\CMS\Language\LanguageAwareTrait;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Language\LanguageAwareTrait
@@ -24,12 +25,11 @@
class LanguageAwareTraitTest extends UnitTestCase
{
/**
- * @testdox The user language can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The user language can be set and accessed by the trait')]
public function testGetSetLanguage()
{
$language = new Language();
@@ -44,16 +44,15 @@ public function get(): Language
$trait->setLanguage($language);
- $this->assertEquals($language, $trait->get());
+ $this->assertSame($language, $trait->get());
}
/**
- * @testdox The user language can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The user language can be set and accessed by the trait')]
public function testGetLanguageThrowsException()
{
$this->expectException(\UnexpectedValueException::class);
diff --git a/tests/Unit/Libraries/Cms/Layout/BaseLayoutTest.php b/tests/Unit/Libraries/Cms/Layout/BaseLayoutTest.php
index 9990c650ab43c..1ed9e395598a4 100644
--- a/tests/Unit/Libraries/Cms/Layout/BaseLayoutTest.php
+++ b/tests/Unit/Libraries/Cms/Layout/BaseLayoutTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Layout\BaseLayout;
use Joomla\Registry\Registry;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* BaseLayoutTest
@@ -56,46 +57,42 @@ protected function tearDown(): void
}
/**
- * @testdox BaseLayout->setOptions() returns a BaseLayout instance with empty parameter.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->setOptions() returns a BaseLayout instance with empty parameter.')]
public function testSetOptionsReturnsInstanceWithEmptyParameters()
{
$this->assertInstanceOf(BaseLayout::class, $this->baseLayout->setOptions());
}
/**
- * @testdox BaseLayout->setOptions() returns a BaseLayout instance with JRegistry parameter.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->setOptions() returns a BaseLayout instance with JRegistry parameter.')]
public function testSetOptionsReturnsInstanceWithRegistryParameter()
{
- $registry = $this->createMock(Registry::class);
+ $registry = $this->createStub(Registry::class);
$this->assertInstanceOf(BaseLayout::class, $this->baseLayout->setOptions($registry));
}
/**
- * @testdox BaseLayout->setOptions() returns a BaseLayout instance with an array parameter.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->setOptions() returns a BaseLayout instance with an array parameter.')]
public function testSetOptionsReturnsInstanceWithAnArrayParameter()
{
$this->assertInstanceOf(BaseLayout::class, $this->baseLayout->setOptions([]));
}
/**
- * @testdox BaseLayout->getOptions() returns a JRegistry object when options parameter is empty.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->getOptions() returns a JRegistry object when options parameter is empty.')]
public function testGetOptionsReturnsAnEmptyRegistryObject()
{
$options = $this->baseLayout->getOptions();
@@ -105,11 +102,10 @@ public function testGetOptionsReturnsAnEmptyRegistryObject()
}
/**
- * @testdox BaseLayout->getOptions() returns a JRegistry object when options parameter is an array.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->getOptions() returns a JRegistry object when options parameter is an array.')]
public function testGetOptionsReturnsAnRegistryObjectWhenOptionsIsArray()
{
$this->baseLayout->setOptions([]);
@@ -120,14 +116,13 @@ public function testGetOptionsReturnsAnRegistryObjectWhenOptionsIsArray()
}
/**
- * @testdox BaseLayout->getOptions() returns a JRegistry object when options parameter is a JRegistry object.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->getOptions() returns a JRegistry object when options parameter is a JRegistry object.')]
public function testGetOptionsReturnsARegistryObjectWhenOptionsParameterIsRegistryObject()
{
- $registry = $this->createMock(Registry::class);
+ $registry = $this->createStub(Registry::class);
$this->baseLayout->setOptions($registry);
$options = $this->baseLayout->getOptions();
@@ -136,11 +131,10 @@ public function testGetOptionsReturnsARegistryObjectWhenOptionsParameterIsRegist
}
/**
- * @testdox BaseLayout->resetOptions() and check options is empty.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('BaseLayout->resetOptions() and check options is empty.')]
public function testResetOptions()
{
$this->baseLayout->setOptions(['not' => 'empty']);
@@ -158,27 +152,27 @@ public function testResetOptions()
*/
public function testEscapingSpecialCharactersIntoHtmlEntities()
{
- $this->assertThat(
+ $this->assertSame(
+ '&',
$this->baseLayout->escape('&'),
- $this->equalTo('&'),
'Test the ampersand is converted to HTML code'
);
- $this->assertThat(
+ $this->assertSame(
+ '"',
$this->baseLayout->escape('"'),
- $this->equalTo('"'),
'Test the double quote is converted to HTML code'
);
- $this->assertThat(
+ $this->assertSame(
+ "'",
$this->baseLayout->escape("'"),
- $this->equalTo("'"),
'Test the single quote is converted to HTML code'
);
- $this->assertThat(
+ $this->assertSame(
+ "<a href='test'>Test</a>",
$this->baseLayout->escape("Test"),
- $this->equalTo("<a href='test'>Test</a>"),
'Test the characters <> are not converted'
);
}
@@ -198,55 +192,51 @@ public function testAddDebugMessageToTheQueue()
$messages = $this->baseLayout->getDebugMessages();
$this->assertCount(1, $messages);
- $this->assertEquals($message, $messages[0]);
+ $this->assertSame($message, $messages[0]);
}
/**
- * @testdox JLayoutBase->getDebugMessages() retrieves a list of debug messages in an array.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('JLayoutBase->getDebugMessages() retrieves a list of debug messages in an array.')]
public function testRetrievingTheListOfDebugMessagesIsAnArray()
{
$this->assertIsArray($this->baseLayout->getDebugMessages());
}
/**
- * @testdox JLayoutBase->renderDebugMessages() returns debug message
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('JLayoutBase->renderDebugMessages() returns debug message')]
public function testRenderDebugMessageReturnsDebugMessage()
{
$this->baseLayout->addDebugMessage('Debug message 1');
- $this->assertEquals("Debug message 1", $this->baseLayout->renderDebugMessages());
+ $this->assertSame("Debug message 1", $this->baseLayout->renderDebugMessages());
}
/**
- * @testdox JLayoutBase->renderDebugMessages() returns string of messages separated by newline character.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('JLayoutBase->renderDebugMessages() returns string of messages separated by newline character.')]
public function testRenderDebugMessageReturnsStringOfMessagesSeparatedByNewlineCharacter()
{
$this->baseLayout->addDebugMessage('Debug message 1');
$this->baseLayout->addDebugMessage('Debug message 2');
- $this->assertEquals("Debug message 1\nDebug message 2", $this->baseLayout->renderDebugMessages());
+ $this->assertSame("Debug message 1\nDebug message 2", $this->baseLayout->renderDebugMessages());
}
/**
- * @testdox JLayoutBase->render() returns an empty string.
- *
* @return void
* @since 3.3.7
*/
+ #[TestDox('JLayoutBase->render() returns an empty string.')]
public function testRenderReturnsAnEmptyString()
{
- $this->assertEquals('', $this->baseLayout->render('Data'), 'BaseLayout::render does not render an output');
+ $this->assertSame('', $this->baseLayout->render('Data'), 'BaseLayout::render does not render an output');
}
}
diff --git a/tests/Unit/Libraries/Cms/MVC/Controller/BaseControllerTest.php b/tests/Unit/Libraries/Cms/MVC/Controller/BaseControllerTest.php
index 54b36a58c18da..e1d9cf63cc199 100644
--- a/tests/Unit/Libraries/Cms/MVC/Controller/BaseControllerTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Controller/BaseControllerTest.php
@@ -10,7 +10,6 @@
namespace Joomla\Tests\Unit\Libraries\Cms\MVC\Controller;
-use Exception;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Application\CMSWebApplicationInterface;
@@ -25,6 +24,7 @@
use Joomla\CMS\User\User;
use Joomla\Input\Input;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Controller\BaseController
@@ -32,19 +32,17 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The BaseController
- *
* @since 4.2.0
*/
+#[TestDox('The BaseController')]
class BaseControllerTest extends UnitTestCase
{
/**
- * @testdox contains the right dependencies
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('contains the right dependencies')]
public function testInjectedDependencies()
{
$mvcFactory = $this->createStub(MVCFactoryInterface::class);
@@ -68,32 +66,30 @@ public function getInput(): Input
}
};
- $this->assertEquals($mvcFactory, $controller->getMVCFactory());
- $this->assertEquals($input, $controller->getInput());
+ $this->assertSame($mvcFactory, $controller->getMVCFactory());
+ $this->assertSame($input, $controller->getInput());
}
/**
- * @testdox gets the injected name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected name')]
public function testGetInjectedName()
{
$controller = new class (['name' => 'unit test', 'base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
};
- $this->assertEquals('unit test', $controller->getName());
+ $this->assertSame('unit test', $controller->getName());
}
/**
- * @testdox compiles its own name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('compiles its own name')]
public function testGetCompiledName()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -103,12 +99,11 @@ public function testGetCompiledName()
}
/**
- * @testdox lists the correct tasks
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('lists the correct tasks')]
public function testAvailableTasks()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -117,16 +112,15 @@ public function unit()
}
};
- $this->assertEquals(['unit', 'display'], $controller->getTasks());
+ $this->assertSame(['unit', 'display'], $controller->getTasks());
}
/**
- * @testdox can unregister a task
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can unregister a task')]
public function testUnregisterTask()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -141,12 +135,11 @@ public function list()
}
/**
- * @testdox executes a task
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('executes a task')]
public function testExecuteTask()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -156,17 +149,16 @@ public function unit()
}
};
- $this->assertEquals('unit test', $controller->execute('unit'));
- $this->assertEquals('unit', $controller->getTask());
+ $this->assertSame('unit test', $controller->execute('unit'));
+ $this->assertSame('unit', $controller->getTask());
}
/**
- * @testdox can execute the injected default task
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can execute the injected default task')]
public function testExecuteInjectedDefaultTask()
{
$controller = new class (['default_task' => 'unit', 'base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -176,17 +168,16 @@ public function unit()
}
};
- $this->assertEquals('unit test', $controller->execute('unit'));
- $this->assertEquals('unit', $controller->getTask());
+ $this->assertSame('unit test', $controller->execute('unit'));
+ $this->assertSame('unit', $controller->getTask());
}
/**
- * @testdox executes the display default task
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('executes the display default task')]
public function testExecuteDisplayDefaultTask()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -196,17 +187,16 @@ public function display($cachable = false, $urlparams = [])
}
};
- $this->assertEquals('unit test', $controller->execute(''));
- $this->assertEquals('', $controller->getTask());
+ $this->assertSame('unit test', $controller->execute(''));
+ $this->assertSame('', $controller->getTask());
}
/**
- * @testdox throws an exception when a task doesn't exist
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("throws an exception when a task doesn't exist")]
public function testExecuteTaskWhichDoesntExist()
{
$controller = new class (['default_task' => 'invalid', 'base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -218,12 +208,11 @@ public function testExecuteTaskWhichDoesntExist()
}
/**
- * @testdox returns the correct model
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct model')]
public function testGetModel()
{
$mvcFactory = $this->createStub(MVCFactoryInterface::class);
@@ -234,20 +223,19 @@ public function testGetModel()
$controller = new class (['base_path' => __DIR__], $mvcFactory, $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
};
- $this->assertEquals($model, $controller->getModel());
+ $this->assertSame($model, $controller->getModel());
}
/**
- * @testdox returns the correct model with an injected prefix
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct model with an injected prefix')]
public function testGetModelWithInjectedPrefix()
{
$mvcFactory = $this->createMock(LegacyFactory::class);
- $mvcFactory->expects($this->once())->method('createModel')->with($this->equalTo('Unit'), $this->equalTo('Test'));
+ $mvcFactory->expects($this->once())->method('createModel')->with('Unit', 'Test');
$controller = new class (['model_prefix' => 'Test', 'base_path' => __DIR__], $mvcFactory, $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
};
@@ -255,16 +243,15 @@ public function testGetModelWithInjectedPrefix()
}
/**
- * @testdox returns the correct model with the app name prefix
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct model with the app name prefix')]
public function testGetModelWithAppNamePrefix()
{
$mvcFactory = $this->createMock(MVCFactoryInterface::class);
- $mvcFactory->expects($this->once())->method('createModel')->with($this->equalTo('Unit'), $this->equalTo('Test'));
+ $mvcFactory->expects($this->once())->method('createModel')->with('Unit', 'Test');
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getName')->willReturn('Test');
@@ -275,12 +262,11 @@ public function testGetModelWithAppNamePrefix()
}
/**
- * @testdox returns false when no model is available
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns false when no model is available')]
public function testGetNullModel()
{
$mvcFactory = $this->createStub(MVCFactoryInterface::class);
@@ -292,12 +278,11 @@ public function testGetNullModel()
}
/**
- * @testdox returns the correct model with the identity from the app
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct model with the identity from the app')]
public function testGetModelWithIdentity()
{
$mvcFactory = $this->createStub(MVCFactoryInterface::class);
@@ -318,16 +303,15 @@ public function getUser(): User
$controller = new class (['base_path' => __DIR__], $mvcFactory, $app, new Input()) extends BaseController {
};
- $this->assertEquals($user, $controller->getModel()->getUser());
+ $this->assertSame($user, $controller->getModel()->getUser());
}
/**
- * @testdox returns the correct view
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct view')]
public function testGetView()
{
$view = new class (['name' => 'test']) extends AbstractView {
@@ -343,20 +327,19 @@ public function display($tpl = null)
$controller = new class (['base_path' => __DIR__], $mvcFactory, $app, new Input()) extends BaseController {
};
- $this->assertEquals($view, $controller->getView('testGetView'));
+ $this->assertSame($view, $controller->getView('testGetView'));
}
/**
- * @testdox returns the correct view with an injected prefix
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct view with an injected prefix')]
public function testGetViewWithInjectedPrefix()
{
$mvcFactory = $this->createMock(LegacyFactory::class);
- $mvcFactory->expects($this->once())->method('createView')->with($this->equalTo('Unit'), $this->equalTo('TestView'))
+ $mvcFactory->expects($this->once())->method('createView')->with('Unit', 'TestView')
->willReturn($this->createStub(AbstractView::class));
$controller = new class (['name' => 'Test', 'base_path' => __DIR__], $mvcFactory, $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
@@ -365,12 +348,11 @@ public function testGetViewWithInjectedPrefix()
}
/**
- * @testdox throws an exception when no view is available
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('throws an exception when no view is available')]
public function testGetNullView()
{
$mvcFactory = $this->createStub(MVCFactoryInterface::class);
@@ -384,12 +366,11 @@ public function testGetNullView()
}
/**
- * @testdox returns the correct view with the identity from the app
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the correct view with the identity from the app')]
public function testGetViewWithIdentity()
{
$view = new class (['name' => 'test']) extends AbstractView implements CurrentUserInterface {
@@ -415,16 +396,15 @@ public function getUser(): User
$controller = new class (['base_path' => __DIR__], $mvcFactory, $app, new Input()) extends BaseController {
};
- $this->assertEquals($user, $controller->getView('testGetViewWithIdentity')->getUser());
+ $this->assertSame($user, $controller->getView('testGetViewWithIdentity')->getUser());
}
/**
- * @testdox gets the injected view path
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected view path')]
public function testInjectViewPath()
{
$path = \dirname(__DIR__);
@@ -436,16 +416,15 @@ public function getPaths()
};
$this->arrayHasKey('view', $controller->getPaths());
- $this->assertEquals([$path . '/'], $controller->getPaths()['view']);
+ $this->assertSame([$path . '/'], $controller->getPaths()['view']);
}
/**
- * @testdox can add a view path
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can add a view path')]
public function testAddViewPath()
{
$controller = new class (['name' => 'unit test', 'base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class)) extends BaseController {
@@ -462,12 +441,11 @@ public function getPaths()
}
/**
- * @testdox can display
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can display')]
public function testDisplay()
{
$doc = $this->createStub(Document::class);
@@ -492,16 +470,15 @@ public function display($tpl = null)
$controller->display(false);
- $this->assertEquals('unit test', $view->value);
+ $this->assertSame('unit test', $view->value);
}
/**
- * @testdox can display and sets a model on the view
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can display and sets a model on the view')]
public function testDisplayWithModel()
{
$doc = $this->createStub(Document::class);
@@ -527,16 +504,15 @@ public function display($tpl = null)
$controller->display(false);
- $this->assertEquals($model, $view->getModel());
+ $this->assertSame($model, $view->getModel());
}
/**
- * @testdox can check the edit id when it exists in user state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can check the edit id when it exists in user state')]
public function testCheckEditIdExist()
{
$app = $this->createStub(CMSWebApplicationInterface::class);
@@ -553,12 +529,11 @@ public function checkEditId($context, $id)
}
/**
- * @testdox cannot check the edit id when it doesn't exists in user state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("cannot check the edit id when it doesn't exists in user state")]
public function testCheckEditIdNotExist()
{
$app = $this->createStub(CMSWebApplicationInterface::class);
@@ -575,12 +550,11 @@ public function checkEditId($context, $id)
}
/**
- * @testdox cannot check the edit id when it is empty
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('cannot check the edit id when it is empty')]
public function testCheckEditEmptyId()
{
$app = $this->createStub(CMSWebApplicationInterface::class);
@@ -597,16 +571,15 @@ public function checkEditId($context, $id)
}
/**
- * @testdox can hold the edit id in app user state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can hold the edit id in app user state')]
public function testHoldEditId()
{
$app = $this->createMock(CMSWebApplicationInterface::class);
- $app->expects($this->once())->method('setUserState')->with($this->equalTo('unit.id'), $this->equalTo([1]));
+ $app->expects($this->once())->method('setUserState')->with('unit.id', [1]);
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $app, new Input()) extends BaseController {
public function holdEditId($context, $id)
@@ -618,12 +591,11 @@ public function holdEditId($context, $id)
}
/**
- * @testdox cannot hold an empty edit id in app user state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('cannot hold an empty edit id in app user state')]
public function testHoldEditEmptyId()
{
$app = $this->createMock(CMSWebApplicationInterface::class);
@@ -639,17 +611,16 @@ public function holdEditId($context, $id)
}
/**
- * @testdox can release the edit id from app user state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can release the edit id from app user state')]
public function testReleaseEditId()
{
$app = $this->createMock(CMSWebApplicationInterface::class);
$app->method('getUserState')->willReturn([1, 2]);
- $app->expects($this->once())->method('setUserState')->with($this->equalTo('unit.id'), $this->equalTo([1 => 2]));
+ $app->expects($this->once())->method('setUserState')->with('unit.id', [1 => 2]);
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $app, new Input()) extends BaseController {
public function releaseEditId($context, $id)
@@ -661,12 +632,11 @@ public function releaseEditId($context, $id)
}
/**
- * @testdox cannot release the edit id from app user state when it doesn't exist
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("cannot release the edit id from app user state when it doesn't exist")]
public function testReleaseInvalidEditId()
{
$app = $this->createMock(CMSWebApplicationInterface::class);
@@ -683,12 +653,11 @@ public function releaseEditId($context, $id)
}
/**
- * @testdox sets the correct redirect, message and type
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('sets the correct redirect, message and type')]
public function testSetRedirect()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
@@ -709,18 +678,17 @@ public function getMessageType()
};
$controller->setRedirect('unit/test', 'unit', 'test');
- $this->assertEquals('unit/test', $controller->getRedirect());
- $this->assertEquals('unit', $controller->getMessage());
- $this->assertEquals('test', $controller->getMessageType());
+ $this->assertSame('unit/test', $controller->getRedirect());
+ $this->assertSame('unit', $controller->getMessage());
+ $this->assertSame('test', $controller->getMessageType());
}
/**
- * @testdox sets the correct redirect and has the default type 'message'
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("sets the correct redirect and has the default type 'message'")]
public function testSetRedirectWithEmptyType()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
@@ -731,21 +699,20 @@ public function getMessageType()
};
$controller->setRedirect('unit/test');
- $this->assertEquals('message', $controller->getMessageType());
+ $this->assertSame('message', $controller->getMessageType());
}
/**
- * @testdox does a redirect on the internal app instance
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does a redirect on the internal app instance')]
public function testRedirect()
{
$app = $this->createMock(CMSWebApplicationInterface::class);
- $app->expects($this->once())->method('redirect')->with($this->equalTo('unit/test'));
- $app->expects($this->once())->method('enqueueMessage')->with($this->equalTo('unit test'));
+ $app->expects($this->once())->method('redirect')->with('unit/test');
+ $app->expects($this->once())->method('enqueueMessage')->with('unit test');
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $app, new Input()) extends BaseController {
public function redirect()
@@ -761,12 +728,11 @@ public function redirect()
}
/**
- * @testdox sets the correct message and type
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('sets the correct message and type')]
public function testSetMessage()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
@@ -782,17 +748,16 @@ public function getMessageType()
};
$this->assertEmpty($controller->setMessage('unit', 'test'));
- $this->assertEquals('unit', $controller->getMessage());
- $this->assertEquals('test', $controller->getMessageType());
+ $this->assertSame('unit', $controller->getMessage());
+ $this->assertSame('test', $controller->getMessageType());
}
/**
- * @testdox returns the old message when a second time set
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the old message when a second time set')]
public function testSetMessageTwice()
{
$controller = new class (['base_path' => __DIR__], $this->createStub(MVCFactoryInterface::class), $this->createStub(CMSApplicationInterface::class), new Input()) extends BaseController {
@@ -803,6 +768,6 @@ public function getMessage()
};
$controller->setMessage('unit');
- $this->assertEquals('unit', $controller->setMessage('test'));
+ $this->assertSame('unit', $controller->setMessage('test'));
}
}
diff --git a/tests/Unit/Libraries/Cms/MVC/Model/BaseModelTest.php b/tests/Unit/Libraries/Cms/MVC/Model/BaseModelTest.php
index d1fb400357d68..a87a080f7f832 100644
--- a/tests/Unit/Libraries/Cms/MVC/Model/BaseModelTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Model/BaseModelTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\MVC\Model\BaseModel;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\BaseModel
@@ -19,34 +20,31 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The BaseModel
- *
* @since 4.2.0
*/
+#[TestDox('The BaseModel')]
class BaseModelTest extends UnitTestCase
{
/**
- * @testdox gets the injected name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected name')]
public function testGetInjectedName()
{
$model = new class (['name' => 'unit test']) extends BaseModel {
};
- $this->assertEquals('unit test', $model->getName());
+ $this->assertSame('unit test', $model->getName());
}
/**
- * @testdox compiles its own name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('compiles its own name')]
public function testGetCompiledName()
{
$model = new class () extends BaseModel {
@@ -56,28 +54,26 @@ public function testGetCompiledName()
}
/**
- * @testdox gets the injected state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected state')]
public function testGetInjectedState()
{
$state = ['test' => 'unit'];
$model = new class (['state' => $state]) extends BaseModel {
};
- $this->assertEquals($state, $model->getState());
+ $this->assertSame($state, $model->getState());
}
/**
- * @testdox does populate the state before accessing it
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does populate the state before accessing it')]
public function testAcceptRequest()
{
$model = new class (['ignore_request' => false]) extends BaseModel {
@@ -91,12 +87,11 @@ protected function populateState()
}
/**
- * @testdox does ignore to populate the state before accessing it
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does ignore to populate the state before accessing it')]
public function testIgnoreRequest()
{
$model = new class (['ignore_request' => true]) extends BaseModel {
diff --git a/tests/Unit/Libraries/Cms/MVC/Model/DatabaseModelTest.php b/tests/Unit/Libraries/Cms/MVC/Model/DatabaseModelTest.php
index 7915635164e30..7280ab3d6cc49 100644
--- a/tests/Unit/Libraries/Cms/MVC/Model/DatabaseModelTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Model/DatabaseModelTest.php
@@ -10,13 +10,13 @@
namespace Joomla\Tests\Unit\Libraries\Cms\MVC\Model;
-use Exception;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\User\User;
use Joomla\Database\DatabaseInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\BaseDatabaseModel
@@ -24,19 +24,17 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The BaseDatabaseModel
- *
* @since 4.2.0
*/
+#[TestDox('The BaseDatabaseModel')]
class DatabaseModelTest extends UnitTestCase
{
/**
- * @testdox contains the right db and MVC factory
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('contains the right db and MVC factory')]
public function testInjectedDatabaseAndMVCFactory()
{
$db = $this->createStub(DatabaseInterface::class);
@@ -54,17 +52,16 @@ public function getMVCFactory(): MVCFactoryInterface
}
};
- $this->assertEquals($db, $model->getDatabase());
- $this->assertEquals($mvcFactory, $model->getMVCFactory());
+ $this->assertSame($db, $model->getDatabase());
+ $this->assertSame($mvcFactory, $model->getMVCFactory());
}
/**
- * @testdox returns the right table
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the right table')]
public function testGetTable()
{
$table = $this->createStub(Table::class);
@@ -74,16 +71,15 @@ public function testGetTable()
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $mvcFactory) extends BaseDatabaseModel {
};
- $this->assertEquals($table, $model->getTable());
+ $this->assertSame($table, $model->getTable());
}
/**
- * @testdox throws an exception when no table can be created
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('throws an exception when no table can be created')]
public function testGetTableWhenNull()
{
$mvcFactory = $this->createStub(MVCFactoryInterface::class);
@@ -97,12 +93,11 @@ public function testGetTableWhenNull()
}
/**
- * @testdox returns the right list when the query is an object
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the right list when the query is an object')]
public function testGetListFromObject()
{
$db = $this->createStub(DatabaseInterface::class);
@@ -115,16 +110,15 @@ public function _getList($query, $limitstart = 0, $limit = 0)
}
};
- $this->assertEquals([1], $model->_getList($this->getQueryStub($db), 0, 1));
+ $this->assertSame([1], $model->_getList($this->getQueryStub($db), 0, 1));
}
/**
- * @testdox returns the right list when the query is a string
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the right list when the query is a string')]
public function testGetListFromString()
{
$db = $this->createStub(DatabaseInterface::class);
@@ -138,16 +132,15 @@ public function _getList($query, $limitstart = 0, $limit = 0)
}
};
- $this->assertEquals([1], $model->_getList('query', 0, 1));
+ $this->assertSame([1], $model->_getList('query', 0, 1));
}
/**
- * @testdox returns the right list count from a query object
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the right list count from a query object')]
public function testGetListCountFromObject()
{
$db = $this->createStub(DatabaseInterface::class);
@@ -160,16 +153,15 @@ public function _getListCount($query)
}
};
- $this->assertEquals(5, $model->_getListCount($this->getQueryStub($db)));
+ $this->assertSame(5, $model->_getListCount($this->getQueryStub($db)));
}
/**
- * @testdox returns the right list count from a query object
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the right list count from a query object')]
public function testGetListCountFromObjectTypeSelect()
{
$db = $this->createStub(DatabaseInterface::class);
@@ -185,16 +177,15 @@ public function _getListCount($query)
$query = $this->getQueryStub($db);
$query->select('*');
- $this->assertEquals(5, $model->_getListCount($query));
+ $this->assertSame(5, $model->_getListCount($query));
}
/**
- * @testdox returns the right list count from a query string
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('returns the right list count from a query string')]
public function testGetListCountFromString()
{
$db = $this->createStub(DatabaseInterface::class);
@@ -207,16 +198,15 @@ public function _getListCount($query)
}
};
- $this->assertEquals(5, $model->_getListCount('query'));
+ $this->assertSame(5, $model->_getListCount('query'));
}
/**
- * @testdox can't determine the checked out state of an item that has not the required field
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't determine the checked out state of an item that has not the required field")]
public function testCheckedOutWithoutField()
{
$table = $this->createStub(Table::class);
@@ -232,12 +222,11 @@ public function testCheckedOutWithoutField()
}
/**
- * @testdox can determine the checked out state of an item with the same user
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can determine the checked out state of an item with the same user')]
public function testCheckedOutWithCheckedOutUser()
{
$table = $this->createStub(Table::class);
@@ -257,12 +246,11 @@ public function testCheckedOutWithCheckedOutUser()
}
/**
- * @testdox can determine the checked out state of an item with a different user
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can determine the checked out state of an item with a different user')]
public function testCheckedOutWithNotCheckedOutUser()
{
$table = $this->createStub(Table::class);
@@ -282,12 +270,11 @@ public function testCheckedOutWithNotCheckedOutUser()
}
/**
- * @testdox can determine the checked out state of an item when the user is not set
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can determine the checked out state of an item when the user is not set')]
public function testCheckedOutWitFieldEmptyUserSet()
{
$table = $this->createStub(Table::class);
diff --git a/tests/Unit/Libraries/Cms/MVC/Model/FormModelTest.php b/tests/Unit/Libraries/Cms/MVC/Model/FormModelTest.php
index 5f7449e0f2385..92ee11e2490ad 100644
--- a/tests/Unit/Libraries/Cms/MVC/Model/FormModelTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Model/FormModelTest.php
@@ -16,6 +16,7 @@
use Joomla\CMS\User\User;
use Joomla\Database\DatabaseInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\FormModel
@@ -23,19 +24,17 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The FormModel
- *
* @since 4.2.0
*/
+#[TestDox('The FormModel')]
class FormModelTest extends UnitTestCase
{
/**
- * @testdox can checkin a record
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkin a record')]
public function testSuccessfulCheckin()
{
$table = $this->createStub(Table::class);
@@ -60,12 +59,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can checkin a record when the id is 0
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkin a record when the id is 0')]
public function testSuccessfulCheckinWithEmptyRecord()
{
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends FormModel {
@@ -79,12 +77,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkin a record
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkin a record")]
public function testFailedCheckin()
{
$table = $this->createStub(Table::class);
@@ -114,12 +111,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkin a record when load of the table fails
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkin a record when load of the table fails")]
public function testFailedCheckinLoad()
{
$table = $this->createStub(Table::class);
@@ -141,12 +137,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can checkin a record when the table has not the required fields
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkin a record when the table has not the required fields')]
public function testSuccessfulCheckinFieldNotAvailableCheck()
{
$table = $this->createStub(Table::class);
@@ -169,12 +164,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkin a record when is checked out as different user and current user is not admin
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkin a record when is checked out as different user and current user is not admin")]
public function testSuccessfulCheckinWhenCurrentUserIsNotAdmin()
{
$table = $this->createStub(Table::class);
@@ -202,12 +196,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can checkin a record when is checked out as different user and current user is admin
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkin a record when is checked out as different user and current user is admin')]
public function testSuccessfulCheckinWhenCurrentUserAdmin()
{
$table = $this->createStub(Table::class);
@@ -236,12 +229,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can checkout a record
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkout a record')]
public function testSuccessfulCheckout()
{
$table = $this->createStub(Table::class);
@@ -270,12 +262,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can checkout a record when the id is 0
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkout a record when the id is 0')]
public function testSuccessfulCheckoutWithEmptyRecord()
{
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends FormModel {
@@ -289,12 +280,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkout a record
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkout a record")]
public function testFailedCheckout()
{
$table = $this->createStub(Table::class);
@@ -328,12 +318,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkout a record when the current user is a guest
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkout a record when the current user is a guest")]
public function testFailedCheckoutAsGuest()
{
$table = $this->createStub(Table::class);
@@ -358,12 +347,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkout a record when load of the table fails
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkout a record when load of the table fails")]
public function testFailedCheckoutLoad()
{
$table = $this->createStub(Table::class);
@@ -384,12 +372,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can checkout a record when the table has not the required fields
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can checkout a record when the table has not the required fields')]
public function testSuccessfulCheckoutFieldNotAvailableCheck()
{
$table = $this->createStub(Table::class);
@@ -411,12 +398,11 @@ public function getForm($data = [], $loadData = true)
}
/**
- * @testdox can't checkout a record when is checked out as different user
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox("can't checkout a record when is checked out as different user")]
public function testSuccessfulCheckoutWhenCurrentUserIsDifferent()
{
$table = $this->createStub(Table::class);
diff --git a/tests/Unit/Libraries/Cms/MVC/Model/ItemModelTest.php b/tests/Unit/Libraries/Cms/MVC/Model/ItemModelTest.php
index 035671cf9ea23..283b9debd5418 100644
--- a/tests/Unit/Libraries/Cms/MVC/Model/ItemModelTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Model/ItemModelTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\MVC\Model\ItemModel;
use Joomla\Database\DatabaseInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\ItemModel
@@ -21,19 +22,17 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The FormModel
- *
* @since 4.2.0
*/
+#[TestDox('The FormModel')]
class ItemModelTest extends UnitTestCase
{
/**
- * @testdox store id is not empty
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('store id is not empty')]
public function testGetStoreId()
{
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends ItemModel {
@@ -51,12 +50,11 @@ public function getItem($pk = null)
}
/**
- * @testdox store id is not empty on an empty id
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('store id is not empty on an empty id')]
public function testGetEmptyStoreId()
{
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends ItemModel {
@@ -74,12 +72,11 @@ public function getItem($pk = null)
}
/**
- * @testdox store id is different with different ids
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('store id is different with different ids')]
public function testStoreIdWithDifferentIds()
{
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends ItemModel {
@@ -97,12 +94,11 @@ public function getItem($pk = null)
}
/**
- * @testdox store id is the same with same ids
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('store id is the same with same ids')]
public function testStoreIdWithSameIds()
{
$model = new class (['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends ItemModel {
diff --git a/tests/Unit/Libraries/Cms/MVC/Model/StateBehaviorTraitTest.php b/tests/Unit/Libraries/Cms/MVC/Model/StateBehaviorTraitTest.php
index e619278cef1b7..cf6e57b3e24c8 100644
--- a/tests/Unit/Libraries/Cms/MVC/Model/StateBehaviorTraitTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Model/StateBehaviorTraitTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\MVC\Model\State;
use Joomla\CMS\MVC\Model\StateBehaviorTrait;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\StateBehaviorTrait
@@ -20,19 +21,17 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The StateBehaviorTrait
- *
* @since 4.2.0
*/
+#[TestDox('The StateBehaviorTrait')]
class StateBehaviorTraitTest extends UnitTestCase
{
/**
- * @testdox can fetch an empty state
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can fetch an empty state')]
public function testGetEmptyState()
{
$trait = new class () {
@@ -43,12 +42,11 @@ public function testGetEmptyState()
}
/**
- * @testdox does populate the state when a state is requested
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does populate the state when a state is requested')]
public function testStatePopulation()
{
$trait = new class () {
@@ -64,12 +62,11 @@ protected function populateState()
}
/**
- * @testdox does not populated the state when already set
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does not populated the state when already set')]
public function testStatePopulationIgnored()
{
$trait = new class () {
@@ -90,12 +87,11 @@ protected function populateState()
}
/**
- * @testdox sets the state correctly
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('sets the state correctly')]
public function testSetState()
{
$trait = new class () {
@@ -107,12 +103,11 @@ public function testSetState()
}
/**
- * @testdox overwrites the state when it is not populated
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('overwrites the state when it is not populated')]
public function testSetStateWithPopulation()
{
$trait = new class () {
@@ -125,16 +120,15 @@ protected function populateState()
};
$trait->setState('state.status', 2);
- $this->assertEquals(1, $trait->getState('state.status'));
+ $this->assertSame(1, $trait->getState('state.status'));
}
/**
- * @testdox does not overwrite the state when it is already populated
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does not overwrite the state when it is already populated')]
public function testSetStateWithPrePopulation()
{
$trait = new class () {
@@ -148,6 +142,6 @@ protected function populateState()
$trait->getState();
$trait->setState('state.status', 2);
- $this->assertEquals(2, $trait->getState('state.status'));
+ $this->assertSame(2, $trait->getState('state.status'));
}
}
diff --git a/tests/Unit/Libraries/Cms/MVC/Model/StateTest.php b/tests/Unit/Libraries/Cms/MVC/Model/StateTest.php
index bb9cfa8edd176..f4c79a1623232 100644
--- a/tests/Unit/Libraries/Cms/MVC/Model/StateTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/Model/StateTest.php
@@ -12,6 +12,7 @@
use Joomla\CMS\MVC\Model\State;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\State
@@ -19,67 +20,62 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The State
- *
* @since 5.0.0
*/
+#[TestDox('The State')]
class StateTest extends UnitTestCase
{
/**
- * @testdox can set and get a property
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('can set and get a property')]
public function testGetProperties()
{
$state = new State();
$state->set('unit', 'test');
$this->assertCount(1, $state->getProperties());
- $this->assertEquals('test', $state->getProperties()['unit']);
+ $this->assertSame('test', $state->getProperties()['unit']);
}
/**
- * @testdox can access property
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('can access property')]
public function testGetDirectPropertyAccess()
{
$state = new State();
$state->set('unit', 'test');
- $this->assertEquals('test', $state->unit);
- $this->assertEquals('test', $state->get('unit'));
+ $this->assertSame('test', $state->unit);
+ $this->assertSame('test', $state->get('unit'));
}
/**
- * @testdox can set a value through the direct property
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('can set a value through the direct property')]
public function testSetDirectPropertyAccess()
{
$state = new State();
$state->unit = 'test';
- $this->assertEquals('test', $state->unit);
- $this->assertEquals('test', $state->get('unit'));
+ $this->assertSame('test', $state->unit);
+ $this->assertSame('test', $state->get('unit'));
}
/**
- * @testdox can return if a property is set
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('can return if a property is set')]
public function testIsSet()
{
$state = new State();
@@ -89,12 +85,11 @@ public function testIsSet()
}
/**
- * @testdox can return if a property is not set
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('can return if a property is not set')]
public function testIsNotSet()
{
$state = new State();
@@ -103,17 +98,16 @@ public function testIsNotSet()
}
/**
- * @testdox can set and get an empty value
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('can set and get an empty value')]
public function testEmptyValue()
{
$state = new State();
$state->set('unit', '');
- $this->assertEquals('', $state->get('unit', 'test'));
+ $this->assertSame('', $state->get('unit', 'test'));
}
}
diff --git a/tests/Unit/Libraries/Cms/MVC/View/AbstractViewTest.php b/tests/Unit/Libraries/Cms/MVC/View/AbstractViewTest.php
index 75cd908622eb1..faaaab7da846c 100644
--- a/tests/Unit/Libraries/Cms/MVC/View/AbstractViewTest.php
+++ b/tests/Unit/Libraries/Cms/MVC/View/AbstractViewTest.php
@@ -16,6 +16,7 @@
use Joomla\Event\Event;
use Joomla\Event\EventInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\View\AbstractView
@@ -23,19 +24,17 @@
* @package Joomla.UnitTest
* @subpackage MVC
*
- * @testdox The AbstractView
- *
* @since 4.2.0
*/
+#[TestDox('The AbstractView')]
class AbstractViewTest extends UnitTestCase
{
/**
- * @testdox gets the injected name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected name')]
public function testGetInjectedName()
{
$view = new class (['name' => 'unit test']) extends AbstractView {
@@ -44,16 +43,15 @@ public function display($tpl = null)
}
};
- $this->assertEquals('unit test', $view->getName());
+ $this->assertSame('unit test', $view->getName());
}
/**
- * @testdox compiles its own name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('compiles its own name')]
public function testGetCompiledName()
{
$view = new class () extends AbstractView {
@@ -66,12 +64,11 @@ public function display($tpl = null)
}
/**
- * @testdox has the injected option
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('has the injected option')]
public function testInjectedOption()
{
$view = new class (['option' => 'unit test']) extends AbstractView {
@@ -85,16 +82,15 @@ public function display($tpl = null)
}
};
- $this->assertEquals('unit test', $view->getOption());
+ $this->assertSame('unit test', $view->getOption());
}
/**
- * @testdox can set a model and get it by name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can set a model and get it by name')]
public function testSetGetModel()
{
$model = new class (['name' => 'unit test']) extends BaseModel {
@@ -107,16 +103,15 @@ public function display($tpl = null)
};
$view->setModel($model, false);
- $this->assertEquals($model, $view->getModel('unit test'));
+ $this->assertSame($model, $view->getModel('unit test'));
}
/**
- * @testdox can set a default model and get it with no name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can set a default model and get it with no name')]
public function testSetGetDefaultModel()
{
$model = new class (['name' => 'unit']) extends BaseModel {
@@ -129,16 +124,15 @@ public function display($tpl = null)
};
$view->setModel($model, true);
- $this->assertEquals($model, $view->getModel());
+ $this->assertSame($model, $view->getModel());
}
/**
- * @testdox can get data
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can get data')]
public function testGetDefaultData()
{
$view = new class () extends AbstractView {
@@ -147,16 +141,15 @@ public function display($tpl = null)
}
};
- $this->assertEquals('test', $view->get('unit', 'test'));
+ $this->assertSame('test', $view->get('unit', 'test'));
}
/**
- * @testdox can get data from model
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can get data from model')]
public function testGetDataFromModel()
{
$model = new class (['name' => 'test']) extends BaseModel {
@@ -173,16 +166,15 @@ public function display($tpl = null)
};
$view->setModel($model, false);
- $this->assertEquals('test', $view->get('unit', 'test'));
+ $this->assertSame('test', $view->get('unit', 'test'));
}
/**
- * @testdox can get data from default model
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can get data from default model')]
public function testGetDataFromDefaultModel()
{
$model = new class (['name' => 'test']) extends BaseModel {
@@ -199,21 +191,20 @@ public function display($tpl = null)
};
$view->setModel($model, true);
- $this->assertEquals('test', $view->get('unit'));
+ $this->assertSame('test', $view->get('unit'));
}
/**
- * @testdox can dispatch an event
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can dispatch an event')]
public function testDispatchEvent()
{
$event = new Event('test');
$dispatcher = $this->createMock(DispatcherInterface::class);
- $dispatcher->expects($this->once())->method('dispatch')->with($this->equalTo('test'), $this->equalTo($event));
+ $dispatcher->expects($this->once())->method('dispatch')->with('test', $event);
$view = new class () extends AbstractView {
public function dispatchEvent(EventInterface $event)
diff --git a/tests/Unit/Libraries/Cms/Mail/MailHelperTest.php b/tests/Unit/Libraries/Cms/Mail/MailHelperTest.php
index f51ac78c25673..7a3f2e234a896 100644
--- a/tests/Unit/Libraries/Cms/Mail/MailHelperTest.php
+++ b/tests/Unit/Libraries/Cms/Mail/MailHelperTest.php
@@ -11,6 +11,7 @@
use Joomla\CMS\Mail\MailHelper;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for JMailHelper.
@@ -29,7 +30,7 @@ class MailHelperTest extends UnitTestCase
*
* @since 3.0.0
*/
- public function dataCleanLine(): array
+ public static function dataCleanLine(): array
{
return [
["test\n\nme\r\r", 'testme'],
@@ -47,12 +48,11 @@ public function dataCleanLine(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataCleanLine
*/
+ #[DataProvider('dataCleanLine')]
public function testCleanLine($input, $expected)
{
- $this->assertEquals($expected, MailHelper::cleanLine($input));
+ $this->assertSame($expected, MailHelper::cleanLine($input));
}
/**
@@ -62,7 +62,7 @@ public function testCleanLine($input, $expected)
*
* @since 3.0.0
*/
- public function dataCleanText(): array
+ public static function dataCleanText(): array
{
return [
["test\nme", "test\nme"],
@@ -109,12 +109,11 @@ public function dataCleanText(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataCleanText
*/
+ #[DataProvider('dataCleanText')]
public function testCleanText($input, $expected)
{
- $this->assertEquals($expected, MailHelper::cleanText($input));
+ $this->assertSame($expected, MailHelper::cleanText($input));
}
/**
@@ -124,7 +123,7 @@ public function testCleanText($input, $expected)
*
* @since 3.0.0
*/
- public function dataCleanBody(): array
+ public static function dataCleanBody(): array
{
return [
["testFrom: Foobar me", "test me"],
@@ -152,12 +151,11 @@ public function dataCleanBody(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataCleanBody
*/
+ #[DataProvider('dataCleanBody')]
public function testCleanBody($input, $expected)
{
- $this->assertEquals($expected, MailHelper::cleanBody($input));
+ $this->assertSame($expected, MailHelper::cleanBody($input));
}
/**
@@ -167,7 +165,7 @@ public function testCleanBody($input, $expected)
*
* @since 3.0.0
*/
- public function dataCleanSubject(): array
+ public static function dataCleanSubject(): array
{
return [
["testFrom: Foobar me", "test me"],
@@ -193,12 +191,11 @@ public function dataCleanSubject(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataCleanSubject
*/
+ #[DataProvider('dataCleanSubject')]
public function testCleanSubject($input, $expected)
{
- $this->assertEquals($expected, MailHelper::cleanSubject($input));
+ $this->assertSame($expected, MailHelper::cleanSubject($input));
}
/**
@@ -208,7 +205,7 @@ public function testCleanSubject($input, $expected)
*
* @since 3.0.0
*/
- public function dataCleanAddress(): array
+ public static function dataCleanAddress(): array
{
return [
["testme", "testme"],
@@ -228,12 +225,11 @@ public function dataCleanAddress(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataCleanAddress
*/
+ #[DataProvider('dataCleanAddress')]
public function testCleanAddress($input, $expected)
{
- $this->assertEquals($expected, MailHelper::cleanAddress($input));
+ $this->assertSame($expected, MailHelper::cleanAddress($input));
}
/**
@@ -243,7 +239,7 @@ public function testCleanAddress($input, $expected)
*
* @since 3.0.0
*/
- public function dataIsEmailAddress(): array
+ public static function dataIsEmailAddress(): array
{
return [
["joe", false],
@@ -279,11 +275,10 @@ public function dataIsEmailAddress(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataIsEmailAddress
*/
+ #[DataProvider('dataIsEmailAddress')]
public function testIsEmailAddress($input, $expected)
{
- $this->assertEquals($expected, MailHelper::isEmailAddress($input));
+ $this->assertSame($expected, MailHelper::isEmailAddress($input));
}
}
diff --git a/tests/Unit/Libraries/Cms/Mail/MailTest.php b/tests/Unit/Libraries/Cms/Mail/MailTest.php
index e2630df7c8db5..de782fe4002c0 100644
--- a/tests/Unit/Libraries/Cms/Mail/MailTest.php
+++ b/tests/Unit/Libraries/Cms/Mail/MailTest.php
@@ -13,6 +13,8 @@
use Joomla\CMS\Mail\Mail;
use Joomla\Tests\Unit\UnitTestCase;
use PHPMailer\PHPMailer\PHPMailer;
+use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for JMail.
@@ -22,6 +24,11 @@
* @subpackage Mail
* @since 1.7.0
*/
+#[CoversMethod(Mail::class, 'addRecipient')]
+#[CoversMethod(Mail::class, 'addCc')]
+#[CoversMethod(Mail::class, 'addBcc')]
+#[CoversMethod(Mail::class, 'addReplyTo')]
+#[CoversMethod(Mail::class, 'isHtml')]
class MailTest extends UnitTestCase
{
/**
@@ -66,7 +73,7 @@ protected function tearDown(): void
*
* @since 4.0.0
*/
- public function seedTestAdd(): array
+ public static function seedTestAdd(): array
{
// Recipient, name, $expected
return [
@@ -98,10 +105,6 @@ public function seedTestAdd(): array
/**
* Tests the addRecipient method.
*
- * @covers Mail::addRecipient
- *
- * @dataProvider seedTestAdd
- *
* @param string $recipient Recipient
* @param string $name Name
* @param string $expected Expected
@@ -110,20 +113,17 @@ public function seedTestAdd(): array
* @since 4.0.0
* @throws \PHPMailer\PHPMailer\Exception
*/
+ #[DataProvider('seedTestAdd')]
public function testAddRecipient($recipient, $name, $expected)
{
$this->mail->addRecipient($recipient, $name);
- $this->assertEquals($expected, $this->mail->getToAddresses());
+ $this->assertSame($expected, $this->mail->getToAddresses());
}
/**
* Tests the addCC method.
*
- * @covers Mail::addCc
- *
- * @dataProvider seedTestAdd
- *
* @param string $recipient Recipient
* @param string $name Name
* @param string $expected Expected
@@ -132,18 +132,17 @@ public function testAddRecipient($recipient, $name, $expected)
* @since 4.0.0
* @throws \PHPMailer\PHPMailer\Exception
*/
+ #[DataProvider('seedTestAdd')]
public function testAddCc($recipient, $name, $expected)
{
$this->mail->addCc($recipient, $name);
- $this->assertEquals($expected, $this->mail->getCcAddresses());
+ $this->assertSame($expected, $this->mail->getCcAddresses());
}
/**
* Tests the addBCC method.
*
- * @covers Mail::addBcc
- *
* @param string $recipient Recipient
* @param string $name Name
* @param string $expected Expected
@@ -151,13 +150,13 @@ public function testAddCc($recipient, $name, $expected)
* @return void
* @since 4.0.0
* @throws \PHPMailer\PHPMailer\Exception
- * @dataProvider seedTestAdd
*/
+ #[DataProvider('seedTestAdd')]
public function testAddBcc($recipient, $name, $expected)
{
$this->mail->addBcc($recipient, $name);
- $this->assertEquals($expected, $this->mail->getBccAddresses());
+ $this->assertSame($expected, $this->mail->getBccAddresses());
}
/**
@@ -167,7 +166,7 @@ public function testAddBcc($recipient, $name, $expected)
*
* @since 4.0.0
*/
- public function seedTestAddReplyTo(): array
+ public static function seedTestAddReplyTo(): array
{
// Recipient, name, $expected
return [
@@ -198,10 +197,6 @@ public function seedTestAddReplyTo(): array
/**
* Tests the addReplyTo method.
*
- * @covers JMail::addReplyTo
- *
- * @dataProvider seedTestAddReplyTo
- *
* @param string $recipient Recipient
* @param string $name Name
* @param string $expected Expected
@@ -210,11 +205,12 @@ public function seedTestAddReplyTo(): array
* @since 4.0.0
* @throws \PHPMailer\PHPMailer\Exception
*/
+ #[DataProvider('seedTestAddReplyTo')]
public function testAddReplyTo($recipient, $name, $expected)
{
$this->mail->addReplyTo($recipient, $name);
- $this->assertEquals($expected, $this->mail->getReplyToAddresses());
+ $this->assertSame($expected, $this->mail->getReplyToAddresses());
}
/**
@@ -235,15 +231,13 @@ public function testAddAttachment()
$mailAttachments = $this->mail->getAttachments();
$this->assertCount(1, $mailAttachments);
- $this->assertEquals($path, $mailAttachments[0][0]);
- $this->assertEquals($name, $mailAttachments[0][2]);
+ $this->assertSame($path, $mailAttachments[0][0]);
+ $this->assertSame($name, $mailAttachments[0][2]);
}
/**
* Tests the IsHTML method.
*
- * @covers JMail::IsHTML
- *
* @return void
*
* @since 4.0.0
@@ -252,14 +246,12 @@ public function testIsHtmlTrue()
{
$this->mail->isHtml(true);
- $this->assertEquals(PHPMailer::CONTENT_TYPE_TEXT_HTML, $this->mail->ContentType);
+ $this->assertSame(PHPMailer::CONTENT_TYPE_TEXT_HTML, $this->mail->ContentType);
}
/**
* Tests the IsHTML method.
*
- * @covers JMail::IsHTML
- *
* @return void
*
* @since 4.0.0
@@ -268,7 +260,7 @@ public function testIsHtmlFalse()
{
$this->mail->isHtml(false);
- $this->assertEquals(PHPMailer::CONTENT_TYPE_PLAINTEXT, $this->mail->ContentType);
+ $this->assertSame(PHPMailer::CONTENT_TYPE_PLAINTEXT, $this->mail->ContentType);
}
/**
@@ -278,7 +270,7 @@ public function testIsHtmlFalse()
*
* @since 3.0.0
*/
- public function dataUseSmtp(): array
+ public static function dataUseSmtp(): array
{
return [
'SMTP without Authentication' => [
@@ -310,20 +302,19 @@ public function dataUseSmtp(): array
* @return void
*
* @since 3.0.0
- *
- * @dataProvider dataUseSMTP
*/
+ #[DataProvider('dataUseSMTP')]
public function testUseSmtp($auth, $host, $user, $pass, $secure, $port, $expected)
{
// Build a partial mock object.
$mailMock = $this->getMockBuilder(Mail::class)
- ->setMethods(['SetLanguage', 'IsSMTP', 'IsMail'])
+ ->onlyMethods(['SetLanguage', 'IsSMTP', 'IsMail'])
->getMock();
$mailMock
->expects($this->once())
->method($expected['called']);
- $this->assertEquals($expected['return'], $mailMock->useSmtp($auth, $host, $user, $pass, $secure, $port));
+ $this->assertSame($expected['return'], $mailMock->useSmtp($auth, $host, $user, $pass, $secure, $port));
}
}
diff --git a/tests/Unit/Libraries/Cms/Mail/MailerFactoryAwareTraitTest.php b/tests/Unit/Libraries/Cms/Mail/MailerFactoryAwareTraitTest.php
index f736b22bcb87b..cdb81820af2aa 100644
--- a/tests/Unit/Libraries/Cms/Mail/MailerFactoryAwareTraitTest.php
+++ b/tests/Unit/Libraries/Cms/Mail/MailerFactoryAwareTraitTest.php
@@ -15,6 +15,7 @@
use Joomla\CMS\Mail\MailerInterface;
use Joomla\Registry\Registry;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Mail\MailerFactoryAwareTrait
@@ -26,12 +27,11 @@
class MailerFactoryAwareTraitTest extends UnitTestCase
{
/**
- * @testdox The mailer factory can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory can be set and accessed by the trait')]
public function testGetSetMailerFactory()
{
$mailerFactory = new class () implements MailerFactoryInterface {
@@ -88,16 +88,15 @@ public function getFactory(): MailerFactoryInterface
$trait->setMailerFactory($mailerFactory);
- $this->assertEquals($mailerFactory, $trait->getFactory());
+ $this->assertSame($mailerFactory, $trait->getFactory());
}
/**
- * @testdox The mailer factory can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory can be set and accessed by the trait')]
public function testGetMailerFactoryThrowsException()
{
$this->expectException(\UnexpectedValueException::class);
diff --git a/tests/Unit/Libraries/Cms/Mail/MailerFactoryTest.php b/tests/Unit/Libraries/Cms/Mail/MailerFactoryTest.php
index bbbb1ed213996..9adc1ff206a42 100644
--- a/tests/Unit/Libraries/Cms/Mail/MailerFactoryTest.php
+++ b/tests/Unit/Libraries/Cms/Mail/MailerFactoryTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\Mail\MailerFactory;
use Joomla\Registry\Registry;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Mail\MailerFactory
@@ -24,12 +25,11 @@
class MailerFactoryTest extends UnitTestCase
{
/**
- * @testdox The mailer factory creates the correct object
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory creates the correct object')]
public function testMailer()
{
$factory = new MailerFactory(new Registry());
@@ -40,12 +40,11 @@ public function testMailer()
}
/**
- * @testdox The mailer factory creates an object with the default settings
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory creates an object with the default settings')]
public function testMailerHasDefaultSettings()
{
$factory = new MailerFactory(new Registry(['mailfrom' => 'test@example.com']));
@@ -53,16 +52,15 @@ public function testMailerHasDefaultSettings()
/** @var Mail $mail */
$mail = $factory->createMailer();
- $this->assertEquals('test@example.com', $mail->From);
+ $this->assertSame('test@example.com', $mail->From);
}
/**
- * @testdox The mailer factory creates an object with the passed settings
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory creates an object with the passed settings')]
public function testMailerHasPassedSettings()
{
$factory = new MailerFactory(new Registry());
@@ -70,16 +68,15 @@ public function testMailerHasPassedSettings()
/** @var Mail $mail */
$mail = $factory->createMailer(new Registry(['mailfrom' => 'test@example.com']));
- $this->assertEquals('test@example.com', $mail->From);
+ $this->assertSame('test@example.com', $mail->From);
}
/**
- * @testdox The mailer factory creates an object with an invalid from address
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory creates an object with an invalid from address')]
public function testMailerHasInvalidFromAddress()
{
$factory = new MailerFactory(new Registry(['mailfrom' => 'testüumlaut@example.com']));
@@ -91,12 +88,11 @@ public function testMailerHasInvalidFromAddress()
}
/**
- * @testdox The mailer factory creates an object with the passed settings overriding the default settings
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory creates an object with the passed settings overriding the default settings')]
public function testMailerHasOverriddenSettings()
{
$factory = new MailerFactory(new Registry(['mailfrom' => 'default@example.com']));
@@ -104,16 +100,15 @@ public function testMailerHasOverriddenSettings()
/** @var Mail $mail */
$mail = $factory->createMailer(new Registry(['mailfrom' => 'test@example.com']));
- $this->assertEquals('test@example.com', $mail->From);
+ $this->assertSame('test@example.com', $mail->From);
}
/**
- * @testdox The mailer factory creates an object with mail type smtp
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The mailer factory creates an object with mail type smtp')]
public function testMailerIsSMTP()
{
$factory = new MailerFactory(new Registry(['mailer' => 'smtp', 'smtphost' => 'localhost']));
@@ -121,6 +116,6 @@ public function testMailerIsSMTP()
/** @var Mail $mail */
$mail = $factory->createMailer();
- $this->assertEquals('smtp', $mail->Mailer);
+ $this->assertSame('smtp', $mail->Mailer);
}
}
diff --git a/tests/Unit/Libraries/Cms/Microdata/MicrodataTest.php b/tests/Unit/Libraries/Cms/Microdata/MicrodataTest.php
index 8a9a051b1fd42..5bde13e1bf567 100644
--- a/tests/Unit/Libraries/Cms/Microdata/MicrodataTest.php
+++ b/tests/Unit/Libraries/Cms/Microdata/MicrodataTest.php
@@ -11,7 +11,9 @@
namespace Joomla\Tests\Unit\Libraries\Cms\Microdata;
use Joomla\CMS\Microdata\Microdata;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for JMicrodata
@@ -34,7 +36,7 @@ public function testDefaultType()
{
$microdata = new MicrodataStub();
- $this->assertEquals('Thing', $microdata->getType());
+ $this->assertSame('Thing', $microdata->getType());
$this->assertTrue($microdata->isEnabled());
}
@@ -48,7 +50,7 @@ public function testOverrideTypeDuringConstruction()
$expectedType = ucfirst(trim($type));
$microdata = new MicrodataStub('some-type', true, [$expectedType => []]);
- $this->assertEquals($expectedType, $microdata->getType());
+ $this->assertSame($expectedType, $microdata->getType());
$this->assertTrue($microdata->isEnabled());
}
@@ -77,7 +79,7 @@ public function testSetType()
$microdata->setType($type);
// Test if the current Type is 'Article'
- $this->assertEquals($type, $microdata->getType());
+ $this->assertSame($type, $microdata->getType());
}
/**
@@ -93,7 +95,7 @@ public function testSetInvalidTypeSetsDefaultType()
$microdata->setType($type);
- $this->assertEquals('Thing', $microdata->getType());
+ $this->assertSame('Thing', $microdata->getType());
}
/**
@@ -118,8 +120,8 @@ public function testFallback()
// Test fallback values
$microdata->fallback('Article', 'articleBody');
- $this->assertEquals('Article', $microdata->getFallbackType());
- $this->assertEquals('articleBody', $microdata->getFallbackProperty());
+ $this->assertSame('Article', $microdata->getFallbackType());
+ $this->assertSame('articleBody', $microdata->getFallbackProperty());
}
/**
@@ -145,7 +147,7 @@ public function testFallbackWithNotExistingProperty()
// Test if the Fallback Property fallbacks when it isn't available in the $Type
$microdata->fallback('Article', 'anUnavailableProperty');
- $this->assertEquals('Article', $microdata->getFallbackType());
+ $this->assertSame('Article', $microdata->getFallbackType());
$this->assertNull($microdata->getFallbackProperty());
}
@@ -161,7 +163,7 @@ public function testFallbackWithNotExistingTypeAndProperty()
// Test if the Fallback Type fallbacks to the 'Thing' Type
$microdata->fallback('anUnavailableType', 'anUnavailableProperty');
- $this->assertEquals('Thing', $microdata->getFallbackType());
+ $this->assertSame('Thing', $microdata->getFallbackType());
$this->assertNull($microdata->getFallbackProperty());
}
@@ -176,7 +178,7 @@ public function testDisplayIsEmptyByDefault()
// Test display() with all null params
$microdata = new MicrodataStub();
- $this->assertEquals('', $microdata->display());
+ $this->assertSame('', $microdata->display());
}
/**
@@ -225,7 +227,7 @@ public function testDisplaySimple()
->property('url')
->display();
- $this->assertEquals("itemprop='url'", $html);
+ $this->assertSame("itemprop='url'", $html);
}
/**
@@ -255,7 +257,7 @@ public function testDisplaySimpleWithContent()
->content($content)
->display();
- $this->assertEquals("$content", $html);
+ $this->assertSame("$content", $html);
}
/**
@@ -285,7 +287,7 @@ public function testDisplaySimpleWithEmptyContent()
->content($content)
->display();
- $this->assertEquals("$content", $html);
+ $this->assertSame("$content", $html);
}
/**
@@ -313,7 +315,7 @@ public function testDisplayNested()
->property('author')
->display();
- $this->assertEquals("itemprop='author' itemscope itemtype='https://schema.org/Organization'", $html);
+ $this->assertSame("itemprop='author' itemscope itemtype='https://schema.org/Organization'", $html);
}
/**
@@ -343,7 +345,7 @@ public function testDisplayNestedWithContent()
->content($content)
->display();
- $this->assertEquals(
+ $this->assertSame(
"$content",
$html
);
@@ -387,7 +389,7 @@ public function testDisplayNestedWithContentAndFallback()
->content($content)
->display();
- $this->assertEquals(
+ $this->assertSame(
"$content",
$html
);
@@ -429,7 +431,7 @@ public function testDisplayNestedWithFallback()
->property('author')
->display();
- $this->assertEquals("itemprop='author' itemscope itemtype='https://schema.org/Person' itemprop='name'", $html);
+ $this->assertSame("itemprop='author' itemscope itemtype='https://schema.org/Person' itemprop='name'", $html);
}
/**
@@ -459,7 +461,7 @@ public function testDisplayMeta()
->property('datePublished')
->display();
- $this->assertEquals("itemprop='datePublished'", $html);
+ $this->assertSame("itemprop='datePublished'", $html);
}
/**
@@ -491,7 +493,7 @@ public function testDisplayMetaWithContent()
->content($content)
->display();
- $this->assertEquals("$content", $html);
+ $this->assertSame("$content", $html);
}
/**
@@ -524,7 +526,7 @@ public function testDisplayMetaWithHumanAndMachineContent()
->content($content, $machineContent)
->display();
- $this->assertEquals("$content", $html);
+ $this->assertSame("$content", $html);
}
/**
@@ -569,7 +571,7 @@ public function testDisplayContentWhenDisabled()
->property('datePublished')
->display();
- $this->assertEquals($content, $html);
+ $this->assertSame($content, $html);
}
/**
@@ -619,7 +621,7 @@ public function testDisplayFallbackForNotExistingProperties()
->fallback('Article', 'about')
->display();
- $this->assertEquals("itemscope itemtype='https://schema.org/Article' itemprop='about'", $html);
+ $this->assertSame("itemscope itemtype='https://schema.org/Article' itemprop='about'", $html);
}
/**
@@ -653,7 +655,7 @@ public function testDisplayFallbackForNotExistingPropertiesWithContent()
->fallback('Article', 'about')
->display();
- $this->assertEquals(
+ $this->assertSame(
"$content",
$html
);
@@ -682,7 +684,7 @@ public function testDisplayFallbackForNotExistingPropertiesAndFallbacks()
->fallback('Article', 'notExisting')
->display();
- $this->assertEquals("itemscope itemtype='https://schema.org/Article'", $html);
+ $this->assertSame("itemscope itemtype='https://schema.org/Article'", $html);
}
/**
@@ -716,7 +718,7 @@ public function testDisplayFallbackWhenThePropertyDoesNotExistInTheType()
->fallback('Article', 'datePublished')
->display();
- $this->assertEquals("itemscope itemtype='https://schema.org/Article' itemprop='datePublished'", $html);
+ $this->assertSame("itemscope itemtype='https://schema.org/Article' itemprop='datePublished'", $html);
}
/**
@@ -752,7 +754,7 @@ public function testDisplayFallbackWithContentWhenThePropertyDoesNotExistInTheTy
->fallback('Article', 'datePublished')
->display();
- $this->assertEquals(
+ $this->assertSame(
"",
$html
);
@@ -761,9 +763,8 @@ public function testDisplayFallbackWithContentWhenThePropertyDoesNotExistInTheTy
/**
* @return array
* @since 4.0.0
- *
*/
- public function displayTypes(): array
+ public static function displayTypes(): array
{
return [
['inline', "itemprop='datePublished'"],
@@ -779,8 +780,8 @@ public function displayTypes(): array
*
* @since 4.0.0
* @return void
- * @dataProvider displayTypes
*/
+ #[DataProvider('displayTypes')]
public function testDisplayTypes($type, $expected)
{
$microdata = new MicrodataStub(
@@ -803,15 +804,14 @@ public function testDisplayTypes($type, $expected)
->property('datePublished')
->display($type);
- $this->assertEquals($expected, $html);
+ $this->assertSame($expected, $html);
}
/**
* @return array
* @since 4.0.0
- *
*/
- public function displayTypesWithContent(): array
+ public static function displayTypesWithContent(): array
{
return [
['inline', 'Some content', "itemprop='datePublished'"],
@@ -828,8 +828,8 @@ public function displayTypesWithContent(): array
*
* @since 4.0.0
* @return void
- * @dataProvider displayTypesWithContent
*/
+ #[DataProvider('displayTypesWithContent')]
public function testDisplayTypesWithContent($type, $content, $expected)
{
$microdata = new MicrodataStub(
@@ -853,7 +853,7 @@ public function testDisplayTypesWithContent($type, $content, $expected)
->property('datePublished')
->display($type);
- $this->assertEquals($expected, $html);
+ $this->assertSame($expected, $html);
}
/**
@@ -902,7 +902,6 @@ public function testIsPropertyInType()
* @return void
*
* @since 3.2
- * @throws \ReflectionException
*/
public function testExpectedDisplayType()
{
@@ -927,12 +926,9 @@ public function testExpectedDisplayType()
);
// Use reflection to test protected method (it's easier than testing this using the public interface)
- $reflectionClass = new \ReflectionClass($microdata);
- $method = $reflectionClass->getMethod('getExpectedDisplayType');
-
- $this->assertEquals('normal', $method->invoke($microdata, 'Article', 'articleBody'));
- $this->assertEquals('nested', $method->invoke($microdata, 'Article', 'about'));
- $this->assertEquals('meta', $method->invoke($microdata, 'Article', 'datePublished'));
+ $this->assertSame('normal', TestHelper::invoke($microdata, 'getExpectedDisplayType', 'Article', 'articleBody'));
+ $this->assertSame('nested', TestHelper::invoke($microdata, 'getExpectedDisplayType', 'Article', 'about'));
+ $this->assertSame('meta', TestHelper::invoke($microdata, 'getExpectedDisplayType', 'Article', 'datePublished'));
}
/**
@@ -955,7 +951,7 @@ public function testDisplayScope()
]
);
- $this->assertEquals("itemscope itemtype='https://schema.org/$type'", $microdata->displayScope());
+ $this->assertSame("itemscope itemtype='https://schema.org/$type'", $microdata->displayScope());
}
/**
@@ -969,7 +965,7 @@ public function testDisplayScopeIsEmptyWhenDisabled()
$type = 'Article';
$microdata = new MicrodataStub($type, false);
- $this->assertEquals("", $microdata->displayScope());
+ $this->assertSame("", $microdata->displayScope());
}
/**
@@ -1004,7 +1000,7 @@ public function testGetAvailableTypes()
$types = $microdata::getAvailableTypes();
$this->assertCount(1, $types);
- $this->assertEquals('Article', $types[0]);
+ $this->assertSame('Article', $types[0]);
}
/**
@@ -1021,19 +1017,19 @@ public function testHtmlMeta()
$property = 'datePublished';
// Test with all params
- $this->assertEquals(
+ $this->assertSame(
"",
MicrodataStub::htmlMeta($content, $property, $scope)
);
// Test with the $inverse mode
- $this->assertEquals(
+ $this->assertSame(
"",
MicrodataStub::htmlMeta($content, $property, $scope, true)
);
// Test without the $scope
- $this->assertEquals(
+ $this->assertSame(
"",
MicrodataStub::htmlMeta($content, $property)
);
@@ -1054,31 +1050,31 @@ public function testHtmlDiv()
$property = 'about';
// Test with all params
- $this->assertEquals(
+ $this->assertSame(
"$content
",
MicrodataStub::htmlDiv($content, $property, $scope)
);
// Test with the $inverse mode
- $this->assertEquals(
+ $this->assertSame(
"$content
",
MicrodataStub::htmlDiv($content, $property, $scope, true)
);
// Test without the $scope
- $this->assertEquals(
+ $this->assertSame(
"$content
",
MicrodataStub::htmlDiv($content, $property)
);
// Test without the $property
- $this->assertEquals(
+ $this->assertSame(
"$content
",
MicrodataStub::htmlDiv($content, $property, $scope, true)
);
// Test without the $scope, $property
- $this->assertEquals(
+ $this->assertSame(
"$content
",
MicrodataStub::htmlDiv($content)
);
@@ -1099,31 +1095,31 @@ public function testHtmlSpan()
$property = 'about';
// Test with all params
- $this->assertEquals(
+ $this->assertSame(
"$content",
MicrodataStub::htmlSpan($content, $property, $scope)
);
// Test with the inverse mode
- $this->assertEquals(
+ $this->assertSame(
"$content",
MicrodataStub::htmlSpan($content, $property, $scope, true)
);
// Test without the $scope
- $this->assertEquals(
+ $this->assertSame(
"$content",
MicrodataStub::htmlSpan($content, $property)
);
// Test without the $property
- $this->assertEquals(
+ $this->assertSame(
"$content",
MicrodataStub::htmlSpan($content, $property, $scope, true)
);
// Test without the $scope, $property
- $this->assertEquals(
+ $this->assertSame(
"$content",
MicrodataStub::htmlSpan($content)
);
diff --git a/tests/Unit/Libraries/Cms/Object/CMSObjectTest.php b/tests/Unit/Libraries/Cms/Object/CMSObjectTest.php
index 862318ced7a73..90b22e7a83537 100644
--- a/tests/Unit/Libraries/Cms/Object/CMSObjectTest.php
+++ b/tests/Unit/Libraries/Cms/Object/CMSObjectTest.php
@@ -12,6 +12,8 @@
use Joomla\CMS\Object\CMSObject;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\CoversMethod;
+use PHPUnit\Framework\Attributes\Group;
/**
* Test class for \Joomla\CMS\Object\CMSObject
@@ -20,61 +22,67 @@
* @subpackage Object
* @since 1.7.0
*/
+#[CoversMethod(CMSObject::class, '__construct')]
+#[CoversMethod(CMSObject::class, 'def')]
+#[CoversMethod(CMSObject::class, 'get')]
+#[CoversMethod(CMSObject::class, 'getProperties')]
+#[CoversMethod(CMSObject::class, 'getError')]
+#[CoversMethod(CMSObject::class, 'getErrors')]
+#[CoversMethod(CMSObject::class, 'set')]
+#[CoversMethod(CMSObject::class, 'setProperties')]
+#[CoversMethod(CMSObject::class, 'setError')]
class CMSObjectTest extends UnitTestCase
{
/**
* Tests the object constructor.
*
- * @group CMSObject
- * @covers CMSObject::__construct
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testIsConstructable()
{
$object = new CMSObject(['property1' => 'value1', 'property2' => 5]);
- $this->assertEquals('value1', $object->get('property1'));
+ $this->assertSame('value1', $object->get('property1'));
}
/**
* Tests setting the default for a property of the object.
*
- * @group CMSObject
- * @covers CMSObject::def
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testDef()
{
$object = new CMSObject();
$object->def("check");
- $this->assertEquals(null, $object->def("check"));
+ $this->assertSame(null, $object->def("check"));
$object->def("check", "paint");
$object->def("check", "forced");
- $this->assertEquals("paint", $object->def("check"));
+ $this->assertSame("paint", $object->def("check"));
$this->assertNotEquals("forced", $object->def("check"));
}
/**
* Tests getting a property of the object.
*
- * @group CMSObject
- * @covers CMSObject::get
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testGet()
{
$object = new CMSObject();
$object->goo = 'car';
- $this->assertEquals('car', $object->get('goo', 'fudge'));
- $this->assertEquals('fudge', $object->get('foo', 'fudge'));
+ $this->assertSame('car', $object->get('goo', 'fudge'));
+ $this->assertSame('fudge', $object->get('foo', 'fudge'));
$this->assertNotEquals(null, $object->get('foo', 'fudge'));
$this->assertNull($object->get('boo'));
}
@@ -82,12 +90,11 @@ public function testGet()
/**
* Tests getting the properties of the object.
*
- * @group CMSObject
- * @covers CMSObject::getProperties
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testGetProperties()
{
$object = new CMSObject([
@@ -96,19 +103,19 @@ public function testGetProperties()
'property2' => 5,
]);
- $this->assertEquals(
+ $this->assertSame(
[
'_errors' => [],
+ 'useExceptions' => false,
'_privateproperty1' => 'valuep1',
'property1' => 'value1',
'property2' => 5,
- 'useExceptions' => false,
],
$object->getProperties(false),
'Should get all properties, including private ones'
);
- $this->assertEquals(
+ $this->assertSame(
[
'property1' => 'value1',
'property2' => 5,
@@ -121,12 +128,11 @@ public function testGetProperties()
/**
* Tests getting a single error.
*
- * @group CMSObject
- * @covers CMSObject::getError
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testGetError()
{
$object = new CMSObject();
@@ -135,18 +141,18 @@ public function testGetError()
$object->setError('Second Test Error');
$object->setError('Third Test Error');
- $this->assertEquals(
+ $this->assertSame(
1234,
$object->getError(0, false),
'Should return the test error as number'
);
- $this->assertEquals(
+ $this->assertSame(
'Second Test Error',
$object->getError(1),
'Should return the second test error'
);
- $this->assertEquals(
+ $this->assertSame(
'Third Test Error',
$object->getError(),
'Should return the third test error'
@@ -159,21 +165,17 @@ public function testGetError()
$exception = new \Exception('error');
$object->setError($exception);
- $this->assertThat(
- $object->getError(3, true),
- $this->equalTo('error')
- );
+ $this->assertSame('error', $object->getError(3, true));
}
/**
* Tests getting the array of errors.
*
- * @group CMSObject
- * @covers CMSObject::getErrors
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testGetErrors()
{
$object = new CMSObject();
@@ -184,7 +186,7 @@ public function testGetErrors()
$object->setError($error);
}
- $this->assertEquals(
+ $this->assertSame(
$errors,
$object->getErrors(),
'Should return every error set'
@@ -194,56 +196,53 @@ public function testGetErrors()
/**
* Tests setting a property.
*
- * @group CMSObject
- * @covers CMSObject::set
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testSet()
{
$object = new CMSObject();
- $this->assertEquals(null, $object->set("foo", "imintheair"));
- $this->assertEquals("imintheair", $object->set("foo", "nojibberjabber"));
- $this->assertEquals("nojibberjabber", $object->foo);
+ $this->assertSame(null, $object->set("foo", "imintheair"));
+ $this->assertSame("imintheair", $object->set("foo", "nojibberjabber"));
+ $this->assertSame("nojibberjabber", $object->foo);
}
/**
* Tests setting multiple properties.
*
- * @group CMSObject
- * @covers CMSObject::setProperties
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testSetProperties()
{
$object = new CMSObject();
$a = ["foo" => "ghost", "knife" => "stewie"];
$f = "foo";
- $this->assertEquals(true, $object->setProperties($a));
- $this->assertEquals(false, $object->setProperties($f));
- $this->assertEquals("ghost", $object->foo);
- $this->assertEquals("stewie", $object->knife);
+ $this->assertSame(true, $object->setProperties($a));
+ $this->assertSame(false, $object->setProperties($f));
+ $this->assertSame("ghost", $object->foo);
+ $this->assertSame("stewie", $object->knife);
}
/**
* Tests setting an error.
*
- * @group CMSObject
- * @covers CMSObject::setError
* @return void
*
* @since 4.0.0
*/
+ #[Group('CMSObject')]
public function testSetError()
{
$object = new CMSObject();
$object->setError('A Test Error');
- $this->assertEquals(
+ $this->assertSame(
['A Test Error'],
$object->getErrors()
);
diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php
index 44ad0633a1614..ff06e14b04bb8 100644
--- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php
+++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php
@@ -19,6 +19,7 @@
use Joomla\Event\SubscriberInterface;
use Joomla\Registry\Registry;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Plugin\CMSPlugin
@@ -26,19 +27,17 @@
* @package Joomla.UnitTest
* @subpackage Plugin
*
- * @testdox The CMSPlugin
- *
* @since 4.2.0
*/
+#[TestDox('The CMSPlugin')]
class CMSPluginTest extends UnitTestCase
{
/**
- * @testdox has the correct dispatcher
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('has the correct dispatcher')]
public function testInjectedDispatcher()
{
$dispatcher = new Dispatcher();
@@ -46,16 +45,15 @@ public function testInjectedDispatcher()
$plugin = new class ($dispatcher, []) extends CMSPlugin {
};
- $this->assertEquals($dispatcher, $plugin->getDispatcher());
+ $this->assertSame($dispatcher, $plugin->getDispatcher());
}
/**
- * @testdox has the correct dispatcher
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('has the correct dispatcher')]
public function testInjectedApplication()
{
$dispatcher = new Dispatcher();
@@ -69,16 +67,15 @@ public function getApplication(): CMSApplicationInterface
};
$plugin->setApplication($app);
- $this->assertEquals($app, $plugin->getApplication());
+ $this->assertSame($app, $plugin->getApplication());
}
/**
- * @testdox has null params when not set
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('has null params when not set')]
public function testEmptyParams()
{
$dispatcher = new Dispatcher();
@@ -90,12 +87,11 @@ public function testEmptyParams()
}
/**
- * @testdox gets the injected params from a registry object
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected params from a registry object')]
public function testInjectedRegistryParams()
{
$dispatcher = new Dispatcher();
@@ -104,16 +100,15 @@ public function testInjectedRegistryParams()
$plugin = new class ($dispatcher, ['params' => $registry]) extends CMSPlugin {
};
- $this->assertEquals($registry, $plugin->params);
+ $this->assertSame($registry, $plugin->params);
}
/**
- * @testdox gets the injected params from array
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected params from array')]
public function testInjectedArrayParams()
{
$dispatcher = new Dispatcher();
@@ -121,16 +116,15 @@ public function testInjectedArrayParams()
$plugin = new class ($dispatcher, ['params' => ['test' => 'unit']]) extends CMSPlugin {
};
- $this->assertEquals('unit', $plugin->params->get('test'));
+ $this->assertSame('unit', $plugin->params->get('test'));
}
/**
- * @testdox gets the injected name
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected name')]
public function testInjectedName()
{
$dispatcher = new Dispatcher();
@@ -142,16 +136,15 @@ public function getName()
}
};
- $this->assertEquals('test', $plugin->getName());
+ $this->assertSame('test', $plugin->getName());
}
/**
- * @testdox gets the injected type
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('gets the injected type')]
public function testInjectedType()
{
$dispatcher = new Dispatcher();
@@ -163,21 +156,20 @@ public function getType()
}
};
- $this->assertEquals('test', $plugin->getType());
+ $this->assertSame('test', $plugin->getType());
}
/**
- * @testdox can load the language
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can load the language')]
public function testLoadLanguage()
{
$dispatcher = new Dispatcher();
$language = $this->createMock(Language::class);
- $language->expects($this->once())->method('load')->with($this->equalTo('plg__'), JPATH_ADMINISTRATOR)->willReturn(true);
+ $language->expects($this->once())->method('load')->with('plg__', JPATH_ADMINISTRATOR)->willReturn(true);
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);
@@ -189,17 +181,16 @@ public function testLoadLanguage()
}
/**
- * @testdox can load the language for a custom extension and path
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can load the language for a custom extension and path')]
public function testLoadLanguageWithExtensionAndPath()
{
$dispatcher = new Dispatcher();
$language = $this->createMock(Language::class);
- $language->expects($this->once())->method('load')->with($this->equalTo('test'), __DIR__)->willReturn(true);
+ $language->expects($this->once())->method('load')->with('test', __DIR__)->willReturn(true);
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);
@@ -211,12 +202,11 @@ public function testLoadLanguageWithExtensionAndPath()
}
/**
- * @testdox does not load the language when the path exists
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('does not load the language when the path exists')]
public function testNotLoadLanguageWhenExists()
{
$dispatcher = new Dispatcher();
@@ -234,12 +224,11 @@ public function testNotLoadLanguageWhenExists()
}
/**
- * @testdox can register the listeners when is SubscriberInterface
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can register the listeners when is SubscriberInterface')]
public function testRegisterListenersAsSubscriber()
{
$dispatcher = new Dispatcher();
@@ -256,16 +245,15 @@ public function unit()
};
$plugin->registerListeners();
- $this->assertEquals([[$plugin, 'unit']], $dispatcher->getListeners('test'));
+ $this->assertSame([[$plugin, 'unit']], $dispatcher->getListeners('test'));
}
/**
- * @testdox can register the listeners when is legacy
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can register the listeners when is legacy')]
public function testRegisterListenersAsLegacy()
{
$dispatcher = new Dispatcher();
@@ -281,12 +269,11 @@ public function onTest()
}
/**
- * @testdox can register the listeners with event interface
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can register the listeners with event interface')]
public function testRegisterListenersForEventInterface()
{
$dispatcher = new Dispatcher();
@@ -302,12 +289,11 @@ public function onTest(EventInterface $event)
}
/**
- * @testdox must register the listeners with event interface
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('must register the listeners with event interface')]
public function testRegisterListenersWithForcedEventInterface()
{
$dispatcher = new Dispatcher();
@@ -325,12 +311,11 @@ public function onTest(EventInterface $event)
}
/**
- * @testdox can register the listeners when has typed arguments
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can register the listeners when has typed arguments')]
public function testRegisterListenersForNoEventInterface()
{
$dispatcher = new Dispatcher();
@@ -346,12 +331,11 @@ public function onTest(string $context)
}
/**
- * @testdox can register the listeners when has untyped arguments
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can register the listeners when has untyped arguments')]
public function testRegisterListenersNotTyped()
{
$dispatcher = new Dispatcher();
@@ -367,12 +351,11 @@ public function onTest($event)
}
/**
- * @testdox can register the listeners when has nullable arguments
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can register the listeners when has nullable arguments')]
public function testRegisterListenersNullable()
{
$dispatcher = new Dispatcher();
@@ -388,12 +371,11 @@ public function onTest(?\stdClass $event = null)
}
/**
- * @testdox can dispatch a legacy listener
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can dispatch a legacy listener')]
public function testDispatchLegacyListener()
{
$dispatcher = new Dispatcher();
@@ -412,16 +394,15 @@ public function onTest()
$plugin->registerTestListener();
$event = $dispatcher->dispatch('onTest');
- $this->assertEquals(['unit'], $event->getArgument('result'));
+ $this->assertSame(['unit'], $event->getArgument('result'));
}
/**
- * @testdox can dispatch a legacy listener with null result
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can dispatch a legacy listener with null result')]
public function testDispatchLegacyListenerWhenNullIsReturned()
{
$dispatcher = new Dispatcher();
@@ -439,16 +420,15 @@ public function onTest()
$plugin->registerTestListener();
$event = $dispatcher->dispatch('onTest');
- $this->assertEquals(null, $event->getArgument('result'));
+ $this->assertSame(null, $event->getArgument('result'));
}
/**
- * @testdox can dispatch a legacy listener and contains the result from the event and the plugin
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can dispatch a legacy listener and contains the result from the event and the plugin')]
public function testDispatchLegacyListenerWhenEventHasResult()
{
$dispatcher = new Dispatcher();
@@ -467,6 +447,6 @@ public function onTest()
$plugin->registerTestListener();
$event = $dispatcher->dispatch('onTest', new Event('onTest', ['result' => ['test']]));
- $this->assertEquals(['test', 'unit'], $event->getArgument('result'));
+ $this->assertSame(['test', 'unit'], $event->getArgument('result'));
}
}
diff --git a/tests/Unit/Libraries/Cms/Proxy/ProxyArrayTest.php b/tests/Unit/Libraries/Cms/Proxy/ProxyArrayTest.php
index 2365162228bfb..e628243ec9dc5 100644
--- a/tests/Unit/Libraries/Cms/Proxy/ProxyArrayTest.php
+++ b/tests/Unit/Libraries/Cms/Proxy/ProxyArrayTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\Proxy\ArrayReadOnlyProxy;
use Joomla\CMS\Proxy\ObjectReadOnlyProxy;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Proxy\ArrayProxy classes
@@ -26,12 +27,11 @@
class ProxyArrayTest extends UnitTestCase
{
/**
- * @testdox Array referencing keep the changes
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Array referencing keep the changes')]
public function testArrayAccessAndModification()
{
$data = [
@@ -45,17 +45,16 @@ public function testArrayAccessAndModification()
$proxy['bar2'] = 'foo2';
- $this->assertEquals($data['bar2'], 'foo2', 'A referenced Array should get a Proxy value');
- $this->assertEquals($proxy['foo'], 'bar', 'Proxy object should return value from Array');
+ $this->assertSame($data['bar2'], 'foo2', 'A referenced Array should get a Proxy value');
+ $this->assertSame($proxy['foo'], 'bar', 'Proxy object should return value from Array');
}
/**
- * @testdox Array Countable implementations
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Array Countable implementations')]
public function testArrayCountable()
{
$data = [
@@ -67,16 +66,15 @@ public function testArrayCountable()
$proxy = new ArrayProxy($data);
- $this->assertEquals(\count($proxy), 2, 'Countable implementation should count correctly');
+ $this->assertCount(2, $proxy, 'Countable implementation should count correctly');
}
/**
- * @testdox Array Iterator implementations
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Array Iterator implementations')]
public function testArrayIterator()
{
$data = [
@@ -88,16 +86,15 @@ public function testArrayIterator()
$proxy = new ArrayProxy($data);
- $this->assertEquals($data, iterator_to_array($proxy));
+ $this->assertSame($data, iterator_to_array($proxy));
}
/**
- * @testdox Array read-only Iterator implementations
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Array read-only Iterator implementations')]
public function testArrayReadOnlyIterator()
{
$data = [
@@ -118,12 +115,11 @@ public function testArrayReadOnlyIterator()
}
/**
- * @testdox Array read-only access
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Array read-only access')]
public function testArrayReadOnlyAccessAndModification()
{
$data = [
@@ -141,12 +137,11 @@ public function testArrayReadOnlyAccessAndModification()
}
/**
- * @testdox Array read-only access to child
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Array read-only access to child')]
public function testArrayReadOnlyChildAccessAndModification()
{
$data = [
diff --git a/tests/Unit/Libraries/Cms/Proxy/ProxyObjectTest.php b/tests/Unit/Libraries/Cms/Proxy/ProxyObjectTest.php
index 6496477aff982..2a6e8bad03c4a 100644
--- a/tests/Unit/Libraries/Cms/Proxy/ProxyObjectTest.php
+++ b/tests/Unit/Libraries/Cms/Proxy/ProxyObjectTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\Proxy\ObjectProxy;
use Joomla\CMS\Proxy\ObjectReadOnlyProxy;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\Proxy\ObjectProxy classes
@@ -26,12 +27,11 @@
class ProxyObjectTest extends UnitTestCase
{
/**
- * @testdox Object referencing keep the changes
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Object referencing keep the changes')]
public function testObjectAccessAndModification()
{
$data = (object) [
@@ -45,17 +45,16 @@ public function testObjectAccessAndModification()
$proxy->bar2 = 'foo2';
- $this->assertEquals($data->bar2, 'foo2', 'A referenced Object should get a Proxy value');
- $this->assertEquals($proxy->foo, 'bar', 'Proxy object should return value from Object');
+ $this->assertSame($data->bar2, 'foo2', 'A referenced Object should get a Proxy value');
+ $this->assertSame($proxy->foo, 'bar', 'Proxy object should return value from Object');
}
/**
- * @testdox Object read-only access
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Object read-only access')]
public function testObjectReadOnlyAccessAndModification()
{
$data = (object) [
@@ -73,12 +72,11 @@ public function testObjectReadOnlyAccessAndModification()
}
/**
- * @testdox Object read-only access to child
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Object read-only access to child')]
public function testObjectReadOnlyChildAccessAndModification()
{
$data = (object) [
@@ -96,12 +94,11 @@ public function testObjectReadOnlyChildAccessAndModification()
}
/**
- * @testdox Object Iterator implementations
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Object Iterator implementations')]
public function testObjectIterator()
{
$data = (object) [
@@ -113,16 +110,15 @@ public function testObjectIterator()
$proxy = new ObjectProxy($data);
- $this->assertEquals((array) $data, iterator_to_array($proxy));
+ $this->assertSame((array) $data, iterator_to_array($proxy));
}
/**
- * @testdox Object read-only Iterator implementations
- *
* @return void
*
* @since 5.0.0
*/
+ #[TestDox('Object read-only Iterator implementations')]
public function testObjectReadOnlyIterator()
{
$data = (object) [
diff --git a/tests/Unit/Libraries/Cms/Session/SessionManagerTest.php b/tests/Unit/Libraries/Cms/Session/SessionManagerTest.php
index b883aa24d2f20..40049fb262c81 100644
--- a/tests/Unit/Libraries/Cms/Session/SessionManagerTest.php
+++ b/tests/Unit/Libraries/Cms/Session/SessionManagerTest.php
@@ -108,7 +108,7 @@ public function testDestroySessionsWithFailure()
$this->sessionHandler->expects($this->exactly(2))
->method('destroy')
- ->will($this->onConsecutiveCalls(true, false));
+ ->willReturn(true, false);
$this->assertFalse($this->manager->destroySessions($sessionIds));
}
diff --git a/tests/Unit/Libraries/Cms/Toolbar/Button/CustomButtonTest.php b/tests/Unit/Libraries/Cms/Toolbar/Button/CustomButtonTest.php
index 736851091dddd..88f0e1aa70f60 100644
--- a/tests/Unit/Libraries/Cms/Toolbar/Button/CustomButtonTest.php
+++ b/tests/Unit/Libraries/Cms/Toolbar/Button/CustomButtonTest.php
@@ -34,6 +34,6 @@ public function testFetchButton()
$button = new CustomButton();
$html = '';
- $this->assertEquals($html, $button->fetchButton('Custom', $html));
+ $this->assertSame($html, $button->fetchButton('Custom', $html));
}
}
diff --git a/tests/Unit/Libraries/Cms/Toolbar/ToolbarTest.php b/tests/Unit/Libraries/Cms/Toolbar/ToolbarTest.php
index 8061b6ac2d363..d4c965efd76f6 100644
--- a/tests/Unit/Libraries/Cms/Toolbar/ToolbarTest.php
+++ b/tests/Unit/Libraries/Cms/Toolbar/ToolbarTest.php
@@ -51,7 +51,7 @@ public function testAppendButtonWithToolbarButtonReturnsButton()
->method('setParent')
->with($toolbar);
- $this->assertEquals($button, $toolbar->appendButton($button));
+ $this->assertSame($button, $toolbar->appendButton($button));
}
/**
@@ -79,7 +79,7 @@ public function testGetItemsReturnsArray()
{
$toolbar = $this->createToolbar();
- $this->assertTrue(\is_array($toolbar->getItems()));
+ $this->assertIsArray($toolbar->getItems());
}
/**
@@ -92,8 +92,8 @@ public function testGetItemsReturnsArray()
public function testGetItemsReturnsButtons()
{
$toolbar = $this->createToolbar();
- $button1 = $this->createMock(ToolbarButton::class);
- $button2 = $this->createMock(ToolbarButton::class);
+ $button1 = $this->createStub(ToolbarButton::class);
+ $button2 = $this->createStub(ToolbarButton::class);
$toolbar->appendButton($button1);
$toolbar->appendButton($button2);
@@ -101,8 +101,8 @@ public function testGetItemsReturnsButtons()
$buttons = $toolbar->getItems();
$this->assertCount(2, $buttons);
- $this->assertEquals($button1, $buttons[0]);
- $this->assertEquals($button2, $buttons[1]);
+ $this->assertSame($button1, $buttons[0]);
+ $this->assertSame($button2, $buttons[1]);
}
/**
@@ -116,16 +116,16 @@ public function testPrependButtonWithToolbarButton()
{
$toolbar = $this->createToolbar();
$toolbar->setItems([
- $this->createMock(ToolbarButton::class),
- $this->createMock(ToolbarButton::class),]);
+ $this->createStub(ToolbarButton::class),
+ $this->createStub(ToolbarButton::class),]);
$button = $this->createMock(ToolbarButton::class);
$button->expects($this->once())
->method('setParent')
->with($toolbar);
- $this->assertEquals($button, $toolbar->prependButton($button));
- $this->assertEquals($button, $toolbar->getItems()[0]);
+ $this->assertSame($button, $toolbar->prependButton($button));
+ $this->assertSame($button, $toolbar->getItems()[0]);
}
/**
@@ -139,17 +139,16 @@ public function testPrependButtonWithStrings()
{
$toolbar = $this->createToolbar();
$toolbar->setItems([
- $this->createMock(ToolbarButton::class),
- $this->createMock(ToolbarButton::class),]);
+ $this->createStub(ToolbarButton::class),
+ $this->createStub(ToolbarButton::class),]);
$button = ['Separator', 'spacer', 25];
$this->assertTrue($toolbar->prependButton(...$button));
- $this->assertEquals($button, $toolbar->getItems()[0]);
+ $this->assertSame($button, $toolbar->getItems()[0]);
}
/**
- *
* @return void
* @since 4.0.0
* @throws \Exception
@@ -175,7 +174,7 @@ public function testRenderButton()
$toolbar = new Toolbar('my-toolbar', $toolbarFactoryMock);
- $this->assertEquals($renderedButton, $toolbar->renderButton($button));
+ $this->assertSame($renderedButton, $toolbar->renderButton($button));
}
/**
@@ -210,7 +209,7 @@ public function testRenderButtonThrowsUnexpectedValueException()
*/
public function testLoadButtonTypeReturnsButton()
{
- $buttonMock = $this->createMock(ToolbarButton::class);
+ $buttonMock = $this->createStub(ToolbarButton::class);
$toolbarFactoryMock = $this->createMock(ToolbarFactoryInterface::class);
$toolbarFactoryMock
->expects($this->once())
@@ -219,7 +218,7 @@ public function testLoadButtonTypeReturnsButton()
$toolbar = new Toolbar('my-toolbar', $toolbarFactoryMock);
- $this->assertEquals($buttonMock, $toolbar->loadButtonType('Separator'));
+ $this->assertSame($buttonMock, $toolbar->loadButtonType('Separator'));
}
/**
@@ -258,11 +257,11 @@ public function testAddButtonPathWithArray()
$toolbar->addButtonPath(['MyTestPath1', 'MyTestPath2']);
$newValue = $toolbar->getButtonPath();
- $this->assertEquals('MyTestPath2' . DIRECTORY_SEPARATOR, $newValue[0]);
- $this->assertEquals('MyTestPath1' . DIRECTORY_SEPARATOR, $newValue[1]);
+ $this->assertSame('MyTestPath2' . DIRECTORY_SEPARATOR, $newValue[0]);
+ $this->assertSame('MyTestPath1' . DIRECTORY_SEPARATOR, $newValue[1]);
for ($i = 0; $i < $initialCount; $i++) {
- $this->assertEquals($initialValue[$i], $newValue[$i + 2]);
+ $this->assertSame($initialValue[$i], $newValue[$i + 2]);
}
}
@@ -282,10 +281,10 @@ public function testAddButtonPathWithString()
$toolbar->addButtonPath('MyTestPath');
$newValue = $toolbar->getButtonPath();
- $this->assertEquals('MyTestPath' . DIRECTORY_SEPARATOR, $newValue[0]);
+ $this->assertSame('MyTestPath' . DIRECTORY_SEPARATOR, $newValue[0]);
for ($i = 0; $i < $initialCount; $i++) {
- $this->assertEquals($initialValue[$i], $newValue[$i + 1]);
+ $this->assertSame($initialValue[$i], $newValue[$i + 1]);
}
}
@@ -300,7 +299,7 @@ public function testAddButtonPathWithString()
*/
protected function createToolbar($name = 'my-toolbar'): Toolbar
{
- $toolbarFactoryMock = $this->createMock(ToolbarFactoryInterface::class);
+ $toolbarFactoryMock = $this->createStub(ToolbarFactoryInterface::class);
return new Toolbar($name, $toolbarFactoryMock);
}
diff --git a/tests/Unit/Libraries/Cms/Updater/ConstraintCheckerTest.php b/tests/Unit/Libraries/Cms/Updater/ConstraintCheckerTest.php
index 75d62766fb920..b5029cd272a3c 100644
--- a/tests/Unit/Libraries/Cms/Updater/ConstraintCheckerTest.php
+++ b/tests/Unit/Libraries/Cms/Updater/ConstraintCheckerTest.php
@@ -14,7 +14,9 @@
use Joomla\CMS\Updater\ConstraintChecker;
use Joomla\CMS\Version;
use Joomla\Database\DatabaseDriver;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
/**
* Test class for Constraint Checker.
@@ -86,18 +88,16 @@ public function testCheckMethodReturnsTrueIfPlatformIsOnlyConstraint()
* @return void
*
* @since 5.1.0
- *
- * @dataProvider supportedDatabasesDataProvider
*/
+ #[DataProvider('supportedDatabasesDataProvider')]
public function testCheckSupportedDatabases($currentDatabase, $supportedDatabases, $expectedResult)
{
- $dbMock = $this->createMock(DatabaseDriver::class);
+ $dbMock = $this->createStub(DatabaseDriver::class);
$dbMock->method('getServerType')->willReturn($currentDatabase['type']);
$dbMock->method('getVersion')->willReturn($currentDatabase['version']);
Factory::$database = $dbMock;
- $method = $this->getPublicMethod('checkSupportedDatabases');
- $result = $method->invoke($this->checker, $supportedDatabases);
+ $result = TestHelper::invoke($this->checker, 'checkSupportedDatabases', $supportedDatabases);
$this->assertSame($expectedResult, $result);
}
@@ -108,14 +108,10 @@ public function testCheckSupportedDatabases($currentDatabase, $supportedDatabase
* @return void
*
* @since 5.1.0
- *
- * @dataProvider targetplatformDataProvider
*/
public function testCheckPhpMinimumReturnFalseForFuturePhp()
{
- $method = $this->getPublicMethod('checkPhpMinimum');
-
- $this->assertFalse($method->invoke($this->checker, '99.9.9'));
+ $this->assertFalse(TestHelper::invoke($this->checker, 'checkPhpMinimum', '99.9.9'));
}
/**
@@ -124,15 +120,11 @@ public function testCheckPhpMinimumReturnFalseForFuturePhp()
* @return void
*
* @since 5.1.0
- *
- * @dataProvider targetplatformDataProvider
*/
+ #[DataProvider('targetplatformDataProvider')]
public function testCheckTargetplatform($targetPlatform, $expectedResult)
{
- $method = $this->getPublicMethod('checkTargetplatform');
- $result = $method->invoke($this->checker, $targetPlatform);
-
- $this->assertSame($expectedResult, $result);
+ $this->assertSame($expectedResult, TestHelper::invoke($this->checker, 'checkTargetplatform', $targetPlatform));
}
/**
@@ -142,7 +134,7 @@ public function testCheckTargetplatform($targetPlatform, $expectedResult)
*
* @return array[]
*/
- protected function supportedDatabasesDataProvider()
+ public static function supportedDatabasesDataProvider()
{
return [
[
@@ -190,7 +182,7 @@ protected function supportedDatabasesDataProvider()
*
* @return array[]
*/
- protected function targetplatformDataProvider()
+ public static function targetplatformDataProvider()
{
return [
[(array) ["name" => "foobar", "version" => "1.*"], false],
@@ -205,22 +197,4 @@ protected function targetplatformDataProvider()
[(array) ["name" => "joomla", "version" => "5.*"], false],
];
}
-
- /**
- * Internal helper method to get access to protected methods
- *
- * @since 5.1.0
- *
- * @param $method
- *
- * @return \ReflectionMethod
- * @throws \ReflectionException
- */
- protected function getPublicMethod($method)
- {
- $reflectionClass = new \ReflectionClass($this->checker);
- $method = $reflectionClass->getMethod($method);
-
- return $method;
- }
}
diff --git a/tests/Unit/Libraries/Cms/Updater/TufAdapterTest.php b/tests/Unit/Libraries/Cms/Updater/TufAdapterTest.php
index 780d27d6de00f..4553c4811f1de 100644
--- a/tests/Unit/Libraries/Cms/Updater/TufAdapterTest.php
+++ b/tests/Unit/Libraries/Cms/Updater/TufAdapterTest.php
@@ -11,6 +11,7 @@
namespace Joomla\Tests\Unit\Libraries\Cms\Updater;
use Joomla\CMS\Updater\Adapter\TufAdapter;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
use Joomla\Utilities\ArrayHelper;
use Tuf\Exception\MetadataException;
@@ -34,12 +35,9 @@ public function testProcessTufTargetThrowsExceptionIfHashesAreMissing()
$this->expectException(MetadataException::class);
$this->expectExceptionMessage("No trusted hashes are available for 'nohash.json'");
- $object = $this->getMockBuilder(TufAdapter::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $object = $this->createStub(TufAdapter::class);
- $method = $this->getPublicMethod($object, 'processTufTarget');
- $method->invoke($object, 'nohash.json', []);
+ TestHelper::invoke($object, 'processTufTarget', 'nohash.json', []);
}
/**
@@ -49,12 +47,9 @@ public function testProcessTufTargetThrowsExceptionIfHashesAreMissing()
*/
public function testProcesstuftargetAssignsCustomTargetKeys()
{
- $object = $this->getMockBuilder(TufAdapter::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $object = $this->createStub(TufAdapter::class);
- $method = $this->getPublicMethod($object, 'processTufTarget');
- $result = $method->invoke($object, 'targets.json', $this->getMockTarget([
+ $result = TestHelper::invoke($object, 'processTufTarget', 'targets.json', $this->getMockTarget([
'custom' => [
'name' => 'Testupdate',
'version' => '1.2.3',
@@ -72,13 +67,9 @@ public function testProcesstuftargetAssignsCustomTargetKeys()
*/
public function testProcesstuftargetAssignsClientId()
{
- $object = $this->getMockBuilder(TufAdapter::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $object = $this->createStub(TufAdapter::class);
-
- $method = $this->getPublicMethod($object, 'processTufTarget');
- $result = $method->invoke($object, 'targets.json', $this->getMockTarget([
+ $result = TestHelper::invoke($object, 'processTufTarget', 'targets.json', $this->getMockTarget([
'client' => 'site',
]));
@@ -92,13 +83,9 @@ public function testProcesstuftargetAssignsClientId()
*/
public function testProcesstuftargetAssignsInfoUrl()
{
- $object = $this->getMockBuilder(TufAdapter::class)
- ->disableOriginalConstructor()
- ->getMock();
-
+ $object = $this->createStub(TufAdapter::class);
- $method = $this->getPublicMethod($object, 'processTufTarget');
- $result = $method->invoke($object, 'targets.json', $this->getMockTarget([
+ $result = TestHelper::invoke($object, 'processTufTarget', 'targets.json', $this->getMockTarget([
'custom' => [
'infourl' => [
'url' => 'https://example.org',
@@ -109,25 +96,6 @@ public function testProcesstuftargetAssignsInfoUrl()
$this->assertSame('https://example.org', $result['infourl']);
}
- /**
- * Internal helper method to get access to protected methods
- *
- * @since 5.1.0
- *
- * @param $object
- * @param $method
- *
- * @return \ReflectionMethod
- * @throws \ReflectionException
- */
- protected function getPublicMethod($object, $method)
- {
- $reflectionClass = new \ReflectionClass($object);
- $method = $reflectionClass->getMethod($method);
-
- return $method;
- }
-
/**
* Target override data
*
diff --git a/tests/Unit/Libraries/Cms/Uri/UriTest.php b/tests/Unit/Libraries/Cms/Uri/UriTest.php
index 359bc8f108d86..db142a0125cdb 100644
--- a/tests/Unit/Libraries/Cms/Uri/UriTest.php
+++ b/tests/Unit/Libraries/Cms/Uri/UriTest.php
@@ -12,6 +12,8 @@
use Joomla\CMS\Uri\Uri;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\BackupGlobals;
+use PHPUnit\Framework\Attributes\CoversMethod;
/**
* Test class for Uri.
@@ -19,9 +21,15 @@
* @package Joomla.UnitTest
* @subpackage Uri
* @since 1.7.0
- *
- * @backupGlobals enabled
*/
+#[BackupGlobals(true)]
+#[CoversMethod(Uri::class, 'getInstance')]
+#[CoversMethod(Uri::class, 'root')]
+#[CoversMethod(Uri::class, 'current')]
+#[CoversMethod(Uri::class, 'parse')]
+#[CoversMethod(Uri::class, 'buildQuery')]
+#[CoversMethod(Uri::class, 'setPath')]
+#[CoversMethod(Uri::class, 'isInternal')]
class UriTest extends UnitTestCase
{
/**
@@ -71,7 +79,6 @@ protected function tearDown(): void
* @return void
*
* @since 1.7.0
- * @covers Uri::getInstance
*/
public function testGetInstance(): void
{
@@ -91,7 +98,6 @@ public function testGetInstance(): void
* @return void
*
* @since 1.7.0
- * @covers Uri::root
*/
public function testRoot(): void
{
@@ -107,7 +113,6 @@ public function testRoot(): void
* @return void
*
* @since 1.7.0
- * @covers Uri::current
*/
public function testCurrent(): void
{
@@ -123,7 +128,6 @@ public function testCurrent(): void
* @return void
*
* @since 1.7.0
- * @covers Uri::parse
*/
public function testParse(): void
{
@@ -136,7 +140,6 @@ public function testParse(): void
* @return void
*
* @since 1.7.0
- * @covers Uri::buildQuery
*/
public function testBuildQuery(): void
{
@@ -152,7 +155,7 @@ public function testBuildQuery(): void
];
$expected = 'field[price][from]=5&field[price][to]=10&field[name]=foo&v=45';
- $this->assertEquals($expected, Uri::buildQuery($params), 'The query string was not built correctly.');
+ $this->assertSame($expected, Uri::buildQuery($params), 'The query string was not built correctly.');
}
/**
@@ -161,7 +164,6 @@ public function testBuildQuery(): void
* @return void
*
* @since 1.7.0
- * @covers Uri::setPath
*/
public function testSetPath(): void
{
@@ -178,8 +180,6 @@ public function testSetPath(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testParseWhenNoSchemeGiven(): void
{
@@ -191,8 +191,6 @@ public function testParseWhenNoSchemeGiven(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithSefUrl(): void
{
@@ -204,8 +202,6 @@ public function testIsInternalWithSefUrl(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithNoSchemeAndNotInternal(): void
{
@@ -219,8 +215,6 @@ public function testIsInternalWithNoSchemeAndNotInternal(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithNoSchemeAndNoHostnameAndNotInternal(): void
{
@@ -234,8 +228,6 @@ public function testIsInternalWithNoSchemeAndNoHostnameAndNotInternal(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithSchemeAndNotInternal(): void
{
@@ -249,8 +241,6 @@ public function testIsInternalWithSchemeAndNotInternal(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWhenInternalWithNoDomainOrScheme(): void
{
@@ -264,8 +254,6 @@ public function testIsInternalWhenInternalWithNoDomainOrScheme(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWhenInternalWithDomainAndSchemeAndPort(): void
{
@@ -279,8 +267,6 @@ public function testIsInternalWhenInternalWithDomainAndSchemeAndPort(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWhenInternalWithDomainAndSchemeAndPortNoSubFolder(): void
{
@@ -303,8 +289,6 @@ public function testIsInternalWhenInternalWithDomainAndSchemeAndPortNoSubFolder(
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWhenNOTInternalWithDomainAndSchemeAndPortAndIndex(): void
{
@@ -318,8 +302,6 @@ public function testIsInternalWhenNOTInternalWithDomainAndSchemeAndPortAndIndex(
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWhenNOTInternalWithDomainAndNoSchemeAndPortAndIndex(): void
{
@@ -333,8 +315,6 @@ public function testIsInternalWhenNOTInternalWithDomainAndNoSchemeAndPortAndInde
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternal3rdPartyDevs(): void
{
@@ -348,8 +328,6 @@ public function testIsInternal3rdPartyDevs(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalAppendingOfBaseToTheEndOfTheUrl(): void
{
@@ -363,8 +341,6 @@ public function testIsInternalAppendingOfBaseToTheEndOfTheUrl(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalAppendingOfBaseToTheEndOfTheUrl2(): void
{
@@ -378,8 +354,6 @@ public function testIsInternalAppendingOfBaseToTheEndOfTheUrl2(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalSchemeEmptyButHostAndPortMatch(): void
{
@@ -393,8 +367,6 @@ public function testIsInternalSchemeEmptyButHostAndPortMatch(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithSchemeAndHostAndPortMatch(): void
{
@@ -408,8 +380,6 @@ public function testIsInternalWithSchemeAndHostAndPortMatch(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithSchemeNotMatch(): void
{
@@ -423,8 +393,6 @@ public function testIsInternalWithSchemeNotMatch(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalPregMatch(): void
{
@@ -438,8 +406,6 @@ public function testIsInternalPregMatch(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithUser(): void
{
@@ -453,8 +419,6 @@ public function testIsInternalWithUser(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithBackslashInUser(): void
{
@@ -468,8 +432,6 @@ public function testIsInternalWithBackslashInUser(): void
* Test hardening of Uri::isInternal against non internal links
*
* @return void
- *
- * @covers Uri::isInternal
*/
public function testIsInternalWithUrlInPath(): void
{
@@ -478,4 +440,34 @@ public function testIsInternalWithUrlInPath(): void
'http://www.evil.com/' . Uri::base() . ' should not be internal'
);
}
+
+ /**
+ * Test hardening of Uri::isInternal against non internal links
+ *
+ * @return void
+ *
+ * @covers Uri::isInternal
+ */
+ public function testIsInternalWithAbsoluteXssPayloads(): void
+ {
+ $this->assertFalse(
+ Uri::isInternal('http://www.example.com/ "'),
+ 'http://www.example.com " should not be internal'
+ );
+ }
+
+ /**
+ * Test hardening of Uri::isInternal against non internal links
+ *
+ * @return void
+ *
+ * @covers Uri::isInternal
+ */
+ public function testIsInternalWithRelativeXssPayloads(): void
+ {
+ $this->assertFalse(
+ Uri::isInternal('index.php?'),
+ 'index.php? should not be internal'
+ );
+ }
}
diff --git a/tests/Unit/Libraries/Cms/User/CurrentUserTraitTest.php b/tests/Unit/Libraries/Cms/User/CurrentUserTraitTest.php
index b2632920792bf..b70f59048eb0f 100644
--- a/tests/Unit/Libraries/Cms/User/CurrentUserTraitTest.php
+++ b/tests/Unit/Libraries/Cms/User/CurrentUserTraitTest.php
@@ -13,6 +13,7 @@
use Joomla\CMS\User\CurrentUserTrait;
use Joomla\CMS\User\User;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\MVC\Model\BaseDatabaseModelUser\CurrentUserTrait
@@ -24,12 +25,11 @@
class CurrentUserTraitTest extends UnitTestCase
{
/**
- * @testdox The current user can be set with setCurrentUser()
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('The current user can be set with setCurrentUser()')]
public function testGetCurrentUser()
{
$user = new User();
@@ -45,6 +45,6 @@ public function getUser(): User
$trait->setCurrentUser($user);
- $this->assertEquals($user, $trait->getUser());
+ $this->assertSame($user, $trait->getUser());
}
}
diff --git a/tests/Unit/Libraries/Cms/User/UserFactoryAwareTraitTest.php b/tests/Unit/Libraries/Cms/User/UserFactoryAwareTraitTest.php
index 83cd5f983ca57..0459293156872 100644
--- a/tests/Unit/Libraries/Cms/User/UserFactoryAwareTraitTest.php
+++ b/tests/Unit/Libraries/Cms/User/UserFactoryAwareTraitTest.php
@@ -14,6 +14,7 @@
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for \Joomla\CMS\User\UserFactoryAwareTrait
@@ -25,12 +26,11 @@
class UserFactoryAwareTraitTest extends UnitTestCase
{
/**
- * @testdox The user factory can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The user factory can be set and accessed by the trait')]
public function testGetSetUserFactory()
{
$userFactory = new class () implements UserFactoryInterface {
@@ -56,16 +56,15 @@ public function getFactory(): UserFactoryInterface
$trait->setUserFactory($userFactory);
- $this->assertEquals($userFactory, $trait->getFactory());
+ $this->assertSame($userFactory, $trait->getFactory());
}
/**
- * @testdox The user factory can be set and accessed by the trait
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('The user factory can be set and accessed by the trait')]
public function testGetUserFactoryThrowsException()
{
$this->expectException(\UnexpectedValueException::class);
diff --git a/tests/Unit/Libraries/Cms/VersionTest.php b/tests/Unit/Libraries/Cms/VersionTest.php
index b6327d1c2c4b2..fb9af498e7231 100644
--- a/tests/Unit/Libraries/Cms/VersionTest.php
+++ b/tests/Unit/Libraries/Cms/VersionTest.php
@@ -88,7 +88,7 @@ public function testGetHelpVersion()
*/
public function testGetShortVersion()
{
- $this->assertEquals(JVERSION, $this->version->getShortVersion());
+ $this->assertSame(JVERSION, $this->version->getShortVersion());
}
/**
diff --git a/tests/Unit/Libraries/Cms/WebAsset/WebAssetManagerTest.php b/tests/Unit/Libraries/Cms/WebAsset/WebAssetManagerTest.php
index 573c3042f53e7..edf7d958c1b0a 100644
--- a/tests/Unit/Libraries/Cms/WebAsset/WebAssetManagerTest.php
+++ b/tests/Unit/Libraries/Cms/WebAsset/WebAssetManagerTest.php
@@ -190,14 +190,14 @@ public function testGetAssets(): void
$wa->useAsset('script', 'test5');
$assets = $wa->getAssets('script');
- $this->assertEquals(
+ $this->assertSame(
['test3', 'test1', 'test2', 'test4', 'test5'],
array_keys($assets),
'Should return all active assets in FIFO order, with automatically enabled dependencies "at top"'
);
$assets2 = $wa->getAssets('script', true);
- $this->assertEquals(
+ $this->assertSame(
['test3', 'test1', 'test2', 'test5', 'test4'],
array_keys($assets2),
'Should return all active assets in a Graph order'
diff --git a/tests/Unit/Libraries/Cms/WebAsset/WebAssetRegistryTest.php b/tests/Unit/Libraries/Cms/WebAsset/WebAssetRegistryTest.php
index d07ac62e03114..8b4c8bad6dda5 100644
--- a/tests/Unit/Libraries/Cms/WebAsset/WebAssetRegistryTest.php
+++ b/tests/Unit/Libraries/Cms/WebAsset/WebAssetRegistryTest.php
@@ -40,7 +40,7 @@ public function testAddGet(): void
$r->add('script', $a);
- $this->assertTrue($r->get('script', 'test') === $a, 'Should return same instance');
+ $this->assertSame($a, $r->get('script', 'test'), 'Should return same instance');
$this->expectException(UnknownAssetException::class);
$r->get('script', 'test.nope');
@@ -131,21 +131,21 @@ function (WebAssetRegistryAssetChanged $event) use (&$eventName, &$eventAsset, &
// Test: new
$r->add('script', $a1);
- $this->assertEquals('onWebAssetRegistryChangedAssetNew', $eventName, 'Should trigger correct event');
- $this->assertTrue($a1 === $eventAsset, 'Should provide correct asset instance');
- $this->assertEquals('new', $change, 'Should provide correct "change"');
+ $this->assertSame('onWebAssetRegistryChangedAssetNew', $eventName, 'Should trigger correct event');
+ $this->assertSame($a1, $eventAsset, 'Should provide correct asset instance');
+ $this->assertSame('new', $change, 'Should provide correct "change"');
// Test: override
$r->add('script', $a2);
- $this->assertEquals('onWebAssetRegistryChangedAssetOverride', $eventName, 'Should trigger correct event');
- $this->assertTrue($a1 === $eventAsset, 'Should provide original asset instance');
- $this->assertEquals('override', $change, 'Should provide correct "change"');
+ $this->assertSame('onWebAssetRegistryChangedAssetOverride', $eventName, 'Should trigger correct event');
+ $this->assertSame($a1, $eventAsset, 'Should provide original asset instance');
+ $this->assertSame('override', $change, 'Should provide correct "change"');
// Test: remove
$r->remove('script', $a2->getName());
- $this->assertEquals('onWebAssetRegistryChangedAssetRemove', $eventName, 'Should trigger correct event');
- $this->assertTrue($a2 === $eventAsset, 'Should provide original asset instance');
- $this->assertEquals('remove', $change, 'Should provide correct "change"');
+ $this->assertSame('onWebAssetRegistryChangedAssetRemove', $eventName, 'Should trigger correct event');
+ $this->assertSame($a2, $eventAsset, 'Should provide original asset instance');
+ $this->assertSame('remove', $change, 'Should provide correct "change"');
}
/**
@@ -161,9 +161,9 @@ public function testCreateAsset(): void
$a = $r->createAsset('test', 'test.js', ['foo' => 'bar'], ['type' => 'module'], ['core']);
$this->assertInstanceOf(WebAssetItem::class, $a);
- $this->assertEquals(['foo' => 'bar'], $a->getOptions());
- $this->assertEquals(['type' => 'module'], $a->getAttributes());
- $this->assertEquals(['core'], $a->getDependencies());
+ $this->assertSame(['foo' => 'bar'], $a->getOptions());
+ $this->assertSame(['type' => 'module'], $a->getAttributes());
+ $this->assertSame(['core'], $a->getDependencies());
// Create with the specified class name
$b = $r->createAsset(
diff --git a/tests/Unit/Libraries/Tuf/DatabaseStorageTest.php b/tests/Unit/Libraries/Tuf/DatabaseStorageTest.php
index 398cc9d5be1c0..bca5645e8a6dc 100644
--- a/tests/Unit/Libraries/Tuf/DatabaseStorageTest.php
+++ b/tests/Unit/Libraries/Tuf/DatabaseStorageTest.php
@@ -12,7 +12,9 @@
use Joomla\CMS\Table\Tuf;
use Joomla\CMS\TUF\DatabaseStorage;
+use Joomla\Test\TestHelper;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
/**
* Test class for DatabaseStorage
@@ -28,12 +30,13 @@ class DatabaseStorageTest extends UnitTestCase
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testConstructorWritesColumnMetadataToInternalStorage()
{
$table = $this->getTableMock(['root' => 'rootfoo']);
$object = new DatabaseStorage($table);
- $this->assertEquals('rootfoo', $this->getInternalStorageValue($object)['root']);
+ $this->assertSame('rootfoo', TestHelper::getValue($object, 'container')['root']);
}
/**
@@ -41,12 +44,13 @@ public function testConstructorWritesColumnMetadataToInternalStorage()
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testConstructorIgnoresNonMetadataColumns()
{
$table = $this->getTableMock(['foobar' => 'aaa']);
$object = new DatabaseStorage($table);
- $this->assertArrayNotHasKey('foobar', $this->getInternalStorageValue($object));
+ $this->assertArrayNotHasKey('foobar', TestHelper::getValue($object, 'container'));
}
/**
@@ -54,10 +58,11 @@ public function testConstructorIgnoresNonMetadataColumns()
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testReadReturnsStorageValueForExistingColumns()
{
$object = new DatabaseStorage($this->getTableMock(['root' => 'foobar']));
- $this->assertEquals('foobar', $object->read('root'));
+ $this->assertSame('foobar', $object->read('root'));
}
/**
@@ -65,6 +70,7 @@ public function testReadReturnsStorageValueForExistingColumns()
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testReadReturnsNullForNonexistentColumns()
{
$object = new DatabaseStorage($this->getTableMock([]));
@@ -76,12 +82,13 @@ public function testReadReturnsNullForNonexistentColumns()
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testWriteUpdatesGivenInternalStorageValue()
{
$object = new DatabaseStorage($this->getTableMock(['root' => 'foo']));
$object->write('root', 'bar');
- $this->assertEquals('bar', $this->getInternalStorageValue($object)['root']);
+ $this->assertSame('bar', TestHelper::getValue($object, 'container')['root']);
}
/**
@@ -89,12 +96,13 @@ public function testWriteUpdatesGivenInternalStorageValue()
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testWriteCreatesNewInternalStorageValue()
{
$object = new DatabaseStorage($this->getTableMock(['root' => 'foo']));
$object->write('targets', 'bar');
- $this->assertEquals('bar', $this->getInternalStorageValue($object)['targets']);
+ $this->assertSame('bar', TestHelper::getValue($object, 'container')['targets']);
}
/**
@@ -102,12 +110,13 @@ public function testWriteCreatesNewInternalStorageValue()
*
* @since 5.1.0
*/
+ #[AllowMockObjectsWithoutExpectations]
public function testDeleteRemovesRowFromInternalStorage()
{
$object = new DatabaseStorage($this->getTableMock(['root' => 'foo']));
$object->delete('root');
- $this->assertArrayNotHasKey('root', $this->getInternalStorageValue($object));
+ $this->assertArrayNotHasKey('root', TestHelper::getValue($object, 'container'));
}
/**
@@ -147,18 +156,4 @@ protected function getTableMock(array $mockData)
return $table;
}
-
- /**
- * @param $class
- *
- * @since 5.1.0
- *
- * @return mixed
- */
- protected function getInternalStorageValue($class)
- {
- $reflectionProperty = new \ReflectionProperty(DatabaseStorage::class, 'container');
-
- return $reflectionProperty->getValue($class);
- }
}
diff --git a/tests/Unit/Libraries/Tuf/HttpLoaderTest.php b/tests/Unit/Libraries/Tuf/HttpLoaderTest.php
index 06ebd9dda56da..e37cfddee0338 100644
--- a/tests/Unit/Libraries/Tuf/HttpLoaderTest.php
+++ b/tests/Unit/Libraries/Tuf/HttpLoaderTest.php
@@ -37,7 +37,7 @@ class HttpLoaderTest extends UnitTestCase
*/
public function testLoaderQueriesCorrectUrl()
{
- $responseBody = $this->createMock(Stream::class);
+ $responseBody = $this->createStub(Stream::class);
$object = new HttpLoader(
self::REPOPATHMOCK,
@@ -54,7 +54,7 @@ public function testLoaderQueriesCorrectUrl()
*/
public function testLoaderForwardsReturnedBodyFromHttpClient()
{
- $responseBody = $this->createMock(Stream::class);
+ $responseBody = $this->createStub(Stream::class);
$object = new HttpLoader(
self::REPOPATHMOCK,
@@ -76,7 +76,7 @@ public function testLoaderThrowsExceptionForNon200Response()
{
$this->expectException(RepoFileNotFound::class);
- $responseBody = $this->createMock(Stream::class);
+ $responseBody = $this->createStub(Stream::class);
$object = new HttpLoader(
self::REPOPATHMOCK,
diff --git a/tests/Unit/Plugin/Authentication/Ldap/LdapPluginTest.php b/tests/Unit/Plugin/Authentication/Ldap/LdapPluginTest.php
index b5106254e3524..f91faa899ab15 100644
--- a/tests/Unit/Plugin/Authentication/Ldap/LdapPluginTest.php
+++ b/tests/Unit/Plugin/Authentication/Ldap/LdapPluginTest.php
@@ -18,6 +18,7 @@
use Joomla\Plugin\Authentication\Ldap\Extension\Ldap;
use Joomla\Plugin\Authentication\Ldap\Factory\LdapFactoryInterface;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
use Symfony\Component\Ldap\Adapter\CollectionInterface;
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
use Symfony\Component\Ldap\Adapter\QueryInterface;
@@ -31,19 +32,17 @@
* @package Joomla.UnitTest
* @subpackage Ldap
*
- * @testdox The Ldap plugin
- *
* @since 4.3.0
*/
+#[TestDox('The Ldap plugin')]
class LdapPluginTest extends UnitTestCase
{
/**
- * @testdox when no host is set
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('when no host is set')]
public function testNoHost()
{
$plugin = new Ldap($this->createFactory(), ['params' => []]);
@@ -53,16 +52,15 @@ public function testNoHost()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => [], 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox when no credentials are set
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('when no credentials are set')]
public function testNoCredentials()
{
$language = $this->createStub(Language::class);
@@ -78,16 +76,15 @@ public function testNoCredentials()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => ['password' => ''], 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can perform no authentication
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform no authentication')]
public function testNoAuthenticationMethod()
{
$language = $this->createStub(Language::class);
@@ -104,16 +101,15 @@ public function testNoAuthenticationMethod()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can perform an authentication using search
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using search')]
public function testSearchAuthenticationMethod()
{
$plugin = new Ldap($this->createFactory(), ['params' => ['auth_method' => 'search', 'host' => 'test']]);
@@ -123,16 +119,15 @@ public function testSearchAuthenticationMethod()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
/**
- * @testdox can perform an authentication using search when no entry is found
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using search when no entry is found')]
public function testSearchAuthenticationMethodNoEntry()
{
$language = $this->createStub(Language::class);
@@ -149,16 +144,15 @@ public function testSearchAuthenticationMethodNoEntry()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can not perform an authentication using search when bind fails
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can not perform an authentication using search when bind fails')]
public function testSearchAuthenticationMethodWithBindException()
{
$language = $this->createStub(Language::class);
@@ -175,16 +169,15 @@ public function testSearchAuthenticationMethodWithBindException()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can not perform an authentication using search when query fails
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can not perform an authentication using search when query fails')]
public function testSearchAuthenticationMethodWithQueryException()
{
$language = $this->createStub(Language::class);
@@ -201,16 +194,15 @@ public function testSearchAuthenticationMethodWithQueryException()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can perform an authentication using bind
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using bind')]
public function testBindAuthenticationMethod()
{
$plugin = new Ldap($this->createFactory(), ['params' => ['auth_method' => 'bind', 'host' => 'test']]);
@@ -220,16 +212,15 @@ public function testBindAuthenticationMethod()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
/**
- * @testdox can perform an authentication using bind when no entry is found
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using bind when no entry is found')]
public function testBindAuthenticationMethodNoEntry()
{
$language = $this->createStub(Language::class);
@@ -246,16 +237,15 @@ public function testBindAuthenticationMethodNoEntry()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can perform an authentication using bind with a DN
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can perform an authentication using bind with a DN')]
public function testBindAuthenticationMethodWithDN()
{
$plugin = new Ldap($this->createFactory(), ['params' => ['auth_method' => 'bind', 'users_dn' => 'test', 'host' => 'test']]);
@@ -265,16 +255,15 @@ public function testBindAuthenticationMethodWithDN()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_SUCCESS, $response->status);
+ $this->assertSame(Authentication::STATUS_SUCCESS, $response->status);
}
/**
- * @testdox can not perform an authentication using bind when bind fails
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can not perform an authentication using bind when bind fails')]
public function testBindAuthenticationMethodWithBindException()
{
$language = $this->createStub(Language::class);
@@ -291,16 +280,15 @@ public function testBindAuthenticationMethodWithBindException()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
- * @testdox can not perform an authentication using bind when query fails
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can not perform an authentication using bind when query fails')]
public function testBindAuthenticationMethodWithQueryException()
{
$language = $this->createStub(Language::class);
@@ -317,7 +305,7 @@ public function testBindAuthenticationMethodWithQueryException()
$event = new AuthenticationEvent('onUserAuthenticate', ['credentials' => $credentials, 'options' => [], 'subject' => $response]);
$plugin->onUserAuthenticate($event);
- $this->assertEquals(Authentication::STATUS_FAILURE, $response->status);
+ $this->assertSame(Authentication::STATUS_FAILURE, $response->status);
}
/**
diff --git a/tests/Unit/Plugin/Content/ConfirmConsent/Extension/ConfirmConsentTest.php b/tests/Unit/Plugin/Content/ConfirmConsent/Extension/ConfirmConsentTest.php
index b0c757cf92cb6..70a5203b2c70e 100644
--- a/tests/Unit/Plugin/Content/ConfirmConsent/Extension/ConfirmConsentTest.php
+++ b/tests/Unit/Plugin/Content/ConfirmConsent/Extension/ConfirmConsentTest.php
@@ -18,6 +18,7 @@
use Joomla\Event\Dispatcher;
use Joomla\Plugin\Content\ConfirmConsent\Extension\ConfirmConsent;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for ConfirmConsent plugin
@@ -25,19 +26,17 @@
* @package Joomla.UnitTest
* @subpackage ConfirmConsent
*
- * @testdox The ConfirmConsent plugin
- *
* @since 4.3.0
*/
+#[TestDox('The ConfirmConsent plugin')]
class ConfirmConsentTest extends UnitTestCase
{
/**
- * @testdox that the consent field is loaded into the form
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('that the consent field is loaded into the form')]
public function testLoadConsentFieldInForm()
{
$form = new Form('com_contact.contact');
@@ -58,12 +57,11 @@ public function testLoadConsentFieldInForm()
}
/**
- * @testdox that the consent field is not loaded into the form when wrong form name
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('that the consent field is not loaded into the form when wrong form name')]
public function testLoadConsentFieldInFormWrongContext()
{
$form = new Form('invalid');
@@ -81,12 +79,11 @@ public function testLoadConsentFieldInFormWrongContext()
}
/**
- * @testdox that the consent field is not loaded into the form when wrong application
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('that the consent field is not loaded into the form when wrong application')]
public function testLoadConsentFieldInFormWrongApplication()
{
$form = new Form('com_contact.contact');
diff --git a/tests/Unit/Plugin/EditorsXtd/PageBreak/Extension/PageBreakTest.php b/tests/Unit/Plugin/EditorsXtd/PageBreak/Extension/PageBreakTest.php
index 34b6cc672b5cf..751cac1c9de94 100644
--- a/tests/Unit/Plugin/EditorsXtd/PageBreak/Extension/PageBreakTest.php
+++ b/tests/Unit/Plugin/EditorsXtd/PageBreak/Extension/PageBreakTest.php
@@ -21,6 +21,7 @@
use Joomla\Event\Dispatcher;
use Joomla\Plugin\EditorsXtd\PageBreak\Extension\PageBreak;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for PageBreak editor button plugin
@@ -28,19 +29,17 @@
* @package Joomla.UnitTest
* @subpackage PageBreak
*
- * @testdox The PageBreak plugin
- *
* @since 4.4.0
*/
+#[TestDox('The PageBreak plugin')]
class PageBreakTest extends UnitTestCase
{
/**
- * @testdox that the button is properly loaded
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('that the button is properly loaded')]
public function testButton()
{
$user = $this->createStub(User::class);
@@ -67,8 +66,8 @@ public function testButton()
$button = $btnsReg->getAll()[0] ?? false;
$this->assertInstanceOf(Button::class, $button);
- $this->assertEquals('pagebreak', $button->getButtonName());
- $this->assertEquals('modal', $button->get('action'));
+ $this->assertSame('pagebreak', $button->getButtonName());
+ $this->assertSame('modal', $button->get('action'));
$this->assertNotEmpty($button->get('link'));
$this->assertNotEmpty($button->get('text'));
$this->assertNotEmpty($button->get('icon'));
@@ -76,12 +75,11 @@ public function testButton()
}
/**
- * @testdox that the user has not enough permission
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('that the user has not enough permission')]
public function testInvalidPermissions()
{
$user = $this->createStub(User::class);
@@ -110,12 +108,11 @@ public function testInvalidPermissions()
}
/**
- * @testdox that the button is not returned when a none web CMS application is used
- *
* @return void
*
* @since 4.4.0
*/
+ #[TestDox('that the button is not returned when a none web CMS application is used')]
public function testInvalidApplication()
{
$btnsReg = new ButtonsRegistry();
diff --git a/tests/Unit/Plugin/Filesystem/Local/Adapter/LocalAdapterTest.php b/tests/Unit/Plugin/Filesystem/Local/Adapter/LocalAdapterTest.php
new file mode 100644
index 0000000000000..6f4c06163f375
--- /dev/null
+++ b/tests/Unit/Plugin/Filesystem/Local/Adapter/LocalAdapterTest.php
@@ -0,0 +1,192 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\Tests\Unit\Plugin\Filesystem\Local\Adapter;
+
+use Joomla\CMS\Application\CMSApplicationInterface;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Component\ComponentRecord;
+use Joomla\CMS\Factory;
+use Joomla\Filesystem\File;
+use Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter;
+use Joomla\Registry\Registry;
+use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
+
+/**
+ * Test class for the Local filesystem adapter.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Local
+ *
+ * @since 6.2.0
+ */
+#[TestDox('The Local adapter')]
+class LocalAdapterTest extends UnitTestCase
+{
+ /**
+ * Absolute path of the throw-away media root used by a single test.
+ *
+ * @var string
+ * @since 6.2.0
+ */
+ private $workDir;
+
+ /**
+ * Creates an isolated media root and the minimal global state that
+ * MediaHelper::canUpload() reaches for (the application and the com_media
+ * component parameters), so the adapter can run as a pure unit test.
+ *
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->workDir = sys_get_temp_dir() . '/joomla-localadapter-' . uniqid();
+ mkdir($this->workDir);
+
+ // canUpload() calls Factory::getApplication() unconditionally.
+ Factory::$application = $this->createStub(CMSApplicationInterface::class);
+
+ // Seed com_media with empty params so ComponentHelper never queries the database.
+ $record = new ComponentRecord(['option' => 'com_media', 'enabled' => 1]);
+ $record->setParams(new Registry());
+
+ $components = new \ReflectionProperty(ComponentHelper::class, 'components');
+ $components->setValue(null, ['com_media' => $record]);
+ }
+
+ /**
+ * Removes the temporary media root and resets the global state touched in setUp().
+ *
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ protected function tearDown(): void
+ {
+ foreach (glob($this->workDir . '/*') ?: [] as $file) {
+ unlink($file);
+ }
+
+ if (is_dir($this->workDir)) {
+ rmdir($this->workDir);
+ }
+
+ Factory::$application = null;
+
+ $components = new \ReflectionProperty(ComponentHelper::class, 'components');
+ $components->setValue(null, []);
+
+ parent::tearDown();
+ }
+
+ /**
+ * Returns the bytes of a tiny, valid single-colour JPEG so that the
+ * MIME/type checks in canUpload() see a real image.
+ *
+ * @param array $rgb The fill colour as [red, green, blue].
+ *
+ * @return string
+ *
+ * @since 6.2.0
+ */
+ private function jpegBytes(array $rgb): string
+ {
+ $image = imagecreatetruecolor(4, 4);
+ $color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
+ imagefilledrectangle($image, 0, 0, 3, 3, $color);
+
+ ob_start();
+ imagejpeg($image);
+ $bytes = ob_get_clean();
+
+
+ return $bytes;
+ }
+
+ /**
+ * This is the behaviour PR #47935 restores: a file whose on-disk name
+ * contains non-ASCII characters (uploaded via FTP, sample data, a
+ * migration, ...) can be re-saved by the image editor instead of being
+ * rejected by canUpload().
+ *
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('saves an edited file back to its original non-ASCII name')]
+ public function testUpdateFileSavesBackToNonAsciiName()
+ {
+ $name = 'erik_schön.jpg';
+ file_put_contents($this->workDir . '/' . $name, $this->jpegBytes([255, 0, 0]));
+
+ $newContent = $this->jpegBytes([0, 0, 255]);
+
+ $adapter = new LocalAdapter($this->workDir, 'test-media');
+ $adapter->updateFile($name, '/', $newContent);
+
+ $this->assertSame(
+ $newContent,
+ file_get_contents($this->workDir . '/' . $name),
+ 'The non-ASCII named file should be updated in place.'
+ );
+ }
+
+ /**
+ * Answers @brianteeman's review question: the "safe" name derived in
+ * checkContent() is only handed to canUpload() as a validation string. It
+ * is never used to name a file on disk (the probe file uses uniqid(), the
+ * real write targets the original path), so a file that already exists at
+ * File::makeSafe($name) is left completely untouched.
+ *
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('never touches a pre-existing file that already has the safe name')]
+ public function testUpdateFileDoesNotTouchExistingSafeNamedNeighbour()
+ {
+ $name = 'erik_schön.jpg';
+ $safeName = File::makeSafe($name);
+
+ // Guard the premise of the test: the two names really are different.
+ $this->assertNotSame($name, $safeName);
+
+ file_put_contents($this->workDir . '/' . $name, $this->jpegBytes([255, 0, 0]));
+
+ // A pre-existing, unrelated file that happens to sit at the safe name.
+ $neighbourContent = 'PRE-EXISTING-SAFE-NAME-CONTENT';
+ file_put_contents($this->workDir . '/' . $safeName, $neighbourContent);
+
+ $adapter = new LocalAdapter($this->workDir, 'test-media');
+ $adapter->updateFile($name, '/', $this->jpegBytes([0, 0, 255]));
+
+ // The neighbour is byte-for-byte unchanged.
+ $this->assertSame(
+ $neighbourContent,
+ file_get_contents($this->workDir . '/' . $safeName),
+ 'The pre-existing safe-named file must not be overwritten.'
+ );
+
+ // Only the two original files remain: the uniqid() probe file was
+ // cleaned up and no new safe-named file was created.
+ $remaining = array_values(array_diff(scandir($this->workDir), ['.', '..']));
+ sort($remaining);
+
+ $expected = [$name, $safeName];
+ sort($expected);
+
+ $this->assertSame($expected, $remaining, 'No stray files should be left behind.');
+ }
+}
diff --git a/tests/Unit/Plugin/Filesystem/Local/Extension/LocalPluginTest.php b/tests/Unit/Plugin/Filesystem/Local/Extension/LocalPluginTest.php
index 620c427cb1363..79461107f3e20 100644
--- a/tests/Unit/Plugin/Filesystem/Local/Extension/LocalPluginTest.php
+++ b/tests/Unit/Plugin/Filesystem/Local/Extension/LocalPluginTest.php
@@ -17,6 +17,7 @@
use Joomla\Component\Media\Administrator\Provider\ProviderManager;
use Joomla\Plugin\Filesystem\Local\Extension\Local;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for Local plugin
@@ -24,33 +25,30 @@
* @package Joomla.UnitTest
* @subpackage Local
*
- * @testdox The Local plugin
- *
* @since 4.3.0
*/
+#[TestDox('The Local plugin')]
class LocalPluginTest extends UnitTestCase
{
/**
- * @testdox has the correct id
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('has the correct id')]
public function testID()
{
$plugin = new Local(['name' => 'test'], __DIR__);
- $this->assertEquals('test', $plugin->getID());
+ $this->assertSame('test', $plugin->getID());
}
/**
- * @testdox has the correct display name
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('has the correct display name')]
public function testDisplayName()
{
$language = $this->createStub(Language::class);
@@ -62,16 +60,15 @@ public function testDisplayName()
$plugin = new Local([], __DIR__);
$plugin->setApplication($app);
- $this->assertEquals('test', $plugin->getDisplayName());
+ $this->assertSame('test', $plugin->getDisplayName());
}
/**
- * @testdox can setup providers
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can setup providers')]
public function testSetupProviders()
{
$manager = new ProviderManager();
@@ -82,17 +79,16 @@ public function testSetupProviders()
$plugin = new Local(['name' => 'test'], __DIR__);
$plugin->onSetupProviders($event);
- $this->assertEquals(['test' => $plugin], $manager->getProviders());
- $this->assertEquals($plugin, $manager->getProvider('test'));
+ $this->assertSame(['test' => $plugin], $manager->getProviders());
+ $this->assertSame($plugin, $manager->getProvider('test'));
}
/**
- * @testdox can deliver adapters
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('can deliver adapters')]
public function testAdapters()
{
$app = $this->createStub(CMSApplicationInterface::class);
@@ -104,16 +100,15 @@ public function testAdapters()
$adapters = $plugin->getAdapters();
$this->assertCount(1, $adapters);
- $this->assertEquals('tests', $adapters['tests']->getAdapterName());
+ $this->assertSame('tests', $adapters['tests']->getAdapterName());
}
/**
- * @testdox throws an Exception when an invalid directory
- *
* @return void
*
* @since 4.3.0
*/
+ #[TestDox('throws an Exception when an invalid directory')]
public function testAdaptersInvalidDirectory()
{
$this->expectException(\InvalidArgumentException::class);
diff --git a/tests/Unit/Plugin/Schemaorg/JobPosting/Extension/JobPostingPluginTest.php b/tests/Unit/Plugin/Schemaorg/JobPosting/Extension/JobPostingPluginTest.php
new file mode 100644
index 0000000000000..33edd96d9abac
--- /dev/null
+++ b/tests/Unit/Plugin/Schemaorg/JobPosting/Extension/JobPostingPluginTest.php
@@ -0,0 +1,153 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\Tests\Unit\Plugin\Schemaorg\JobPosting\Extension;
+
+use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent;
+use Joomla\Plugin\Schemaorg\JobPosting\Extension\JobPosting;
+use Joomla\Registry\Registry;
+use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
+
+/**
+ * Test class for JobPosting plugin
+ *
+ * @package Joomla.UnitTest
+ * @subpackage JobPosting
+ *
+ * @since 6.2.0
+ */
+#[TestDox('The JobPosting plugin')]
+class JobPostingPluginTest extends UnitTestCase
+{
+ /**
+ * Dispatches the schema through the plugin and returns the resulting graph.
+ *
+ * @param array $entry The JobPosting graph entry to compile
+ *
+ * @return array The compiled graph entry
+ *
+ * @since 6.2.0
+ */
+ private function compileGraphEntry(array $entry): array
+ {
+ $plugin = new JobPosting(['name' => 'jobposting', 'type' => 'schemaorg']);
+
+ $schema = new Registry();
+ $schema->loadArray(['@graph' => [$entry]]);
+
+ $event = new BeforeCompileHeadEvent('onSchemaBeforeCompileHead', [
+ 'subject' => $schema,
+ 'context' => 'com_content.article.1',
+ ]);
+
+ $plugin->onSchemaBeforeCompileHead($event);
+
+ return $schema->get('@graph')[0];
+ }
+
+ /**
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('maps a telecommute job location type to the TELECOMMUTE value expected by search engines')]
+ public function testTelecommuteIsMappedToUppercaseTelecommute()
+ {
+ $entry = $this->compileGraphEntry([
+ '@type' => 'JobPosting',
+ 'title' => 'Remote Developer',
+ 'jobLocationType' => 'Telecommute',
+ ]);
+
+ $this->assertSame('TELECOMMUTE', $entry['jobLocationType']);
+ }
+
+ /**
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('maps a hybrid job location type to TELECOMMUTE while keeping the physical job location')]
+ public function testHybridIsMappedToTelecommuteAndKeepsJobLocation()
+ {
+ $jobLocation = [
+ '@type' => 'Place',
+ 'address' => ['@type' => 'PostalAddress', 'addressLocality' => 'Berlin'],
+ ];
+
+ $entry = $this->compileGraphEntry([
+ '@type' => 'JobPosting',
+ 'title' => 'Hybrid Developer',
+ 'jobLocationType' => 'Hybrid',
+ 'jobLocation' => $jobLocation,
+ ]);
+
+ $this->assertSame('TELECOMMUTE', $entry['jobLocationType']);
+ $this->assertSame($jobLocation, $entry['jobLocation']);
+ }
+
+ /**
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('omits the job location type for an on-site job so only the job location is emitted')]
+ public function testOnsiteJobLocationTypeIsOmitted()
+ {
+ $jobLocation = [
+ '@type' => 'Place',
+ 'address' => ['@type' => 'PostalAddress', 'addressLocality' => 'Berlin'],
+ ];
+
+ $entry = $this->compileGraphEntry([
+ '@type' => 'JobPosting',
+ 'title' => 'Onsite Developer',
+ 'jobLocationType' => 'Onsite',
+ 'jobLocation' => $jobLocation,
+ ]);
+
+ $this->assertArrayNotHasKey('jobLocationType', $entry);
+ $this->assertSame($jobLocation, $entry['jobLocation']);
+ }
+
+ /**
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('leaves an entry without a job location type untouched')]
+ public function testEntryWithoutJobLocationTypeIsUntouched()
+ {
+ $entry = $this->compileGraphEntry([
+ '@type' => 'JobPosting',
+ 'title' => 'Developer',
+ ]);
+
+ $this->assertArrayNotHasKey('jobLocationType', $entry);
+ $this->assertSame('Developer', $entry['title']);
+ }
+
+ /**
+ * @return void
+ *
+ * @since 6.2.0
+ */
+ #[TestDox('does not touch graph entries of other schema types')]
+ public function testOtherSchemaTypesAreUntouched()
+ {
+ $entry = $this->compileGraphEntry([
+ '@type' => 'Event',
+ 'jobLocationType' => 'Onsite',
+ ]);
+
+ $this->assertSame('Onsite', $entry['jobLocationType']);
+ }
+}
diff --git a/tests/Unit/Plugin/Task/Checkfiles/Extension/CheckfilesPluginTest.php b/tests/Unit/Plugin/Task/Checkfiles/Extension/CheckfilesPluginTest.php
index 9030fe7ae7105..1a9cdee19b782 100644
--- a/tests/Unit/Plugin/Task/Checkfiles/Extension/CheckfilesPluginTest.php
+++ b/tests/Unit/Plugin/Task/Checkfiles/Extension/CheckfilesPluginTest.php
@@ -18,6 +18,7 @@
use Joomla\Filesystem\Folder;
use Joomla\Plugin\Task\Checkfiles\Extension\Checkfiles;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for Checkfiles plugin
@@ -25,10 +26,9 @@
* @package Joomla.UnitTest
* @subpackage Checkfiles
*
- * @testdox The Checkfiles plugin
- *
* @since 4.2.0
*/
+#[TestDox('The Checkfiles plugin')]
class CheckfilesPluginTest extends UnitTestCase
{
/**
@@ -76,12 +76,11 @@ public function tearDown(): void
}
/**
- * @testdox can resize an image
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can resize an image')]
public function testResize()
{
$language = $this->createStub(Language::class);
@@ -105,20 +104,19 @@ public function testResize()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
- $this->assertEquals(20, $width);
- $this->assertEquals(20, $height);
+ $this->assertSame(20, $width);
+ $this->assertSame(20, $height);
}
/**
- * @testdox can resize a subset of images
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can resize a subset of images')]
public function testResizeWithLimit()
{
copy($this->tmpFolder . '/test.png', $this->tmpFolder . '/test1.png');
@@ -144,24 +142,23 @@ public function testResizeWithLimit()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
- $this->assertEquals(20, $width);
- $this->assertEquals(20, $height);
+ $this->assertSame(20, $width);
+ $this->assertSame(20, $height);
list($width, $height) = getimagesize($this->tmpFolder . '/test1.png');
- $this->assertEquals(200, $width);
- $this->assertEquals(200, $height);
+ $this->assertSame(200, $width);
+ $this->assertSame(200, $height);
}
/**
- * @testdox can resize an image
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can resize an image')]
public function testIgnoreResize()
{
$language = $this->createStub(Language::class);
@@ -185,20 +182,19 @@ public function testIgnoreResize()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
- $this->assertEquals(200, $width);
- $this->assertEquals(200, $height);
+ $this->assertSame(200, $width);
+ $this->assertSame(200, $height);
}
/**
- * @testdox can not run when invalid folder
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can not run when invalid folder')]
public function testInvalidFolder()
{
$language = $this->createStub(Language::class);
@@ -223,8 +219,8 @@ public function testInvalidFolder()
$plugin->standardRoutineHandler($event);
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
- $this->assertEquals(Status::NO_RUN, $event->getResultSnapshot()['status']);
- $this->assertEquals(200, $width);
- $this->assertEquals(200, $height);
+ $this->assertSame(Status::NO_RUN, $event->getResultSnapshot()['status']);
+ $this->assertSame(200, $width);
+ $this->assertSame(200, $height);
}
}
diff --git a/tests/Unit/Plugin/Task/Requests/Extension/RequestsPluginTest.php b/tests/Unit/Plugin/Task/Requests/Extension/RequestsPluginTest.php
index 614c326930d56..e6ce7e86a1a3b 100644
--- a/tests/Unit/Plugin/Task/Requests/Extension/RequestsPluginTest.php
+++ b/tests/Unit/Plugin/Task/Requests/Extension/RequestsPluginTest.php
@@ -23,6 +23,8 @@
use Joomla\Plugin\Task\Requests\Extension\Requests;
use Joomla\Tests\Unit\UnitTestCase;
use Joomla\Uri\UriInterface;
+use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for Requests plugin
@@ -30,10 +32,9 @@
* @package Joomla.UnitTest
* @subpackage Requests
*
- * @testdox The Requests plugin
- *
* @since 4.2.0
*/
+#[TestDox('The Requests plugin')]
class RequestsPluginTest extends UnitTestCase
{
/**
@@ -77,12 +78,11 @@ public function tearDown(): void
}
/**
- * @testdox can perform a HTTP GET request
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can perform a HTTP GET request')]
public function testRequest()
{
$transport = new class () implements TransportInterface {
@@ -129,19 +129,18 @@ public static function isSupported()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('SAVED', $event->getResultSnapshot()['output']);
- $this->assertEquals('http://example.com', $transport->url);
+ $this->assertSame('http://example.com', $transport->url);
$this->assertStringEqualsFile($this->tmpFolder . '/task_1_response.html', 'test');
}
/**
- * @testdox can perform a HTTP GET request where the return code is not 200
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can perform a HTTP GET request where the return code is not 200')]
public function testInvalidRequest()
{
$transport = new class () implements TransportInterface {
@@ -188,19 +187,18 @@ public static function isSupported()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::KNOCKOUT, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::KNOCKOUT, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('SAVED', $event->getResultSnapshot()['output']);
- $this->assertEquals('http://example.com', $transport->url);
+ $this->assertSame('http://example.com', $transport->url);
$this->assertStringEqualsFile($this->tmpFolder . '/task_1_response.html', 'test');
}
/**
- * @testdox can perform a HTTP GET request with auth headers
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can perform a HTTP GET request with auth headers')]
public function testAuthRequest()
{
$transport = new class () implements TransportInterface {
@@ -247,16 +245,15 @@ public static function isSupported()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(['Authorization' => 'basic 123'], $transport->headers);
+ $this->assertSame(['Authorization' => 'basic 123'], $transport->headers);
}
/**
- * @testdox can handle an exception during the request
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can handle an exception during the request')]
public function testExceptionInRequest()
{
$transport = new class () implements TransportInterface {
@@ -296,15 +293,15 @@ public static function isSupported()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::TIMEOUT, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::TIMEOUT, $event->getResultSnapshot()['status']);
}
/**
- * @testdox can handle an invalid file location
- *
* @return void
*
* @since 4.2.0
*/
+ #[RequiresOperatingSystemFamily('Linux')]
+ #[TestDox('can handle an invalid file location')]
public function testInvalidFileToWrite()
{
$transport = new class () implements TransportInterface {
@@ -347,7 +344,7 @@ public static function isSupported()
);
$plugin->standardRoutineHandler($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('NOT_SAVED', $event->getResultSnapshot()['output']);
}
}
diff --git a/tests/Unit/Plugin/Task/SiteStatus/Extension/SiteStatusPluginTest.php b/tests/Unit/Plugin/Task/SiteStatus/Extension/SiteStatusPluginTest.php
index d972bdfc63470..ed4fff50a2faa 100644
--- a/tests/Unit/Plugin/Task/SiteStatus/Extension/SiteStatusPluginTest.php
+++ b/tests/Unit/Plugin/Task/SiteStatus/Extension/SiteStatusPluginTest.php
@@ -18,6 +18,8 @@
use Joomla\Filesystem\Folder;
use Joomla\Plugin\Task\SiteStatus\Extension\SiteStatus;
use Joomla\Tests\Unit\UnitTestCase;
+use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
+use PHPUnit\Framework\Attributes\TestDox;
/**
* Test class for SiteStatus plugin
@@ -25,10 +27,9 @@
* @package Joomla.UnitTest
* @subpackage SiteStatus
*
- * @testdox The SiteStatus plugin
- *
* @since 4.2.0
*/
+#[TestDox('The SiteStatus plugin')]
class SiteStatusPluginTest extends UnitTestCase
{
/**
@@ -74,12 +75,11 @@ public function tearDown(): void
}
/**
- * @testdox can set the config from online to offline
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can set the config from online to offline')]
public function testSetOnlineWhenOffline()
{
$language = $this->createStub(Language::class);
@@ -97,17 +97,16 @@ public function testSetOnlineWhenOffline()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('$offline = false;', file_get_contents($this->tmpFolder . '/config.php'));
}
/**
- * @testdox can keep the config online
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can keep the config online')]
public function testSetOnlineWhenOnline()
{
$language = $this->createStub(Language::class);
@@ -125,17 +124,16 @@ public function testSetOnlineWhenOnline()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('$offline = false;', file_get_contents($this->tmpFolder . '/config.php'));
}
/**
- * @testdox can set the config from offline to online
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can set the config from offline to online')]
public function testSetOfflineWhenOnline()
{
$language = $this->createStub(Language::class);
@@ -153,17 +151,16 @@ public function testSetOfflineWhenOnline()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('$offline = true;', file_get_contents($this->tmpFolder . '/config.php'));
}
/**
- * @testdox can keep the config offline
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can keep the config offline')]
public function testSetOfflineWhenOffline()
{
$language = $this->createStub(Language::class);
@@ -181,17 +178,16 @@ public function testSetOfflineWhenOffline()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('$offline = true;', file_get_contents($this->tmpFolder . '/config.php'));
}
/**
- * @testdox can toggle the config from online to offline
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can toggle the config from online to offline')]
public function testToggleOffline()
{
$language = $this->createStub(Language::class);
@@ -209,17 +205,16 @@ public function testToggleOffline()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('$offline = true;', file_get_contents($this->tmpFolder . '/config.php'));
}
/**
- * @testdox can toggle the config from offline to online
- *
* @return void
*
* @since 4.2.0
*/
+ #[TestDox('can toggle the config from offline to online')]
public function testToggleOnline()
{
$language = $this->createStub(Language::class);
@@ -237,17 +232,17 @@ public function testToggleOnline()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('$offline = false;', file_get_contents($this->tmpFolder . '/config.php'));
}
/**
- * @testdox can't set the config file'
- *
* @return void
*
* @since 4.2.0
*/
+ #[RequiresOperatingSystemFamily('Linux')]
+ #[TestDox("can't set the config file'")]
public function testInvalidConfigFile()
{
$language = $this->createStub(Language::class);
@@ -265,7 +260,7 @@ public function testInvalidConfigFile()
$event = new ExecuteTaskEvent('test', ['subject' => $task]);
$plugin->alterSiteStatus($event);
- $this->assertEquals(Status::KNOCKOUT, $event->getResultSnapshot()['status']);
+ $this->assertSame(Status::KNOCKOUT, $event->getResultSnapshot()['status']);
$this->assertFileDoesNotExist('/proc/invalid/config.php');
}
}