Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Apr 9, 2024
1 parent 0a664c2 commit 8ae2cc8
Show file tree
Hide file tree
Showing 52 changed files with 314 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" convertDeprecationsToExceptions="false">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
Expand Down
2 changes: 1 addition & 1 deletion tests/BasePurchaseServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 4 additions & 9 deletions tests/PaymentMathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public function setUp(): void
Config::modify()->set(PaymentMath::class, 'useBcMath', true);
}

/**
* @doesNotPerformAssertions
*/

public function testPrecision()
{
if (!function_exists('bcsub')) {
Expand All @@ -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);
Expand All @@ -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')) {
Expand Down Expand Up @@ -114,9 +111,7 @@ public function testSubtractionFloat()
$this->assertEquals('45.9990', $result);
}

/**
* @doesNotPerformAssertions
*/

public function testAddition()
{
if (!function_exists('bcadd')) {
Expand Down
8 changes: 4 additions & 4 deletions tests/PaymentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

class i18nOtherModule
{
public function mymethod()
{
_t(
'i18nOtherModule.ENTITY',
'Other Module Entity'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use SilverStripe\i18n\i18nEntityProvider;

class i18nProviderClass implements i18nEntityProvider
{
public function provideI18nEntities()
{
return [
'i18nProviderClass.TITLE' => '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'
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use SilverStripe\ORM\DataExtension;

class i18nTestModuleExtension extends DataExtension
{

public static $db = [
'MyExtraField' => 'Varchar'
];
}
4 changes: 4 additions & 0 deletions tests/i18nTest/_fakewebroot/i18nothermodule/lang/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
de:
i18nOtherModule:
ENTITY: Other Module Entity (de)
MAINTEMPLATE: Main Template Other Module (de)
4 changes: 4 additions & 0 deletions tests/i18nTest/_fakewebroot/i18nothermodule/lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
i18nOtherModule:
ENTITY: Other Module Entity
MAINTEMPLATE: Main Template Other Module
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%t i18nOtherModule.MAINTEMPLATE "Main Template Other Module" %>
Empty file.
1 change: 1 addition & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
27 changes: 27 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/code/i18nTestModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use SilverStripe\ORM\DataObject;
use SilverStripe\Dev\TestOnly;

class i18nTestModule extends DataObject implements TestOnly
{
private static $db = [
'MyField' => 'Varchar',
];

public function myMethod()
{
_t(
'i18nTestModule.ENTITY',
'Entity with "Double Quotes"',
'Comment for entity'
);
}
}
class i18nTestModule_Addition
{
public function myAdditionalMethod()
{
_t('i18nTestModule.ADDITION', 'Addition');
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace i18nTest;

class i18nTestNamespacedClass
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class i18nTestSubModule
{
public function __construct()
{
_t('i18nTestModule.OTHERENTITY', 'Other Entity');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
de:
i18nTestModule:
PRIORITYNOTICE: High Module Priority (de)
OTHERENTITY: Other Entity (de)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
en:
i18nTestModule:
OTHERENTITY: Other Entity
16 changes: 16 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
de:
NONAMESPACE: Include Entity without Namespace (de)
REPLACEMENTNONAMESPACE: "My replacement no namespace: {replacement} (de)"
REPLACEMENTINCLUDENONAMESPACE: "My include replacement no namespace: {replacement} (de)"
LAYOUTTEMPLATENONAMESPACE: Layout Template no namespace (de)
i18nTestModule:
# Comment for entity
ENTITY: 'Entity with "Double Quotes" (de)'
ADDITION: Addition (de)
MAINTEMPLATE: Main Template (de)
WITHNAMESPACE: Include Entity with Namespace (de)
LAYOUTTEMPLATE: Layout Template (de)
REPLACEMENTNAMESPACE: "My replacement: {replacement} (de)"
PRIORITYNOTICE: Low Module Priority (de)
i18nTestModuleInclude_ss:
REPLACEMENTINCLUDENAMESPACE: "My include replacement: {replacement} (de)"
3 changes: 3 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/de_AT.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
de_AT:
i18nTestModule:
ENTITY: 'Entity with "Double Quotes" (de_AT)'
22 changes: 22 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
en:
NONAMESPACE: Include Entity without Namespace
REPLACEMENTNONAMESPACE: 'My replacement no namespace: {replacement}'
REPLACEMENTINCLUDENONAMESPACE: 'My include replacement no namespace: {replacement}'
LAYOUTTEMPLATENONAMESPACE: Layout Template no namespace
i18nTestModule:
# Comment for entity
ENTITY: 'Entity with "Double Quotes"'
ADDITION: Addition
MAINTEMPLATE: Main Template
WITHNAMESPACE: Include Entity with Namespace
LAYOUTTEMPLATE: Layout Template
REPLACEMENTNAMESPACE: 'My replacement: {replacement}'
PLURALS:
one: 'A test'
other: '{count} tests'
i18nTestModuleInclude_ss:
REPLACEMENTINCLUDENAMESPACE: "My include replacement: {replacement}"
Month:
PLURALS:
one: 'A month'
other: '{count} months'
15 changes: 15 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/en_GB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
NONAMESPACE: Include Entity without Namespace
REPLACEMENTNONAMESPACE: "My replacement no namespace: {replacement}"
REPLACEMENTINCLUDENONAMESPACE: "My include replacement no namespace: {replacement}"
LAYOUTTEMPLATENONAMESPACE: Layout Template no namespace
i18nTestModule:
# Comment for entity
ENTITY: 'Entity with "Double Quotes"'
ADDITION: Addition
MAINTEMPLATE: Main Template
WITHNAMESPACE: Include Entity with Namespace
LAYOUTTEMPLATE: Layout Template
REPLACEMENTNAMESPACE: "My replacement: {replacement}"
i18nTestModuleInclude_ss:
REPLACEMENTINCLUDENAMESPACE: "My include replacement: {replacement}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
NONAMESPACE: Include Entity without Namespace
Invalid: Foo
About: 'About us'
- Invalid # this should throw "A colon cannot be used in an unquoted mapping value at line 5"
15 changes: 15 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/es_AR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
NONAMESPACE: Include Entity without Namespace
REPLACEMENTNONAMESPACE: 'My replacement no namespace: {replacement}'
REPLACEMENTINCLUDENONAMESPACE: 'My include replacement no namespace: {replacement}'
LAYOUTTEMPLATENONAMESPACE: Layout Template no namespace
i18nTestModule:
# Comment for entity
ENTITY: Entity with "Double Quotes"
ADDITION: Addition
MAINTEMPLATE: Main Template
WITHNAMESPACE: Include Entity with Namespace
LAYOUTTEMPLATE: Layout Template
REPLACEMENTNAMESPACE: 'My replacement: {replacement}'
i18nTestModuleInclude_ss:
REPLACEMENTINCLUDENAMESPACE: 'My include replacement: {replacement}'
15 changes: 15 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/es_ES.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
NONAMESPACE: Include Entity without Namespace
REPLACEMENTNONAMESPACE: 'My replacement no namespace: {replacement}'
REPLACEMENTINCLUDENONAMESPACE: 'My include replacement no namespace: {replacement}'
LAYOUTTEMPLATENONAMESPACE: Layout Template no namespace
i18nTestModule:
# Comment for entity
ENTITY: Entity with "Double Quotes"
ADDITION: Addition
MAINTEMPLATE: Main Template
WITHNAMESPACE: Include Entity with Namespace
LAYOUTTEMPLATE: Layout Template
REPLACEMENTNAMESPACE: 'My replacement: {replacement}'
i18nTestModuleInclude_ss:
REPLACEMENTINCLUDENAMESPACE: 'My include replacement: {replacement}'
3 changes: 3 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fr:
i18nTestModule:
ENTITY: 'Entity with "Double Quotes" (fr)'
4 changes: 4 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/ja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ja:
Month:
PLURALS:
other: '{count}日'
3 changes: 3 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/mi_NZ.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mi_NZ:
i18nTestModule:
ENTITY: Translation (mi_NZ)
7 changes: 7 additions & 0 deletions tests/i18nTest/_fakewebroot/i18ntestmodule/lang/pl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pl:
Month:
PLURALS:
one: '1 miesiąc'
few: '{count} miesiące'
many: '{count} miesięcy'
other: '{count} miesiąca'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%t i18nTestModule.WITHNAMESPACE 'Include Entity with Namespace' %>
<%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 %>
Original file line number Diff line number Diff line change
@@ -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" %>
Original file line number Diff line number Diff line change
@@ -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 %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions tests/i18nTest/_fakewebroot/notmodule/noop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
11 changes: 11 additions & 0 deletions tests/i18nTest/_fakewebroot/themes/testtheme1/lang/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
de:
i18nTestTheme1:
LAYOUTTEMPLATE: Theme1 Layout Template (de)
REPLACEMENTNAMESPACE: 'Theme1 My replacement: {replacement} (de)'
i18nTestTheme1Include:
WITHNAMESPACE: Theme1 Include Entity with Namespace (de)
REPLACEMENTINCLUDENAMESPACE: 'Theme1 My include replacement: {replacement} (de)'
NONAMESPACE: Theme1 Include Entity without Namespace (de)
REPLACEMENTINCLUDENONAMESPACE: 'Theme1 My include replacement no namespace: {replacement} (de)'
LAYOUTTEMPLATENONAMESPACE: Theme1 Layout Template no namespace (de)
REPLACEMENTNONAMESPACE: 'Theme1 My replacement no namespace: {replacement} (de)'
11 changes: 11 additions & 0 deletions tests/i18nTest/_fakewebroot/themes/testtheme1/lang/de_DE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

global $lang;

if (array_key_exists('de_DE', $lang ?? []) && is_array($lang['de_DE'])) {
$lang['de_DE'] = array_merge($lang['en_US'], $lang['de_DE']);
} else {
$lang['de_DE'] = $lang['en_US'];
}

$lang['de_DE']['i18nOtherModule']['LEGACYTHEME'] = 'Legacy translation (de_DE)';
Loading

0 comments on commit 8ae2cc8

Please sign in to comment.