-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7103246
commit 2ba37a1
Showing
2 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* BEdita Brevia plugin | ||
* | ||
* Copyright 2023 Atlas Srl | ||
*/ | ||
namespace Brevia\BEdita\Test\TestCase\Command; | ||
|
||
use BEdita\Core\Model\Entity\ObjectEntity; | ||
use Brevia\BEdita\Test\TestMockTrait; | ||
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; | ||
use Cake\Routing\Router; | ||
use Cake\TestSuite\TestCase; | ||
|
||
/** | ||
* {@see \Brevia\BEdita\Command\ImportSitemapCommand} Test Case | ||
* | ||
* @coversDefaultClass \Brevia\BEdita\Command\ImportSitemapCommand | ||
*/ | ||
class ImportSitemapCommandTest extends TestCase | ||
{ | ||
use ConsoleIntegrationTestTrait; | ||
use TestMockTrait; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->useCommandRunner(); | ||
Router::reload(); | ||
} | ||
|
||
/** | ||
* Test buildOptionParser method | ||
* | ||
* @return void | ||
* @covers ::buildOptionParser() | ||
*/ | ||
public function testBuildOptionParser(): void | ||
{ | ||
$this->exec('import_sitemap --help'); | ||
$this->assertOutputContains('File path or URL of sitemap to import'); | ||
$this->assertOutputContains('Optional path prefix of URLs to import'); | ||
$this->assertOutputContains('Collection used to index'); | ||
} | ||
|
||
/** | ||
* Test options failure | ||
* | ||
* @return void | ||
* @covers ::initialize() | ||
* @covers ::execute() | ||
*/ | ||
public function testOptionFailure(): void | ||
{ | ||
$this->exec('import_sitemap --sitemap /not/existing/path --collection gustavo'); | ||
$this->assertExitError('File not found: /not/existing/path'); | ||
|
||
$this->mockClientResponse(json_encode([])); | ||
$xmlPath = sprintf('%s/tests/files/sitemap.xml', getcwd()); | ||
$this->exec(sprintf('import_sitemap --sitemap %s --collection gustavo', $xmlPath)); | ||
$this->assertExitError('Collection not found: gustavo'); | ||
|
||
$this->mockClientResponse('[{"cmetadata": {"id":"1"}}]'); | ||
$this->mockTable('Collections', new ObjectEntity()); | ||
$xmlPath = sprintf('%s/tests/files/empty.csv', getcwd()); | ||
$this->exec(sprintf('import_sitemap --sitemap %s --collection gustavo', $xmlPath)); | ||
$this->assertExitError('No URLs found in sitemap'); | ||
|
||
} | ||
|
||
/** | ||
* Test command success | ||
* | ||
* @return void | ||
* @covers ::execute() | ||
*/ | ||
public function testCommand(): void | ||
{ | ||
$this->mockTable('Collections', new ObjectEntity()); | ||
$this->mockTable('Links', new ObjectEntity()); | ||
$this->mockClientResponse('[{"cmetadata": {"id":"1"}}]', 200, 3); | ||
$xmlPath = sprintf('%s/tests/files/sitemap.xml', getcwd()); | ||
$this->exec(sprintf('import_sitemap --sitemap %s --collection gustavo', $xmlPath)); | ||
$this->assertExitSuccess('Done'); | ||
} | ||
} |
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,14 @@ | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> | ||
<url> | ||
<loc>https://example.com/home</loc> | ||
<lastmod>2024-04-28T08:02:38+00:00</lastmod> | ||
<changefreq>always</changefreq> | ||
<priority>1.0</priority> | ||
</url> | ||
<url> | ||
<loc>https://example.com/page2</loc> | ||
<lastmod>2024-04-28T08:02:38+00:00</lastmod> | ||
<changefreq>always</changefreq> | ||
<priority>1.0</priority> | ||
</url> | ||
</urlset> |