Skip to content

Commit

Permalink
Merge pull request #33 from loadsys/f/xml-sitemap
Browse files Browse the repository at this point in the history
f/xml-sitemap
  • Loading branch information
justinyost committed May 27, 2016
2 parents b342f82 + 6e516b3 commit 8157192
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions config/routes.php
Expand Up @@ -5,6 +5,7 @@
'Sitemap',
['path' => '/sitemap'],
function ($routes) {
$routes->extensions(['xml']);
$routes->fallbacks('DashedRoute');
}
);
4 changes: 2 additions & 2 deletions src/Controller/AppController.php
Expand Up @@ -4,10 +4,10 @@
*/
namespace Sitemap\Controller;

use Cake\Controller\Controller;
use App\Controller\AppController as BaseController;

/**
* \Sitemap\Controller\AppController
*/
class AppController extends Controller {
class AppController extends BaseController {
}
5 changes: 4 additions & 1 deletion src/Model/Behavior/SitemapBehavior.php
Expand Up @@ -4,6 +4,7 @@
*/
namespace Sitemap\Model\Behavior;

use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Behavior;
use Cake\ORM\Entity;
use Cake\ORM\Query;
Expand Down Expand Up @@ -68,6 +69,8 @@ public function initialize(array $config) {
public function returnUrlForEntity(Entity $entity) {
return Router::url(
[
'plugin' => null,
'prefix' => null,
'controller' => $this->_table->registryAlias(),
'action' => 'view',
$entity->{$this->_table->primaryKey()},
Expand Down Expand Up @@ -108,7 +111,7 @@ public function findSitemapRecords(Query $query, array $options) {
* @return \Cake\Collection\CollectionInterface Returns the modified collection
* of Results.
*/
public function mapResults(\Cake\Datasource\ResultSetInterface $results) {
public function mapResults(ResultSetInterface $results) {
return $results->map(function ($entity) {
return $this->mapEntity($entity);
});
Expand Down
8 changes: 4 additions & 4 deletions src/Template/Sitemaps/index.ctp
Expand Up @@ -25,16 +25,16 @@
<?php foreach($dataForKey as $record): ?>
<tr>
<td>
<?= h($record->_loc); ?>
<?= h($record->_loc) ?>
</td>
<td>
<?= h($record->_priority); ?>
<?= h($record->_priority) ?>
</td>
<td>
<?= h($record->_changefreq); ?>
<?= h($record->_changefreq) ?>
</td>
<td>
<?= h($record->_lastmod); ?>
<?= h($record->_lastmod) ?>
</td>
</tr>
<?php endforeach; ?>
Expand Down
22 changes: 22 additions & 0 deletions src/Template/Sitemaps/xml/index.ctp
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach($data as $key => $dataForKey): ?>
<!-- <?= __($key) ?> -->
<?php foreach($dataForKey as $record): ?>
<url>
<loc>
<?= h($record->_loc) ?>
</loc>
<lastmod>
<?= h($record->_lastmod) ?>
</lastmod>
<changefreq>
<?= h($record->_changefreq) ?>
</changefreq>
<priority>
<?= h($record->_priority) ?>
</priority>
</url>
<?php endforeach; ?>
<?php endforeach; ?>
</urlset>
3 changes: 2 additions & 1 deletion tests/TestCase/Controller/SitemapsControllerTest.php
Expand Up @@ -4,6 +4,7 @@
*/
namespace Sitemap\Test\TestCase\Controller;

use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestCase;
use Sitemap\Controller\SitemapsController;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testIndexNoModels() {
* @covers \Sitemap\Controller\SitemapsController::index
*/
public function testIndexWithModels() {
\Cake\Core\Configure::write('Sitemap.tables', ['Pages']);
Configure::write('Sitemap.tables', ['Pages']);
$pagesFindQuery = $this->Pages->find('forSitemap');

$Controller = $this->getMock(
Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/Model/Behavior/SitemapBehaviorTest.php
Expand Up @@ -5,6 +5,7 @@
namespace Sitemap\Test\TestCase\Model\Behavior;

use Cake\Datasource\ConnectionManager;
use Cake\I18n\Time;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
Expand Down Expand Up @@ -209,7 +210,7 @@ public function testMapEntity() {
);

$this->assertEquals(
new \Cake\I18n\Time('2015-10-08 21:27:04'),
new Time('2015-10-08 21:27:04'),
$entity->_lastmod,
'The _loc field should be set to our standard url'
);
Expand Down Expand Up @@ -243,7 +244,7 @@ public function testMapEntity() {
);

$this->assertEquals(
new \Cake\I18n\Time('2015-10-08 21:27:04'),
new Time('2015-10-08 21:27:04'),
$entity->_lastmod,
'The _loc field should be set to our standard url'
);
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -73,3 +73,5 @@
'quoteIdentifiers' => true,
'cacheMetadata' => true,
]);

class_alias('Cake\Controller\Controller', 'App\Controller\AppController');

0 comments on commit 8157192

Please sign in to comment.