-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Added dg/bypass-finals dev requirement to test final classe…
…s, added more tests, fixed wrong doktype for backend_section
- Loading branch information
Showing
12 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YoastSeoForTypo3\YoastSeo\Tests\Functional; | ||
|
||
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; | ||
use TYPO3\CMS\Core\Http\ServerRequest; | ||
use TYPO3\CMS\Core\Http\Uri; | ||
use TYPO3\CMS\Core\Localization\LanguageServiceFactory; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
abstract class AbstractFunctionalTestCase extends FunctionalTestCase | ||
{ | ||
protected array $testExtensionsToLoad = [ | ||
'typo3conf/ext/yoast_seo', | ||
]; | ||
|
||
protected array $coreExtensionsToLoad = [ | ||
'seo', | ||
]; | ||
|
||
protected function setUpBackendRequest(): void | ||
{ | ||
$GLOBALS['LANG'] = $this->getContainer()->get(LanguageServiceFactory::class)->create('default'); | ||
|
||
$request = new ServerRequest(); | ||
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); | ||
$GLOBALS['TYPO3_REQUEST'] = $request->withUri(new Uri('http://localhost/')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YoastSeoForTypo3\YoastSeo\Tests\Functional\Backend; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use TYPO3\CMS\Backend\Controller\PageLayoutController; | ||
use YoastSeoForTypo3\YoastSeo\Backend\PageLayoutHeader; | ||
use YoastSeoForTypo3\YoastSeo\Tests\Functional\AbstractFunctionalTestCase; | ||
|
||
#[CoversClass(PageLayoutHeader::class)] | ||
class PageLayoutHeaderTest extends AbstractFunctionalTestCase | ||
{ | ||
protected PageLayoutHeader $pageLayoutHeader; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv'); | ||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv'); | ||
$this->setUpBackendUser(1); | ||
$this->setUpBackendRequest(); | ||
|
||
$this->pageLayoutHeader = $this->getContainer()->get(PageLayoutHeader::class); | ||
} | ||
|
||
#[Test] | ||
public function testRenderReturnsEmptyStringWhenNoPageExists(): void | ||
{ | ||
$_GET['id'] = '99999'; // page does not exist in the fixture | ||
$result = $this->pageLayoutHeader->render(null, $this->getContainer()->get(PageLayoutController::class)); | ||
$this->assertSame('', $result); | ||
} | ||
|
||
#[Test] | ||
public function testRenderReturnsOutputForExistingPage(): void | ||
{ | ||
$_GET['id'] = '1'; // page exists in the fixture | ||
$result = $this->pageLayoutHeader->render(null, $this->getContainer()->get(PageLayoutController::class)); | ||
$this->assertNotEmpty($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"pages" | ||
,"uid","pid","title","doktype" | ||
,1,0,"Home",1 | ||
,2,1,"Page 1",1 | ||
,3,1,"Page 2 with invalid doktype",10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YoastSeoForTypo3\YoastSeo\Tests\Unit\EventListener; | ||
|
||
use DG\BypassFinals; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; | ||
use TYPO3\CMS\Seo\Event\ModifyUrlForCanonicalTagEvent; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
use YoastSeoForTypo3\YoastSeo\EventListener\RecordCanonicalListener; | ||
use YoastSeoForTypo3\YoastSeo\Record\Record; | ||
use YoastSeoForTypo3\YoastSeo\Record\RecordService; | ||
|
||
#[CoversClass(RecordCanonicalListener::class)] | ||
class RecordCanonicalListenerTest extends UnitTestCase | ||
{ | ||
protected RecordService $recordService; | ||
protected RecordCanonicalListener $subject; | ||
|
||
protected function setUp(): void | ||
{ | ||
BypassFinals::enable(); | ||
parent::setUp(); | ||
|
||
$this->recordService = $this->createMock(RecordService::class); | ||
$this->subject = new RecordCanonicalListener($this->recordService); | ||
} | ||
|
||
#[Test] | ||
public function testSetCanonicalWithNoActiveRecord(): void | ||
{ | ||
$event = $this->createMock(ModifyUrlForCanonicalTagEvent::class); | ||
$this->recordService->method('getActiveRecord')->willReturn(null); | ||
|
||
$event->expects($this->never())->method('setUrl'); | ||
|
||
$this->subject->setCanonical($event); | ||
} | ||
|
||
#[Test] | ||
public function testSetCanonicalWithNoCanonicalLink(): void | ||
{ | ||
$event = $this->createMock(ModifyUrlForCanonicalTagEvent::class); | ||
$record = $this->createMock(Record::class); | ||
$record->method('getRecordData')->willReturn([]); | ||
|
||
$this->recordService->method('getActiveRecord')->willReturn($record); | ||
|
||
$event->expects($this->never())->method('setUrl'); | ||
|
||
$this->subject->setCanonical($event); | ||
} | ||
|
||
#[Test] | ||
public function testSetCanonicalWithCanonicalLink(): void | ||
{ | ||
$event = $this->createMock(ModifyUrlForCanonicalTagEvent::class); | ||
$record = $this->createMock(Record::class); | ||
$record->method('getRecordData')->willReturn(['canonical_link' => 'https://example.com']); | ||
|
||
$this->recordService->method('getActiveRecord')->willReturn($record); | ||
|
||
$GLOBALS['TSFE'] = $this->createMock(\stdClass::class); | ||
$GLOBALS['TSFE']->cObj = $this->createMock(ContentObjectRenderer::class); | ||
$GLOBALS['TSFE']->cObj->method('typoLink_URL')->willReturn('https://example.com'); | ||
|
||
$event->expects($this->once())->method('setUrl')->with('https://example.com'); | ||
|
||
$this->subject->setCanonical($event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters