mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
Merge pull request #136 from creative-commoners/pulls/2.0/phpcs-fix
FIX Add phpcs to dev requirements to fix CI builds
This commit is contained in:
commit
bfaaa42e10
@ -13,7 +13,8 @@
|
||||
"silverstripe/framework": "^4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7"
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^3"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
10
phpcs.xml.dist
Normal file
10
phpcs.xml.dist
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset name="SilverStripe">
|
||||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
||||
|
||||
<!-- base rules are PSR-2 -->
|
||||
<rule ref="PSR2" >
|
||||
<!-- Current exclusions -->
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
||||
</rule>
|
||||
</ruleset>
|
@ -68,7 +68,11 @@ class GoogleSitemapController extends Controller
|
||||
$class = $this->unsanitiseClassName($this->request->param('ID'));
|
||||
$page = $this->request->param('OtherID');
|
||||
|
||||
if (GoogleSitemap::enabled() && $class && $page && ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))) {
|
||||
if (GoogleSitemap::enabled()
|
||||
&& $class
|
||||
&& $page
|
||||
&& ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))
|
||||
) {
|
||||
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
||||
$this->getResponse()->addHeader('X-Robots-Tag', 'noindex');
|
||||
|
||||
@ -78,9 +82,9 @@ class GoogleSitemapController extends Controller
|
||||
return array(
|
||||
'Items' => $items
|
||||
);
|
||||
} else {
|
||||
return new HTTPResponse('Page not found', 404);
|
||||
}
|
||||
|
||||
return new HTTPResponse('Page not found', 404);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,8 +42,9 @@ class GoogleSitemapExtension extends DataExtension
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow override. In this case, since this can return multiple results, we'll use an "and" based policy. That is
|
||||
// if any value is false then the current value will be false. Only only if all are true will we then return true.
|
||||
// Allow override. In this case, since this can return multiple results, we'll use an "and" based policy.
|
||||
// That is if any value is false then the current value will be false. Only only if all are true will we
|
||||
// then return true.
|
||||
$override = $this->owner->invokeWithExtensions('alterCanIncludeInGoogleSitemap', $can);
|
||||
|
||||
if ($override) {
|
||||
|
@ -39,14 +39,26 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
||||
$tabset = $fields->findOrMakeTab('Root.Settings');
|
||||
|
||||
$message = "<p>";
|
||||
$message .= sprintf(_t('GoogleSitemaps.METANOTEPRIORITY', "Manually specify a Google Sitemaps priority for this page (%s)"),
|
||||
'<a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=71936#prioritize" target="_blank">?</a>'
|
||||
$message .= sprintf(
|
||||
_t(
|
||||
'GoogleSitemaps.METANOTEPRIORITY',
|
||||
"Manually specify a Google Sitemaps priority for this page (%s)"
|
||||
),
|
||||
'<a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=71936#prioritize" '
|
||||
. 'target="_blank">?</a>'
|
||||
);
|
||||
$message .= "</p>";
|
||||
|
||||
$tabset->push(new Tab('GoogleSitemap', _t('GoogleSitemaps.TABGOOGLESITEMAP', 'Google Sitemap'),
|
||||
new LiteralField("GoogleSitemapIntro", $message),
|
||||
$priority = new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $prorities, $this->owner->Priority)
|
||||
$tabset->push(new Tab(
|
||||
'GoogleSitemap',
|
||||
_t('GoogleSitemaps.TABGOOGLESITEMAP', 'Google Sitemap'),
|
||||
LiteralField::create("GoogleSitemapIntro", $message),
|
||||
$priority = DropdownField::create(
|
||||
"Priority",
|
||||
$this->owner->fieldLabel('Priority'),
|
||||
$prorities,
|
||||
$this->owner->Priority
|
||||
)
|
||||
));
|
||||
|
||||
$priority->setEmptyString(_t('GoogleSitemaps.PRIORITYAUTOSET', 'Auto-set based on page depth'));
|
||||
|
@ -473,7 +473,9 @@ class GoogleSitemap
|
||||
));
|
||||
|
||||
$googleResponse = self::send_ping(
|
||||
"www.google.com", "/webmasters/sitemaps/ping", sprintf("sitemap=%s", $location)
|
||||
"www.google.com",
|
||||
"/webmasters/sitemaps/ping",
|
||||
sprintf("sitemap=%s", $location)
|
||||
);
|
||||
|
||||
// bing
|
||||
@ -481,7 +483,9 @@ class GoogleSitemap
|
||||
|
||||
if ($bing) {
|
||||
$bingResponse = self::send_ping(
|
||||
"www.bing.com", "/ping", sprintf("sitemap=%s", $location)
|
||||
"www.bing.com",
|
||||
"/ping",
|
||||
sprintf("sitemap=%s", $location)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2,22 +2,21 @@
|
||||
|
||||
namespace Wilr\GoogleSitemaps\Tests;
|
||||
|
||||
use Exception;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\LiteralField;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
||||
use Wilr\GoogleSitemaps\Extensions\GoogleSitemapExtension;
|
||||
use Wilr\GoogleSitemaps\Tests\Model\TestDataObject;
|
||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
||||
use Wilr\GoogleSitemaps\Tests\Model\OtherDataObject;
|
||||
use Wilr\GoogleSitemaps\Tests\Model\TestDataObject;
|
||||
use Wilr\GoogleSitemaps\Tests\Model\UnviewableDataObject;
|
||||
use Exception;
|
||||
|
||||
class GoogleSitemapTest extends FunctionalTest
|
||||
{
|
||||
@ -117,14 +116,32 @@ class GoogleSitemapTest extends FunctionalTest
|
||||
|
||||
// the sitemap should contain <loc> to both those files and not the other
|
||||
// dataobject as it hasn't been registered
|
||||
$expected = "<loc>". Director::absoluteURL("sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1") ."</loc>";
|
||||
$this->assertEquals(1, substr_count($body, $expected), 'A link to GoogleSitemapTest_DataObject exists');
|
||||
$expected = "<loc>". Director::absoluteURL(
|
||||
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1"
|
||||
) ."</loc>";
|
||||
$this->assertEquals(
|
||||
1,
|
||||
substr_count($body, $expected),
|
||||
'A link to GoogleSitemapTest_DataObject exists'
|
||||
);
|
||||
|
||||
$expected = "<loc>". Director::absoluteURL("sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1") ."</loc>";
|
||||
$this->assertEquals(1, substr_count($body, $expected), 'A link to GoogleSitemapTest_OtherDataObject exists');
|
||||
$expected = "<loc>". Director::absoluteURL(
|
||||
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1"
|
||||
) ."</loc>";
|
||||
$this->assertEquals(
|
||||
1,
|
||||
substr_count($body, $expected),
|
||||
'A link to GoogleSitemapTest_OtherDataObject exists'
|
||||
);
|
||||
|
||||
$expected = "<loc>". Director::absoluteURL("sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-UnviewableDataObject/2") ."</loc>";
|
||||
$this->assertEquals(0, substr_count($body, $expected), 'A link to a GoogleSitemapTest_UnviewableDataObject does not exist');
|
||||
$expected = "<loc>". Director::absoluteURL(
|
||||
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-UnviewableDataObject/2"
|
||||
) ."</loc>";
|
||||
$this->assertEquals(
|
||||
0,
|
||||
substr_count($body, $expected),
|
||||
'A link to a GoogleSitemapTest_UnviewableDataObject does not exist'
|
||||
);
|
||||
}
|
||||
|
||||
public function testLastModifiedDateOnRootXML()
|
||||
@ -151,7 +168,11 @@ class GoogleSitemapTest extends FunctionalTest
|
||||
|
||||
$expected = '<lastmod>2014-03-14</lastmod>';
|
||||
|
||||
$this->assertEquals(1, substr_count($body, $expected), 'The last mod date should use most recent LastEdited date');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
substr_count($body, $expected),
|
||||
'The last mod date should use most recent LastEdited date'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIndexFilePaginatedSitemapFiles()
|
||||
@ -162,11 +183,23 @@ class GoogleSitemapTest extends FunctionalTest
|
||||
|
||||
$response = $this->get('sitemap.xml');
|
||||
$body = $response->getBody();
|
||||
$expected = "<loc>". Director::absoluteURL("sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1") ."</loc>";
|
||||
$this->assertEquals(1, substr_count($body, $expected), 'A link to the first page of GoogleSitemapTest_DataObject exists');
|
||||
$expected = "<loc>". Director::absoluteURL(
|
||||
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1"
|
||||
) ."</loc>";
|
||||
$this->assertEquals(
|
||||
1,
|
||||
substr_count($body, $expected),
|
||||
'A link to the first page of GoogleSitemapTest_DataObject exists'
|
||||
);
|
||||
|
||||
$expected = "<loc>". Director::absoluteURL("sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2") ."</loc>";
|
||||
$this->assertEquals(1, substr_count($body, $expected), 'A link to the second page GoogleSitemapTest_DataObject exists');
|
||||
$expected = "<loc>". Director::absoluteURL(
|
||||
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2"
|
||||
) ."</loc>";
|
||||
$this->assertEquals(
|
||||
1,
|
||||
substr_count($body, $expected),
|
||||
'A link to the second page GoogleSitemapTest_DataObject exists'
|
||||
);
|
||||
|
||||
Config::inst()->update(GoogleSitemap::class, 'objects_per_sitemap', $original);
|
||||
}
|
||||
@ -218,7 +251,7 @@ class GoogleSitemapTest extends FunctionalTest
|
||||
$this->assertDOSContains(array(
|
||||
array('Title' => 'Testpage1'),
|
||||
array('Title' => 'Testpage2')
|
||||
), GoogleSitemap::get_items('\SilverStripe\CMS\Model\SiteTree'), "There should be 2 pages in the sitemap after publishing");
|
||||
), GoogleSitemap::inst()->getItems(SiteTree::class), "There should be 2 pages in the sitemap after publishing");
|
||||
|
||||
// check if we make a page readonly that it is hidden
|
||||
$page2->CanViewType = 'LoggedInUsers';
|
||||
@ -229,7 +262,7 @@ class GoogleSitemapTest extends FunctionalTest
|
||||
|
||||
$this->assertDOSEquals(array(
|
||||
array('Title' => 'Testpage1')
|
||||
), GoogleSitemap::get_items('\SilverStripe\CMS\Model\SiteTree'), "There should be only 1 page, other is logged in only");
|
||||
), GoogleSitemap::inst()->getItems(SiteTree::class), "There should be only 1 page, other is logged in only");
|
||||
}
|
||||
|
||||
public function testAccess()
|
||||
|
@ -6,7 +6,6 @@ use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Control\Director;
|
||||
|
||||
|
||||
class TestDataObject extends DataObject implements TestOnly
|
||||
{
|
||||
|
||||
|
@ -55,7 +55,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<p id="Footer" class="expl">Generated by the SilverStripe
|
||||
<a href="https://github.com/silverstripe-labs/silverstripe-googlesitemaps" target="_blank" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
||||
<a href="https://github.com/wilr/silverstripe-googlesitemaps" target="_blank" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
||||
<br />More information about XML sitemaps on <a href="http://sitemaps.org" target="_blank">sitemaps.org</a>.
|
||||
</p>
|
||||
</div>
|
||||
|
@ -47,7 +47,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<p id="Footer" class="expl">Generated by the SilverStripe
|
||||
<a href="https://github.com/silverstripe-labs/silverstripe-googlesitemaps" target="_blank" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
||||
<a href="https://github.com/wilr/silverstripe-googlesitemaps" target="_blank" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
||||
<br />More information about XML sitemaps on <a href="http://sitemaps.org" target="_blank">sitemaps.org</a>.
|
||||
</p>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user