Skip to content

Commit

Permalink
Merge pull request #736 from creative-commoners/pulls/4/sapphire-test…
Browse files Browse the repository at this point in the history
…-nine

API phpunit 9 support
  • Loading branch information
tractorcow authored Nov 5, 2021
2 parents fbabf52 + c739587 commit 95c35ac
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 80 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Module CI

on:
push:
pull_request:

jobs:
ci:
uses: silverstripe/github-actions-ci-cd/.github/workflows/[email protected]
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"issues": "http://github.com/tractorcow-farm/silverstripe-fluent/issues"
},
"require": {
"php": "^7.3 || ^8.0",
"silverstripe/vendor-plugin": "^1",
"silverstripe/framework": "^4",
"silverstripe/framework": "^4.10",
"silverstripe/cms": "^4",
"symbiote/silverstripe-gridfieldextensions": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"sminnee/phpunit-mock-objects": "^3.4.5",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3"
},
"extra": {
Expand Down
14 changes: 7 additions & 7 deletions tests/php/Extension/FluentBadgeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FluentBadgeExtensionTest extends SapphireTest
*/
protected $extension;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -63,9 +63,9 @@ public function testDefaultLocaleBadgeAdded()

$result = $this->extension->getBadge($this->mockPage);
$this->assertInstanceOf(DBHTMLText::class, $result);
$this->assertContains('fluent-badge--default', $result->getValue());
$this->assertContains('Default locale', $result->getValue());
$this->assertContains('NZ', $result->getValue(), 'Badge shows owner locale');
$this->assertStringContainsString('fluent-badge--default', (string) $result->getValue());
$this->assertStringContainsString('Default locale', (string) $result->getValue());
$this->assertStringContainsString('NZ', (string) $result->getValue(), 'Badge shows owner locale');
});
}

Expand All @@ -77,9 +77,9 @@ public function testInvisibleLocaleBadgeWasAdded()

$result = $this->extension->getBadge($this->mockPage);
$this->assertInstanceOf(DBHTMLText::class, $result);
$this->assertContains('fluent-badge--invisible', $result->getValue());
$this->assertContains('is not visible in this locale', $result->getValue());
$this->assertContains('NZ', $result->getValue(), 'Badge shows owner locale');
$this->assertStringContainsString('fluent-badge--invisible', (string) $result->getValue());
$this->assertStringContainsString('is not visible in this locale', (string) $result->getValue());
$this->assertStringContainsString('NZ', (string) $result->getValue(), 'Badge shows owner locale');
});
}
}
6 changes: 3 additions & 3 deletions tests/php/Extension/FluentDirectorExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FluentDirectorExtensionTest extends FunctionalTest
],
];

public function setUp() // phpcs:ignore SlevomatCodingStandard.TypeHints
protected function setUp(): void // phpcs:ignore SlevomatCodingStandard.TypeHints
{
parent::setUp();

Expand All @@ -62,7 +62,7 @@ public function testVisitUrlByLocaleWithMultiByteCharacter()

$this->get($page->AbsoluteLink());

$this->assertContains(sprintf('<title>%s', $expectedTitle), $this->content());
$this->assertStringContainsString(sprintf('<title>%s', $expectedTitle), $this->content());
});
}

Expand All @@ -83,7 +83,7 @@ public function testLocalizedControllerRouting()

$this->get(Director::absoluteURL('nouvelle-z%C3%A9lande/TestController'));

$this->assertContains('Test Controller! en_NZ', $this->content());
$this->assertStringContainsString('Test Controller! en_NZ', $this->content());
}

protected function setUpRoutes()
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Extension/FluentExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FluentExtensionTest extends SapphireTest
],
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Extension/FluentFilteredExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FluentFilteredExtensionTest extends SapphireTest
],
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
10 changes: 5 additions & 5 deletions tests/php/Extension/FluentSiteTreeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FluentSiteTreeExtensionTest extends SapphireTest
],
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
Config::modify()
Expand Down Expand Up @@ -204,7 +204,7 @@ public function testStatusMessageNotVisible()
$statusMessage = $fields->fieldByName('LocaleStatusMessage');

$this->assertNotNull($statusMessage, 'Locale message was not added');
$this->assertContains('This page will not be visible', $statusMessage->getContent());
$this->assertStringContainsString('This page will not be visible', $statusMessage->getContent());
});
}

Expand All @@ -227,7 +227,7 @@ public function testStatusMessageInherited()
$statusMessage = $fields->fieldByName('LocaleStatusMessage');

$this->assertNotNull($fields->fieldByName('LocaleStatusMessage'));
$this->assertContains('Content for this page may be inherited', $statusMessage->getContent());
$this->assertStringContainsString('Content for this page may be inherited', $statusMessage->getContent());
});
}

Expand All @@ -251,7 +251,7 @@ public function testStatusMessageDrafted()
$statusMessage = $fields->fieldByName('LocaleStatusMessage');

$this->assertNotNull($fields->fieldByName('LocaleStatusMessage'));
$this->assertContains('A draft has been created for this locale', $statusMessage->getContent());
$this->assertStringContainsString('A draft has been created for this locale', $statusMessage->getContent());
});
}

Expand Down Expand Up @@ -295,7 +295,7 @@ public function testUpdateCMSActionsDrafted()

$this->assertEquals('Saved', $actionSave->Title());
// The default value changed between SS 4.0 and 4.1 - assert it contains Publish instead of exact matching
$this->assertContains('publish', strtolower($actionPublish->Title()));
$this->assertStringContainsString('publish', strtolower($actionPublish->Title()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Extension/FluentVersionedExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FluentVersionedExtensionTest extends SapphireTest
],
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Middleware/DetectLocaleMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DetectLocaleMiddlewareTest extends SapphireTest
*/
protected $globalDefaultLocale;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->middleware = new Stub\DetectLocaleMiddlewareSpy;
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Model/Delete/DeleteRecordPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DeleteRecordPolicyTest extends SapphireTest
FilteredRecord::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
22 changes: 11 additions & 11 deletions tests/php/Model/LocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LocaleTest extends SapphireTest
{
protected static $fixture_file = 'LocaleTest.yml';

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -100,26 +100,26 @@ public function testGetBaseURLContainsDomainAndURLSegmentForNonDefaultLocale()
{
// es_ES has a domain but is not the default locale for that domain
$result = Locale::getByLocale('es_ES')->getBaseURL();
$this->assertContains('fluent.es', $result, "Locale's domain is in the URL");
$this->assertContains('/es/', $result, 'URL segment for non-default locale is in the URL');
$this->assertStringContainsString('fluent.es', $result, "Locale's domain is in the URL");
$this->assertStringContainsString('/es/', $result, 'URL segment for non-default locale is in the URL');

// Turning off domain mode removes domain but not prefix
FluentState::singleton()->setIsDomainMode(false);
$result = Locale::getByLocale('es_ES')->getBaseURL();
$this->assertNotContains('fluent.es', $result, "Locale's domain is in the URL");
$this->assertContains('/es/', $result, 'URL segment for non-default locale is in the URL');
$this->assertStringNotContainsString('fluent.es', $result, "Locale's domain is in the URL");
$this->assertStringContainsString('/es/', $result, 'URL segment for non-default locale is in the URL');
}

public function testBaseURLPrefixDisabled()
{
// Default base url includes the default url segment
$result = Locale::getDefault()->getBaseURL();
$this->assertContains('/au/', $result);
$this->assertStringContainsString('/au/', $result);

// Default base url shortens the default locale url base by excluding the locale's url segment
Config::inst()->set(FluentDirectorExtension::class, 'disable_default_prefix', true);
$result = Locale::getDefault()->getBaseURL();
$this->assertNotContains('/au/', $result);
$this->assertStringNotContainsString('/au/', $result);
}

public function testGetBaseURLOnlyContainsDomainForPrefixDisabledDefaultLocale()
Expand All @@ -128,14 +128,14 @@ public function testGetBaseURLOnlyContainsDomainForPrefixDisabledDefaultLocale()

// es_US has a domain and is the default
$result = Locale::getByLocale('es_US')->getBaseURL();
$this->assertContains('fluent.es', $result, "Locale's domain is in the URL");
$this->assertNotContains('/es-usa/', $result, 'URL segment is not in the URL for default locales');
$this->assertStringContainsString('fluent.es', $result, "Locale's domain is in the URL");
$this->assertStringNotContainsString('/es-usa/', $result, 'URL segment is not in the URL for default locales');

// When domain mode is turned off, prefix is now necessary
FluentState::singleton()->setIsDomainMode(false);
$result = Locale::getByLocale('es_US')->getBaseURL();
$this->assertNotContains('fluent.es', $result, "Domain not used");
$this->assertContains('/es-usa/', $result, 'URL Segment necessary for non-global default');
$this->assertStringNotContainsString('fluent.es', $result, "Domain not used");
$this->assertStringContainsString('/es-usa/', $result, 'URL Segment necessary for non-global default');
}

public function testGetSiblings()
Expand Down

0 comments on commit 95c35ac

Please sign in to comment.