Source of file SwiftypeMetaTagRobotsTest.php
Size: 4,239 Bytes - Last Modified: 2021-12-24T05:17:12+00:00
/var/www/docs.ssmods.com/process/src/tests/php/MetaTags/SwiftypeMetaTagRobotsTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 | <?php namespace Ichaber\SSSwiftype\Tests\Extensions; use Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagRobots; use Ichaber\SSSwiftype\Tests\Fake\SwiftypeSiteTree; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; /** * Class SwiftypeMetaTagRobotsTest * * @package Ichaber\SSSwiftype\Tests\MetaTags */ class SwiftypeMetaTagRobotsTest extends SapphireTest { /** * @var string */ protected static $fixture_file = 'SwiftypeMetaTagTest.yml'; public function testRobotsTagNoIndex(): void { Config::inst()->update( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ SwiftypeMetaTagRobots::class, ] ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_index', true ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_follow', false ); /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page2'); // Quickly render an expected mock $mock = '<meta name="robots" content="noindex">'; $mock = trim(preg_replace("/\s+/S", '', $mock)); // Remove formatting from output output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); } public function testRobotsTagNoFollow(): void { Config::inst()->update( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ SwiftypeMetaTagRobots::class, ] ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_index', false ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_follow', true ); /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page2'); // Quickly render an expected mock $mock = '<meta name="robots" content="nofollow">'; $mock = trim(preg_replace("/\s+/S", '', $mock)); // Remove formatting from output output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); } public function testRobotsTagBoth(): void { Config::inst()->update( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ SwiftypeMetaTagRobots::class, ] ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_index', true ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_follow', true ); /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page2'); // Quickly render an expected mock $mock = '<meta name="robots" content="noindex, nofollow">'; $mock = trim(preg_replace("/\s+/S", '', $mock)); // Remove formatting from output output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); } public function testRobotsTagNone(): void { Config::inst()->update( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ SwiftypeMetaTagRobots::class, ] ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_index', false ); Config::inst()->update( SwiftypeMetaTagRobots::class, 'no_follow', false ); /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page2'); // Remove formatting from output output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals('', $output); } } |