2011-03-18 04:23:47 +01:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Model;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2017-06-21 06:29:40 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Control\Director;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\Control\HTTP;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2019-07-16 05:16:09 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2016-01-26 06:38:42 +01:00
|
|
|
/**
|
|
|
|
* Tests {@see SiteTreeLinkTracking} broken links feature: LinkTracking
|
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
class SiteTreeBacklinksTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = "SiteTreeBacklinksTest.yml";
|
|
|
|
|
2017-06-21 06:29:40 +02:00
|
|
|
protected static $required_extensions = [
|
|
|
|
SiteTree::class => [
|
2018-05-04 03:04:18 +02:00
|
|
|
SiteTreeBacklinksTest_DOD::class,
|
2017-06-21 06:29:40 +02:00
|
|
|
],
|
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2019-07-16 05:16:09 +02:00
|
|
|
protected static $extra_dataobjects = [
|
|
|
|
SiteTreeBacklinksTestContentObject::class,
|
|
|
|
];
|
|
|
|
|
2021-10-27 23:40:52 +02:00
|
|
|
protected function setUp(): void
|
2017-01-25 21:59:25 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Log in as admin so that we don't run into permission issues. That's not what we're
|
|
|
|
// testing here.
|
|
|
|
$this->logInWithPermission('ADMIN');
|
2019-07-16 05:16:09 +02:00
|
|
|
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2019-07-16 05:16:09 +02:00
|
|
|
$page3->Content = str_replace(
|
|
|
|
'$page1.ID',
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->objFromFixture(SiteTree::class, 'page1')->ID ?? '',
|
2022-04-13 07:07:59 +02:00
|
|
|
$page3->Content ?? ''
|
2019-07-16 05:16:09 +02:00
|
|
|
);
|
|
|
|
$page3->write();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSavingPageWithLinkAddsBacklink()
|
|
|
|
{
|
|
|
|
// load page 1
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert backlink to page 2 doesn't exist
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2 = $this->objFromFixture(SiteTree::class, 'page2');
|
|
|
|
$this->assertNotContains(
|
|
|
|
$page2->ID,
|
|
|
|
$page1->BackLinkTracking()->column('ID'),
|
|
|
|
'Assert backlink to page 2 doesn\'t exist'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// add hyperlink to page 1 on page 2
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2->Content .= '<p><a href="[sitetree_link,id=' . $page1->ID . ']">Testing page 1 link</a></p>';
|
2017-01-25 21:59:25 +01:00
|
|
|
$page2->write();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// load page 1
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert backlink to page 2 exists
|
|
|
|
$this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 exists');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRemovingLinkFromPageRemovesBacklink()
|
|
|
|
{
|
|
|
|
// load page 1
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert backlink to page 3 exits
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->assertContains($page3->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 exists');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// remove hyperlink to page 1
|
|
|
|
$page3->Content = '<p>No links anymore!</p>';
|
|
|
|
$page3->write();
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// load page 1
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert backlink to page 3 exists
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertNotContains(
|
|
|
|
$page3->ID,
|
|
|
|
$page1->BackLinkTracking()->column('ID'),
|
|
|
|
'Assert backlink to page 3 doesn\'t exist'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testChangingUrlOnDraftSiteRewritesLink()
|
|
|
|
{
|
|
|
|
// load page 1
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert backlink to page 3 exists
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->assertContains($page3->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 exists');
|
|
|
|
|
|
|
|
// assert hyperlink to page 1's current url exists on page 3
|
|
|
|
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'page1',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// change url of page 1
|
|
|
|
$page1->URLSegment = 'new-url-segment';
|
|
|
|
$page1->write();
|
2016-01-26 06:38:42 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// load page 3
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert hyperlink to page 1's new url exists
|
|
|
|
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'new-url-segment',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s new url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function testChangingUrlOnLiveSiteRewritesLink()
|
|
|
|
{
|
|
|
|
// publish page 1 & 3
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->assertTrue($page1->publishRecursive());
|
|
|
|
$this->assertTrue($page3->publishRecursive());
|
|
|
|
|
|
|
|
// load pages from live
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page1->ID);
|
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert backlink to page 3 exists
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
|
|
|
$page3live->ID,
|
|
|
|
$page1live->BackLinkTracking()->column('ID'),
|
|
|
|
'Assert backlink to page 3 exists'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert hyperlink to page 1's current url exists on page 3
|
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'page1',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// change url of page 1
|
|
|
|
$page1live->URLSegment = 'new-url-segment';
|
|
|
|
$page1live->writeToStage('Live');
|
|
|
|
|
|
|
|
// load page 3 from live
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert hyperlink to page 1's new url exists
|
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'new-url-segment',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s new url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPublishingPageWithModifiedUrlRewritesLink()
|
|
|
|
{
|
|
|
|
// publish page 1 & 3
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$this->assertTrue($page1->publishRecursive());
|
|
|
|
$this->assertTrue($page3->publishRecursive());
|
|
|
|
|
|
|
|
// load page 3 from live
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// assert hyperlink to page 1's current url exists
|
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'page1',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// rename url of page 1 on stage
|
|
|
|
$page1->URLSegment = 'new-url-segment';
|
|
|
|
$page1->write();
|
|
|
|
|
|
|
|
// assert hyperlink to page 1's current publish url exists
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'page1',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current published url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
// publish page 1
|
|
|
|
$this->assertTrue($page1->publishRecursive());
|
|
|
|
|
|
|
|
// assert hyperlink to page 1's new published url exists
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'new-url-segment',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s new published url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPublishingPageWithModifiedLinksRewritesLinks()
|
|
|
|
{
|
|
|
|
// publish page 1 & 3
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->assertTrue($page1->publishRecursive());
|
|
|
|
$this->assertTrue($page3->publishRecursive());
|
|
|
|
|
|
|
|
// assert hyperlink to page 1's current url exists
|
|
|
|
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'page1',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current published url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// change page 1 url on draft
|
|
|
|
$page1->URLSegment = 'new-url-segment';
|
|
|
|
|
|
|
|
// save page 1
|
|
|
|
$page1->write();
|
|
|
|
|
|
|
|
// assert page 3 on draft contains new page 1 url
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3 = $this->objFromFixture(SiteTree::class, 'page3');
|
2017-01-25 21:59:25 +01:00
|
|
|
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'new-url-segment',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current draft url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// publish page 3
|
|
|
|
$this->assertTrue($page3->publishRecursive());
|
|
|
|
|
|
|
|
// assert page 3 on published site contains old page 1 url
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'page1',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current published url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// publish page 1
|
|
|
|
$this->assertTrue($page1->publishRecursive());
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// assert page 3 on published site contains new page 1 url
|
2018-05-04 03:04:18 +02:00
|
|
|
$page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertContains(
|
2022-08-26 08:34:14 +02:00
|
|
|
Director::baseURL() . 'new-url-segment',
|
2018-05-04 03:04:18 +02:00
|
|
|
$links,
|
|
|
|
'Assert hyperlink to page 1\'s current published url exists on page 3'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkTrackingOnExtraContentFields()
|
|
|
|
{
|
2018-05-04 03:04:18 +02:00
|
|
|
/** @var SiteTree $page1 */
|
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
|
|
|
/** @var SiteTree $page2 */
|
|
|
|
$page2 = $this->objFromFixture(SiteTree::class, 'page2');
|
2017-01-25 21:59:25 +01:00
|
|
|
$page1->publishRecursive();
|
|
|
|
$page2->publishRecursive();
|
|
|
|
|
|
|
|
// assert backlink to page 2 doesn't exist
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertNotContains(
|
|
|
|
$page2->ID,
|
|
|
|
$page1->BackLinkTracking()->column('ID'),
|
|
|
|
'Assert backlink to page 2 doesn\'t exist'
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// add hyperlink to page 1 on page 2
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2->ExtraContent .= '<p><a href="[sitetree_link,id=' . $page1->ID . ']">Testing page 1 link</a></p>';
|
2017-01-25 21:59:25 +01:00
|
|
|
$page2->write();
|
|
|
|
$page2->publishRecursive();
|
|
|
|
|
|
|
|
// assert backlink to page 2 exists
|
|
|
|
$this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 exists');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// update page1 url
|
2018-05-04 03:04:18 +02:00
|
|
|
$page1 = $this->objFromFixture(SiteTree::class, 'page1');
|
2017-01-25 21:59:25 +01:00
|
|
|
$page1->URLSegment = "page1-new-url";
|
|
|
|
$page1->write();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// confirm that draft link on page2 has been rewritten
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2 = $this->objFromFixture(SiteTree::class, 'page2');
|
|
|
|
$this->assertEquals(
|
2022-08-26 08:34:14 +02:00
|
|
|
'<p><a href="' . Director::baseURL() . 'page1-new-url">Testing page 1 link</a></p>',
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2->obj('ExtraContent')->forTemplate()
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// confirm that published link hasn't
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2Live = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $page2->ID");
|
2017-01-25 21:59:25 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertEquals(
|
2022-08-26 08:34:14 +02:00
|
|
|
'<p><a href="' . Director::baseURL() . 'page1">Testing page 1 link</a></p>',
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2Live->obj('ExtraContent')->forTemplate()
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// publish page1 and confirm that the link on the published page2 has now been updated
|
|
|
|
$page1->publishRecursive();
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2Live = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $page2->ID");
|
|
|
|
$this->assertEquals(
|
2022-08-26 08:34:14 +02:00
|
|
|
'<p><a href="' . Director::baseURL() . 'page1-new-url">Testing page 1 link</a></p>',
|
2018-05-04 03:04:18 +02:00
|
|
|
$page2Live->obj('ExtraContent')->forTemplate()
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2017-06-21 06:29:40 +02:00
|
|
|
// Edit draft again
|
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2017-01-25 21:59:25 +01:00
|
|
|
$page2->ExtraContent = '<p>No links anymore!</p>';
|
|
|
|
$page2->write();
|
|
|
|
|
|
|
|
// assert backlink to page 2 no longer exists
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertNotContains(
|
|
|
|
$page2->ID,
|
|
|
|
$page1->BackLinkTracking()->column('ID'),
|
|
|
|
'Assert backlink to page 2 has been removed'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2019-07-16 05:16:09 +02:00
|
|
|
|
|
|
|
public function testLinkTrackingWithUntitledObjectsDisplaysAReadableIdentifier()
|
|
|
|
{
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = $this->objFromFixture(SiteTree::class, 'page2');
|
2019-07-16 05:16:09 +02:00
|
|
|
|
|
|
|
$referencingObject = new SiteTreeBacklinksTestContentObject();
|
|
|
|
$referencingObject->Content = '<p><a href="[sitetree_link,id='
|
|
|
|
. $page->ID
|
|
|
|
. ']">Page 2</a></p>';
|
|
|
|
// Title purposely not set - this is the coverage case for this test
|
|
|
|
$referencingObject->write();
|
|
|
|
|
|
|
|
/** @var GridField $gridField */
|
|
|
|
$gridField = $page->getCMSFields()->dataFieldByName('DependentPages');
|
|
|
|
|
|
|
|
// Prepare and sanity check
|
|
|
|
$this->assertNotNull($gridField);
|
|
|
|
$list = $gridField->getList();
|
|
|
|
$this->assertEquals(1, $list->count());
|
|
|
|
|
|
|
|
$content = $gridField->getColumnContent($list->first(), 'Title');
|
|
|
|
|
2021-10-27 23:40:52 +02:00
|
|
|
$this->assertStringContainsString('Untitled Backlink test content object', $content);
|
2019-07-16 05:16:09 +02:00
|
|
|
}
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|