Skip to content

Commit

Permalink
Fix linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Anthony Adriano committed May 18, 2022
1 parent 7a55f29 commit 4a414c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/Extensions/Subsites/IndexConfigurationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ class IndexConfigurationExtension extends Extension
public function updateIndexesForDocument(DocumentInterface $doc, array &$indexes): void
{
$docSubsiteId = null;
/** @var DataObject $doc */
$dataObj = $doc->getDataObject();

if ($doc instanceof DataObjectDocument) {
$docSubsiteId = $dataObj->SubsiteID ?? null;
}


if ($docSubsiteId === null) {
// DataObject does not have a defined SubsiteID
// So if the developer explicitly defined the dataObject to be
// included in the Subsite Index configuration then
// allow the dataObject to be added in.
foreach ($indexes as $indexName => $data) {

// DataObject explicitly defined on Subsite index definition
$explicitClasses = $data['includeClasses'] ?? [];
if (!isset($explicitClasses[$dataObj->ClassName])) {
Expand Down
25 changes: 18 additions & 7 deletions tests/DataObject/DataObjectDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

namespace SilverStripe\SearchService\Tests\DataObject;

use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\RelationList;
use SilverStripe\SearchService\DataObject\DataObjectDocument;
use SilverStripe\SearchService\Exception\IndexConfigurationException;
use SilverStripe\SearchService\Extensions\SearchServiceExtension;
use SilverStripe\SearchService\Interfaces\DocumentAddHandler;
use SilverStripe\SearchService\Interfaces\DocumentRemoveHandler;
use SilverStripe\SearchService\Schema\Field;
use SilverStripe\SearchService\Service\IndexConfiguration;
use SilverStripe\SearchService\Tests\Fake\DataObjectFake;
use SilverStripe\SearchService\Tests\Fake\DataObjectFakeVersioned;
use SilverStripe\SearchService\Tests\Fake\DataObjectSubclassFake;
Expand Down Expand Up @@ -89,7 +85,7 @@ public function testShouldIndex()
$this->assertFalse($doc->shouldIndex());
}

public function testSubsiteShouldIndex()
public function testSubsiteDataObjectShouldIndex()
{
$config = $this->mockConfig();

Expand All @@ -111,7 +107,7 @@ public function testSubsiteShouldIndex()
]
);

/** @var Versioned $dataobject */
/** @var Versioned $dataobject1 */
$dataobject1 = new VersionedDataObjectFake([
'ID' => 6,
'ShowInSearch' => true,
Expand All @@ -125,7 +121,7 @@ public function testSubsiteShouldIndex()
// Incorrect SubsiteID for DO so should fail
$this->assertFalse($doc1->shouldIndex());

/** @var Versioned $dataobject */
/** @var Versioned $dataobject2 */
$dataobject2 = new VersionedDataObjectFake([
'ID' => 7,
'ShowInSearch' => true,
Expand All @@ -139,6 +135,21 @@ public function testSubsiteShouldIndex()
// SubsiteID is NULL for DO but explicitly defined in config so should be true.
$this->assertNull($dataobject2->SubsiteID);
$this->assertTrue($doc2->shouldIndex());

/** @var Versioned $dataobject3 */
$dataobject3 = new VersionedDataObjectFake([
'ID' => 7,
'ShowInSearch' => true,
'SubsiteID' => 0,
]);
$dataobject3->publishSingle();
$dataobject3->can_view = true;

$doc3 = DataObjectDocument::create($dataobject3);

// SubsiteID is correct on DO and as per config so should be true.
$this->assertEquals(0, $dataobject3->SubsiteID);
$this->assertTrue($doc3->shouldIndex());
}

public function testMarkIndexed()
Expand Down

0 comments on commit 4a414c1

Please sign in to comment.