Compare commits

...

3 Commits

Author SHA1 Message Date
Steve Boyd
7ee6edf4b1
Merge f180723daa into ba97de9458 2024-10-21 05:43:06 +00:00
Steve Boyd
f180723daa MNT Fix unit tests 2024-10-21 18:42:59 +13:00
Steve Boyd
89213c90ec FIX Call defineMethods if lower method is missing 2024-10-21 18:21:16 +13:00
4 changed files with 36 additions and 13 deletions

View File

@ -171,11 +171,14 @@ trait CustomMethods
} }
// Lazy define methods // Lazy define methods
$lowerClass = strtolower(static::class); $lowerClass = strtolower(static::class);
if (!isset(self::class::$extra_methods[$lowerClass])) { $lowerMethod = strtolower($method);
if (!array_key_exists($lowerClass, self::class::$extra_methods)
|| !array_key_exists($lowerMethod, self::class::$extra_methods[$lowerClass])
) {
$this->defineMethods(); $this->defineMethods();
} }
return self::class::$extra_methods[$lowerClass][strtolower($method)] ?? null; return self::class::$extra_methods[$lowerClass][$lowerMethod] ?? null;
} }
/** /**

View File

@ -391,7 +391,7 @@ class Deprecation
} }
// Getting a backtrace is slow, so we only do it if we need it // Getting a backtrace is slow, so we only do it if we need it
$backtrace = null; $backtrace = [];
// Get the calling scope // Get the calling scope
if ($scope == Deprecation::SCOPE_METHOD) { if ($scope == Deprecation::SCOPE_METHOD) {

View File

@ -111,8 +111,8 @@ class DeprecationTest extends SapphireTest
'Will be removed without equivalent functionality to replace it.', 'Will be removed without equivalent functionality to replace it.',
'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.' 'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.'
]); ]);
$this->expectDeprecation(); $this->expectException(DeprecationTestException::class);
$this->expectDeprecationMessage($message); $this->expectExceptionMessage($message);
$this->enableDeprecationNotices(true); $this->enableDeprecationNotices(true);
$ret = $this->myDeprecatedMethodNoReplacement(); $ret = $this->myDeprecatedMethodNoReplacement();
$this->assertSame('abc', $ret); $this->assertSame('abc', $ret);

View File

@ -138,16 +138,36 @@ class SearchContextTest extends SapphireTest
public function testUserDefinedFieldsAppearInSearchContext() public function testUserDefinedFieldsAppearInSearchContext()
{ {
$company = SearchContextTest\Company::singleton(); $company = SearchContextTest\Company::singleton();
$searchName = $company->getGeneralSearchFieldName();
$expected = new FieldList(
new HiddenField($searchName, 'General Search'),
(new TextField("Name", 'Name'))
->setMaxLength(255),
new TextareaField("Industry", 'Industry'),
new NumericField("AnnualProfit", 'The Almighty Annual Profit')
);
$context = $company->getDefaultSearchContext(); $context = $company->getDefaultSearchContext();
$actual = $context->getFields();
$this->assertSame($expected->count(), $actual->count());
$this->assertEquals( $this->assertEquals(
new FieldList( $expected->fieldByName($searchName)->Title,
new HiddenField($company->getGeneralSearchFieldName(), 'General Search'), $actual->fieldByName($searchName)->Title
(new TextField("Name", 'Name')) );
->setMaxLength(255), $this->assertEquals(
new TextareaField("Industry", 'Industry'), $expected->fieldByName('Name')->Title,
new NumericField("AnnualProfit", 'The Almighty Annual Profit') $actual->fieldByName('Name')->Title
), );
$context->getFields() $this->assertEquals(
$expected->fieldByName('Name')->getMaxLength(),
$actual->fieldByName('Name')->getMaxLength()
);
$this->assertEquals(
$expected->fieldByName('Industry')->Title,
$actual->fieldByName('Industry')->Title
);
$this->assertEquals(
$expected->fieldByName('AnnualProfit')->Title,
$actual->fieldByName('AnnualProfit')->Title
); );
} }