From 8ae2cc85230a7929e6b869b6696d567d65191cf2 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 2 Apr 2024 20:58:33 +1300 Subject: [PATCH] fix: update tests --- composer.json | 2 +- phpunit.xml.dist | 2 +- tests/BasePurchaseServiceTest.php | 2 +- tests/PaymentMathTest.php | 13 +++------ tests/PaymentModelTest.php | 8 +++--- tests/i18nTest/_fakewebroot/_manifest_exclude | 0 tests/i18nTest/_fakewebroot/assets/blank | 0 .../i18nnonstandardmodule/_config.php | 1 + .../i18nnonstandardmodule/phpfile.php | 1 + .../i18nnonstandardmodule/template.ss | 1 + .../tests/NothingInHere.php | 1 + .../i18nothermodule/_config/blank.yml | 0 .../i18nothermodule/code/i18nOtherModule.php | 12 +++++++++ .../code/i18nProviderClass.php | 23 ++++++++++++++++ .../code/i18nTestModuleDecorator.php | 11 ++++++++ .../_fakewebroot/i18nothermodule/lang/de.yml | 4 +++ .../_fakewebroot/i18nothermodule/lang/en.yml | 4 +++ .../templates/i18nOtherModule.ss | 1 + .../wrongplace/i18nNotIncluded.ss | 0 .../_fakewebroot/i18ntestmodule/_config.php | 1 + .../i18ntestmodule/code/i18nTestModule.php | 27 +++++++++++++++++++ .../i18ntestmodule/code/subfolder/_config.php | 0 .../subfolder/i18nTestNamespacedClass.php | 8 ++++++ .../code/subfolder/i18nTestSubModule.php | 9 +++++++ .../i18ntestmodule/code/subfolder/lang/de.yml | 4 +++ .../i18ntestmodule/code/subfolder/lang/en.yml | 3 +++ .../_fakewebroot/i18ntestmodule/lang/de.yml | 16 +++++++++++ .../i18ntestmodule/lang/de_AT.yml | 3 +++ .../_fakewebroot/i18ntestmodule/lang/en.yml | 22 +++++++++++++++ .../i18ntestmodule/lang/en_GB.yml | 15 +++++++++++ .../i18ntestmodule/lang/en_corrupt.yml | 5 ++++ .../i18ntestmodule/lang/es_AR.yml | 15 +++++++++++ .../i18ntestmodule/lang/es_ES.yml | 15 +++++++++++ .../_fakewebroot/i18ntestmodule/lang/fr.yml | 3 +++ .../_fakewebroot/i18ntestmodule/lang/ja.yml | 4 +++ .../i18ntestmodule/lang/mi_NZ.yml | 3 +++ .../_fakewebroot/i18ntestmodule/lang/pl.yml | 7 +++++ .../Includes/i18nTestModuleInclude.ss | 4 +++ .../templates/Layout/i18nTestModule.ss | 12 +++++++++ .../templates/i18nTestModule.ss | 7 +++++ .../i18ntestmodule/tests/DontLook.php | 1 + .../i18nTest/_fakewebroot/notmodule/noop.php | 1 + .../themes/testtheme1/lang/de.yml | 11 ++++++++ .../themes/testtheme1/lang/de_DE.php | 11 ++++++++ .../themes/testtheme1/lang/en.yml | 11 ++++++++ .../themes/testtheme1/lang/en_US.php | 5 ++++ .../Includes/i18nTestTheme1Include.ss | 4 +++ .../templates/Layout/i18nTestTheme1.ss | 5 ++++ .../templates/i18nTestTheme1Main.ss | 3 +++ .../themes/testtheme2/lang/de.yml | 3 +++ .../themes/testtheme2/lang/en.yml | 3 +++ .../testtheme2/templates/i18nTestTheme2.ss | 3 +++ 52 files changed, 314 insertions(+), 16 deletions(-) create mode 100644 tests/i18nTest/_fakewebroot/_manifest_exclude create mode 100644 tests/i18nTest/_fakewebroot/assets/blank create mode 100644 tests/i18nTest/_fakewebroot/i18nnonstandardmodule/_config.php create mode 100644 tests/i18nTest/_fakewebroot/i18nnonstandardmodule/phpfile.php create mode 100644 tests/i18nTest/_fakewebroot/i18nnonstandardmodule/template.ss create mode 100644 tests/i18nTest/_fakewebroot/i18nnonstandardmodule/tests/NothingInHere.php create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/_config/blank.yml create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/code/i18nOtherModule.php create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/code/i18nProviderClass.php create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/lang/de.yml create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/lang/en.yml create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/templates/i18nOtherModule.ss create mode 100644 tests/i18nTest/_fakewebroot/i18nothermodule/wrongplace/i18nNotIncluded.ss create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/_config.php create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/code/i18nTestModule.php create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/_config.php create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/i18nTestNamespacedClass.php create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/i18nTestSubModule.php create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/lang/de.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/lang/en.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/de.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/de_AT.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/en.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/en_GB.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/en_corrupt.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/es_AR.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/es_ES.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/fr.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/ja.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/mi_NZ.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/lang/pl.yml create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/templates/Includes/i18nTestModuleInclude.ss create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/templates/Layout/i18nTestModule.ss create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/templates/i18nTestModule.ss create mode 100644 tests/i18nTest/_fakewebroot/i18ntestmodule/tests/DontLook.php create mode 100644 tests/i18nTest/_fakewebroot/notmodule/noop.php create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/lang/de.yml create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/lang/de_DE.php create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/lang/en.yml create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/lang/en_US.php create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/templates/Includes/i18nTestTheme1Include.ss create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/templates/Layout/i18nTestTheme1.ss create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme1/templates/i18nTestTheme1Main.ss create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme2/lang/de.yml create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme2/lang/en.yml create mode 100644 tests/i18nTest/_fakewebroot/themes/testtheme2/templates/i18nTestTheme2.ss diff --git a/composer.json b/composer.json index d1d93981..b052b66f 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "BSD-3-Clause", "keywords": ["silverstripe","payment","omnipay"], "require": { - "php": "^8.1", + "php": "^8.2", "silverstripe/framework": "^5", "omnipay/common": "^3" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4ae0500f..ce4cc993 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + src/ diff --git a/tests/BasePurchaseServiceTest.php b/tests/BasePurchaseServiceTest.php index 9505ebad..460c564e 100644 --- a/tests/BasePurchaseServiceTest.php +++ b/tests/BasePurchaseServiceTest.php @@ -737,7 +737,7 @@ protected function buildPaymentGatewayStub($endpoint, Closure $successFunc, $sen $mockPaymentResponse->expects($this->any()) ->method('getRedirectResponse') - ->will($this->returnValue(RedirectResponse::create($endpoint))); + ->will($this->returnValue(new RedirectResponse($endpoint))); $mockPaymentRequest = $this->getMockBuilder('Omnipay\PaymentExpress\Message\PxPayPurchaseRequest') ->disableOriginalConstructor()->getMock(); diff --git a/tests/PaymentMathTest.php b/tests/PaymentMathTest.php index 75dd4a14..ed431992 100644 --- a/tests/PaymentMathTest.php +++ b/tests/PaymentMathTest.php @@ -18,9 +18,7 @@ public function setUp(): void Config::modify()->set(PaymentMath::class, 'useBcMath', true); } - /** - * @doesNotPerformAssertions - */ + public function testPrecision() { if (!function_exists('bcsub')) { @@ -45,6 +43,7 @@ public function testPrecision() $this->assertEquals('0.499000000000000', PaymentMath::add('0.273', '0.226')); } + public function testPrecisionFloat() { Config::modify()->set(PaymentMath::class, 'useBcMath', false); @@ -70,9 +69,7 @@ public function testPrecisionFloat() $this->assertEquals('0.4990000000000', PaymentMath::add('0.273', '0.226')); } - /** - * @doesNotPerformAssertions - */ + public function testSubtraction() { if (!function_exists('bcsub')) { @@ -114,9 +111,7 @@ public function testSubtractionFloat() $this->assertEquals('45.9990', $result); } - /** - * @doesNotPerformAssertions - */ + public function testAddition() { if (!function_exists('bcadd')) { diff --git a/tests/PaymentModelTest.php b/tests/PaymentModelTest.php index 3d9af6a2..282b3366 100644 --- a/tests/PaymentModelTest.php +++ b/tests/PaymentModelTest.php @@ -4,6 +4,7 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Forms\FieldList; use SilverStripe\i18n\i18n; use SilverStripe\Omnipay\GatewayInfo; use SilverStripe\Omnipay\Model\Payment; @@ -33,13 +34,12 @@ public function testParameterSetup() $this->assertEquals("Manual", $payment->Gateway); } - /** - * @doesNotPerformAssertions - */ + public function testCMSFields() { $fields = Payment::create()->getCMSFields(); - $this->markTestIncomplete('getCMSFields tests'); + + $this->assertInstanceOf(FieldList::class, $fields); } public function testTitle() diff --git a/tests/i18nTest/_fakewebroot/_manifest_exclude b/tests/i18nTest/_fakewebroot/_manifest_exclude new file mode 100644 index 00000000..e69de29b diff --git a/tests/i18nTest/_fakewebroot/assets/blank b/tests/i18nTest/_fakewebroot/assets/blank new file mode 100644 index 00000000..e69de29b diff --git a/tests/i18nTest/_fakewebroot/i18nnonstandardmodule/_config.php b/tests/i18nTest/_fakewebroot/i18nnonstandardmodule/_config.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18nnonstandardmodule/_config.php @@ -0,0 +1 @@ +

diff --git a/tests/i18nTest/_fakewebroot/i18nnonstandardmodule/tests/NothingInHere.php b/tests/i18nTest/_fakewebroot/i18nnonstandardmodule/tests/NothingInHere.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18nnonstandardmodule/tests/NothingInHere.php @@ -0,0 +1 @@ + 'My Provider Class', + 'i18nProviderClass.PLURALS' => [ + 'comment' => 'Plural forms for the test class', + 'one' => 'A class', + 'other' => '{count} classes', + ], + 'i18nProviderClass.OTHER_MODULE' => [ + 'comment' => 'Test string in another module', + 'default' => 'i18ntestmodule string defined in i18nothermodule', + 'module' => 'i18ntestmodule' + ], + ]; + } +} diff --git a/tests/i18nTest/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php b/tests/i18nTest/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php new file mode 100644 index 00000000..d04ab889 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18nothermodule/code/i18nTestModuleDecorator.php @@ -0,0 +1,11 @@ + 'Varchar' + ]; +} diff --git a/tests/i18nTest/_fakewebroot/i18nothermodule/lang/de.yml b/tests/i18nTest/_fakewebroot/i18nothermodule/lang/de.yml new file mode 100644 index 00000000..95728f25 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18nothermodule/lang/de.yml @@ -0,0 +1,4 @@ +de: + i18nOtherModule: + ENTITY: Other Module Entity (de) + MAINTEMPLATE: Main Template Other Module (de) diff --git a/tests/i18nTest/_fakewebroot/i18nothermodule/lang/en.yml b/tests/i18nTest/_fakewebroot/i18nothermodule/lang/en.yml new file mode 100644 index 00000000..84b78a48 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18nothermodule/lang/en.yml @@ -0,0 +1,4 @@ +en: + i18nOtherModule: + ENTITY: Other Module Entity + MAINTEMPLATE: Main Template Other Module diff --git a/tests/i18nTest/_fakewebroot/i18nothermodule/templates/i18nOtherModule.ss b/tests/i18nTest/_fakewebroot/i18nothermodule/templates/i18nOtherModule.ss new file mode 100644 index 00000000..8ae18229 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18nothermodule/templates/i18nOtherModule.ss @@ -0,0 +1 @@ +<%t i18nOtherModule.MAINTEMPLATE "Main Template Other Module" %> diff --git a/tests/i18nTest/_fakewebroot/i18nothermodule/wrongplace/i18nNotIncluded.ss b/tests/i18nTest/_fakewebroot/i18nothermodule/wrongplace/i18nNotIncluded.ss new file mode 100644 index 00000000..e69de29b diff --git a/tests/i18nTest/_fakewebroot/i18ntestmodule/_config.php b/tests/i18nTest/_fakewebroot/i18ntestmodule/_config.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18ntestmodule/_config.php @@ -0,0 +1 @@ + 'Varchar', + ]; + + public function myMethod() + { + _t( + 'i18nTestModule.ENTITY', + 'Entity with "Double Quotes"', + 'Comment for entity' + ); + } +} +class i18nTestModule_Addition +{ + public function myAdditionalMethod() + { + _t('i18nTestModule.ADDITION', 'Addition'); + } +} diff --git a/tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/_config.php b/tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/_config.php new file mode 100644 index 00000000..e69de29b diff --git a/tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/i18nTestNamespacedClass.php b/tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/i18nTestNamespacedClass.php new file mode 100644 index 00000000..085b8f6e --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18ntestmodule/code/subfolder/i18nTestNamespacedClass.php @@ -0,0 +1,8 @@ + +<%t NONAMESPACE 'Include Entity without Namespace' %> +<%t i18nTestModuleInclude_ss.REPLACEMENTINCLUDENAMESPACE 'My include replacement: {replacement}' replacement=$TestProperty %> +<%t REPLACEMENTINCLUDENONAMESPACE 'My include replacement no namespace: {replacement}' replacement=$TestProperty %> diff --git a/tests/i18nTest/_fakewebroot/i18ntestmodule/templates/Layout/i18nTestModule.ss b/tests/i18nTest/_fakewebroot/i18ntestmodule/templates/Layout/i18nTestModule.ss new file mode 100644 index 00000000..9be4e8d2 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18ntestmodule/templates/Layout/i18nTestModule.ss @@ -0,0 +1,12 @@ +<%t i18nTestModule.LAYOUTTEMPLATE "Layout Template" %> +<%t LAYOUTTEMPLATENONAMESPACE "Layout Template no namespace" %> +<%t i18nTestModule.REPLACEMENTNAMESPACE 'My replacement: {replacement}' replacement=$TestProperty %> +<%t REPLACEMENTNONAMESPACE 'My replacement no namespace: {replacement}' replacement=$TestProperty %> +<% include i18nTestModuleInclude %> + +<%t i18nTestModule.NEWMETHODSIG "New _t method signature test" %> +<%t i18nTestModule.INJECTIONS_DOES_NOT_EXIST "Hello {name} {greeting}. But it is late, {goodbye}" name="Mark" greeting="welcome" goodbye="bye" %> +<%t i18nTestModule.INJECTIONS "Hello {name} {greeting}. But it is late, {goodbye}" name="Paul" greeting="good you are here" goodbye="see you" %> +<%t i18nTestModule.INJECTIONS "Hello {name} {greeting}. But it is late, {goodbye}" is "New context (this should be ignored)" name="Steffen" greeting="willkommen" goodbye="wiedersehen" %> +<%t i18nTestModule.INJECTIONS name="Cat" greeting='meow' goodbye="meow" %> +<%t i18nTestModule.INJECTIONS name=$absoluteBaseURL greeting=$get_locale goodbye="global calls" %> diff --git a/tests/i18nTest/_fakewebroot/i18ntestmodule/templates/i18nTestModule.ss b/tests/i18nTest/_fakewebroot/i18ntestmodule/templates/i18nTestModule.ss new file mode 100644 index 00000000..74f01a3b --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18ntestmodule/templates/i18nTestModule.ss @@ -0,0 +1,7 @@ +<%t i18nTestModule.MAINTEMPLATE "Main Template" %> +$Layout +lonely _t() call that should be ignored +<%t i18nTestModule.NEWENTITY "Not stored in master file yet" %> +Single: <%t i18nTestModule.PLURALS 'An item|{count} items' count=1 %> +Multiple: <%t i18nTestModule.PLURALS 'An item|{count} items' count=4 %> +None: <%t i18nTestModule.PLURALS 'An item|{count} items' count=0 %> diff --git a/tests/i18nTest/_fakewebroot/i18ntestmodule/tests/DontLook.php b/tests/i18nTest/_fakewebroot/i18ntestmodule/tests/DontLook.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/i18ntestmodule/tests/DontLook.php @@ -0,0 +1 @@ + +<%t NONAMESPACE 'Theme1 Include Entity without Namespace' %> +<%t i18nTestTheme1Include.REPLACEMENTINCLUDENAMESPACE 'Theme1 My include replacement: {replacement}' replacement=$TestProperty %> +<%t REPLACEMENTINCLUDENONAMESPACE 'Theme1 My include replacement no namespace: {replacement}' replacement=$TestProperty %> diff --git a/tests/i18nTest/_fakewebroot/themes/testtheme1/templates/Layout/i18nTestTheme1.ss b/tests/i18nTest/_fakewebroot/themes/testtheme1/templates/Layout/i18nTestTheme1.ss new file mode 100644 index 00000000..ece4849e --- /dev/null +++ b/tests/i18nTest/_fakewebroot/themes/testtheme1/templates/Layout/i18nTestTheme1.ss @@ -0,0 +1,5 @@ +<%t i18nTestTheme1.LAYOUTTEMPLATE "Theme1 Layout Template" %> +<%t LAYOUTTEMPLATENONAMESPACE "Theme1 Layout Template no namespace" %> +<%t i18nTestTheme1.REPLACEMENTNAMESPACE 'Theme1 My replacement: {replacement}' replacement=$TestProperty %> +<%t REPLACEMENTNONAMESPACE 'Theme1 My replacement no namespace: {replacement}' replacement=$TestProperty %> +<% include i18nTestTheme1Include %> diff --git a/tests/i18nTest/_fakewebroot/themes/testtheme1/templates/i18nTestTheme1Main.ss b/tests/i18nTest/_fakewebroot/themes/testtheme1/templates/i18nTestTheme1Main.ss new file mode 100644 index 00000000..5aeaab02 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/themes/testtheme1/templates/i18nTestTheme1Main.ss @@ -0,0 +1,3 @@ +<%t i18nTestTheme1.MAINTEMPLATE "Theme1 Main Template" %> +$Layout +lonely _t() call that should be ignored diff --git a/tests/i18nTest/_fakewebroot/themes/testtheme2/lang/de.yml b/tests/i18nTest/_fakewebroot/themes/testtheme2/lang/de.yml new file mode 100644 index 00000000..35a047c4 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/themes/testtheme2/lang/de.yml @@ -0,0 +1,3 @@ +de: + i18nTestTheme2: + MAINTEMPLATE: Theme2 Main Template (de) diff --git a/tests/i18nTest/_fakewebroot/themes/testtheme2/lang/en.yml b/tests/i18nTest/_fakewebroot/themes/testtheme2/lang/en.yml new file mode 100644 index 00000000..be7733bc --- /dev/null +++ b/tests/i18nTest/_fakewebroot/themes/testtheme2/lang/en.yml @@ -0,0 +1,3 @@ +en: + i18nTestTheme2: + MAINTEMPLATE: Theme2 Main Template diff --git a/tests/i18nTest/_fakewebroot/themes/testtheme2/templates/i18nTestTheme2.ss b/tests/i18nTest/_fakewebroot/themes/testtheme2/templates/i18nTestTheme2.ss new file mode 100644 index 00000000..c99ac8d4 --- /dev/null +++ b/tests/i18nTest/_fakewebroot/themes/testtheme2/templates/i18nTestTheme2.ss @@ -0,0 +1,3 @@ +<%t i18nTestTheme2.MAINTEMPLATE "Theme2 Main Template" %> +$Layout +lonely _t() call that should be ignored