2009-10-16 00:40:06 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests link tracking to files and images.
|
|
|
|
*/
|
|
|
|
class FileLinkTrackingTest extends SapphireTest {
|
|
|
|
static $fixture_file = "sapphire/tests/FileLinkTrackingTest.yml";
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2010-02-21 22:35:06 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2010-06-29 06:59:48 +02:00
|
|
|
|
|
|
|
$fh = fopen(Director::baseFolder() . '/assets/testscript-test-file.pdf', "w");
|
|
|
|
fwrite($fh, str_repeat('x',1000000));
|
|
|
|
fclose($fh);
|
2009-10-16 00:40:06 +02:00
|
|
|
}
|
|
|
|
function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
$testFiles = array(
|
|
|
|
'/assets/testscript-test-file.pdf',
|
|
|
|
'/assets/renamed-test-file.pdf',
|
2010-01-13 00:34:26 +01:00
|
|
|
'/assets/renamed-test-file-second-time.pdf',
|
2009-10-16 00:40:06 +02:00
|
|
|
);
|
|
|
|
foreach($testFiles as $file) {
|
|
|
|
if(file_exists(Director::baseFolder().$file)) unlink(Director::baseFolder().$file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFileRenameUpdatesDraftAndPublishedPages() {
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$this->assertTrue($page->doPublish());
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/testscript-test-file.pdf"',
|
2009-10-16 00:40:06 +02:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
|
|
|
|
|
|
|
|
$file = $this->objFromFixture('File', 'file1');
|
|
|
|
$file->Name = 'renamed-test-file.pdf';
|
|
|
|
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
2009-10-16 00:40:06 +02:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
2010-01-13 00:34:26 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
|
2009-10-16 00:40:06 +02:00
|
|
|
}
|
2010-01-12 23:56:51 +01:00
|
|
|
|
|
|
|
function testFileLinkRewritingOnVirtualPages() {
|
|
|
|
// Publish the source page
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$this->assertTrue($page->doPublish());
|
|
|
|
|
|
|
|
// Create a virtual page from it, and publish that
|
|
|
|
$svp = new VirtualPage();
|
|
|
|
$svp->CopyContentFromID = $page->ID;
|
|
|
|
$svp->write();
|
|
|
|
$svp->doPublish();
|
|
|
|
|
|
|
|
// Rename the file
|
|
|
|
$file = $this->objFromFixture('File', 'file1');
|
|
|
|
$file->Name = 'renamed-test-file.pdf';
|
|
|
|
|
|
|
|
// Verify that the draft and publish virtual pages both have the corrected link
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
2010-01-12 23:56:51 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value());
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
2010-01-12 23:56:51 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $svp->ID")->value());
|
2010-01-13 00:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testLinkRewritingOnAPublishedPageDoesntMakeItEditedOnDraft() {
|
|
|
|
// Publish the source page
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$this->assertTrue($page->doPublish());
|
|
|
|
$this->assertFalse($page->IsModifiedOnStage);
|
|
|
|
|
|
|
|
// Rename the file
|
|
|
|
$file = $this->objFromFixture('File', 'file1');
|
|
|
|
$file->Name = 'renamed-test-file.pdf';
|
|
|
|
|
|
|
|
// Caching hack
|
|
|
|
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Stage', array($page->ID));
|
|
|
|
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Live', array($page->ID));
|
|
|
|
|
|
|
|
// Confirm that the page hasn't gone green.
|
|
|
|
$this->assertFalse($page->IsModifiedOnStage);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoFileRenamesInARowWork() {
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$this->assertTrue($page->doPublish());
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/testscript-test-file.pdf"',
|
2010-01-13 00:34:26 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
|
|
|
|
|
|
|
|
// Rename the file twice
|
|
|
|
$file = $this->objFromFixture('File', 'file1');
|
|
|
|
$file->Name = 'renamed-test-file.pdf';
|
|
|
|
$file->write();
|
|
|
|
|
|
|
|
$file->Name = 'renamed-test-file-second-time.pdf';
|
|
|
|
$file->write();
|
|
|
|
|
|
|
|
// Confirm that the correct image is shown in both the draft and live site
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file-second-time.pdf"',
|
2010-01-13 00:34:26 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
|
2010-03-16 04:50:37 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file-second-time.pdf"',
|
2010-01-13 00:34:26 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
|
|
|
|
}
|
2009-10-16 00:40:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|