Skip to content

Commit

Permalink
Merge branch '1' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 30, 2023
2 parents df6c6cd + b90f25f commit 54cfdc0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ on:
push:
pull_request:
workflow_dispatch:
# Every Tuesday at 12:10pm UTC
schedule:
- cron: '10 12 * * 2'

jobs:
ci:
name: CI
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
16 changes: 16 additions & 0 deletions .github/workflows/dispatch-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Dispatch CI

on:
# At 12:10 PM UTC, only on Tuesday and Wednesday
schedule:
- cron: '10 12 * * 2,3'

jobs:
dispatch-ci:
name: Dispatch CI
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Dispatch CI
uses: silverstripe/gha-dispatch-ci@v1
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
17 changes: 6 additions & 11 deletions src/ImageManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,23 +1061,15 @@ protected function castDimension($value, $dimension)
*/
private function copyImageBackend(): AssetContainer
{
// Store result in new DBFile instance
/** @var DBFile $file */
$file = DBField::create_field(
'DBFile',
[
'Filename' => $this->getFilename(),
'Hash' => $this->getHash(),
'Variant' => $this->getVariant()
]
);
$file = clone $this;

$backend = $this->getImageBackend();
if ($backend) {
$file->setImageBackend($backend);
}

return $file->setOriginal($this);
$file->File->setOriginal($this);
return $file;
}

/**
Expand All @@ -1096,6 +1088,9 @@ public function setAttribute($name, $value)
[$name => $value]
));

// If this file has already been rendered then AttributesHTML will be cached, so we have to clear the cache
$file->objCacheClear();

return $file;
}

Expand Down
28 changes: 24 additions & 4 deletions tests/php/ImageManipulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

namespace SilverStripe\Assets\Tests;

use InvalidArgumentException;
use Prophecy\Prophecy\ObjectProphecy;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Image_Backend;
use SilverStripe\Assets\InterventionBackend;
use SilverStripe\Assets\Storage\AssetContainer;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Storage\DBFile;
use SilverStripe\Assets\Tests\ImageManipulationTest\LazyLoadAccessorExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\SSViewer;
Expand Down Expand Up @@ -362,6 +359,29 @@ public function testBadLazyLoad($val)
);
}

public function testLazyLoadIsAccessibleInExtensions()
{
Image::add_extension(LazyLoadAccessorExtension::class);

/** @var Image $origin */
$image = $this->objFromFixture(Image::class, 'imageWithTitle');

$this->assertTrue(
$image->LazyLoad(true)->getLazyLoadValueViaExtension(),
'Incorrect LazyLoad value reported by extension'
);
$this->assertFalse(
$image->LazyLoad(false)->getLazyLoadValueViaExtension(),
'Incorrect LazyLoad value reported by extension'
);
$this->assertTrue(
$image->LazyLoad(false)->LazyLoad(true)->getLazyLoadValueViaExtension(),
'Incorrect LazyLoad value reported by extension'
);

Image::remove_extension(LazyLoadAccessorExtension::class);
}

public function renderProvider()
{
$alt = 'This is a image Title';
Expand Down
13 changes: 13 additions & 0 deletions tests/php/ImageManipulationTest/LazyLoadAccessorExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace SilverStripe\Assets\Tests\ImageManipulationTest;

use SilverStripe\Core\Extension;

class LazyLoadAccessorExtension extends Extension
{
public function getLazyLoadValueViaExtension(): bool
{
return $this->getOwner()->IsLazyLoaded();
}
}

0 comments on commit 54cfdc0

Please sign in to comment.