diff --git a/.travis.yml b/.travis.yml index f0ca414..5e60164 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,16 +17,17 @@ matrix: - php: 5.6 env: DB=MYSQL CORE_RELEASE=3.5 - php: 5.6 - env: DB=MYSQL CORE_RELEASE=3.6 + env: DB=MYSQL CORE_RELEASE=3.6 MAINTENANCE=^1 - php: 7.0 env: DB=MYSQL CORE_RELEASE=3.6 - php: 7.1 - env: DB=MYSQL CORE_RELEASE=3.6 + env: DB=MYSQL CORE_RELEASE=3.6 MAINTENANCE=1.0.x-dev before_script: - composer self-update || true - composer clear-cache - composer validate --strict + - if [[ $MAINTENANCE ]]; then composer require --no-update bringyourownideas/silverstripe-maintenance $MAINTENANCE; fi - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - cd ~/builds/ss diff --git a/src/Extensions/PackageSecruityExtension.php b/src/Extensions/PackageSecurityExtension.php similarity index 100% rename from src/Extensions/PackageSecruityExtension.php rename to src/Extensions/PackageSecurityExtension.php diff --git a/templates/SecurityAlertSummary.ss b/templates/SecurityAlertSummary.ss index 66a317d..2880447 100644 --- a/templates/SecurityAlertSummary.ss +++ b/templates/SecurityAlertSummary.ss @@ -1,6 +1,6 @@ -
+
<%t SecurityAlertSummary.TITLE "Security alert" %>
- <% if Count > 1 %>
+ <% if $Count > 1 %>
<%t SecurityAlertSummary.NOTICE_MANY "Notices have been issued for {count} of your modules. Review and updating is recommended." count=$Count %>
<% else %>
<%t SecurityAlertSummary.NOTICE_ONE "A notice has been issued for {count} of your modules. Review and updating is recommended." count=$Count %>
diff --git a/tests/PackageSecurityExtensionTest.php b/tests/PackageSecurityExtensionTest.php
new file mode 100644
index 0000000..ccabd1f
--- /dev/null
+++ b/tests/PackageSecurityExtensionTest.php
@@ -0,0 +1,30 @@
+markTestSkipped(
+ 'Module bringyourownideas/silverstripe-maintenance is required for this test, but is not present.'
+ );
+ }
+ parent::setUp();
+ }
+
+ public function testListSecurityAlertIdentifiers()
+ {
+ $package = $this->objFromFixture(Package::class, 'otheralerts');
+ $this->assertEquals('ABC-001, SPY-007', $package->listSecurityAlertIdentifiers());
+ }
+
+ public function testGetBadgesHook()
+ {
+ $package = $this->objFromFixture(Package::class, 'otheralerts');
+ $badges = $package->getBadges();
+ $this->assertCount(1, $badges);
+ $this->assertEquals('warning security-alerts__toggler', $badges->first()->Type);
+ }
+}
diff --git a/tests/PackagesWithAlerts.yml b/tests/PackagesWithAlerts.yml
new file mode 100644
index 0000000..7470e9d
--- /dev/null
+++ b/tests/PackagesWithAlerts.yml
@@ -0,0 +1,25 @@
+Package:
+ noalerts:
+ Name: venderr/noalert
+ Type: silverstripe-module
+ analert:
+ Name: venderr/analert
+ Type: silverstripe-vendormodule
+ otheralerts:
+ Name: venderr/otheralerts
+ Type: silverstripe-module
+SecurityAlert:
+ one:
+ ID: 1
+ Title: 'an alert'
+ PackageRecord: '=>Package.analert'
+ two:
+ ID: 2
+ Title: 'another alert'
+ Identifier: ABC-001
+ PackageRecord: '=>Package.otheralerts'
+ three:
+ ID: 4
+ Title: 'other alert'
+ Identifier: SPY-007
+ PackageRecord: '=>Package.otheralerts'
\ No newline at end of file
diff --git a/tests/SecurityAlertExtensionTest.php b/tests/SecurityAlertExtensionTest.php
new file mode 100644
index 0000000..ea9ef36
--- /dev/null
+++ b/tests/SecurityAlertExtensionTest.php
@@ -0,0 +1,22 @@
+markTestSkipped(
+ 'Module bringyourownideas/silverstripe-maintenance is required for this test, but is not present.'
+ );
+ }
+ parent::setUp();
+ }
+
+ public function testExtensionAppliesWhenMaintenanceModuleIsPresent()
+ {
+ $alert = $this->objFromFixture(SecurityAlert::class, 'two');
+ $this->assertTrue($alert->PackageRecord()->exists());
+ }
+}
diff --git a/tests/SiteSummaryExtensionTest.php b/tests/SiteSummaryExtensionTest.php
new file mode 100644
index 0000000..b1833ab
--- /dev/null
+++ b/tests/SiteSummaryExtensionTest.php
@@ -0,0 +1,66 @@
+ [SiteSummaryAlertStub::class]
+ ];
+
+ public function setUpOnce()
+ {
+ if (!class_exists(Package::class)) {
+ $this->requiredExtensions = [];
+ }
+ parent::setUpOnce();
+ }
+
+ public function setUp()
+ {
+ if (!class_exists(Package::class)) {
+ $this->markTestSkipped(
+ 'Module bringyourownideas/silverstripe-maintenance is required for this test, but is not present.'
+ );
+ }
+ // The themes should not affect test results.
+ // Ensure we use the default templates supplied with this module.
+ Config::inst()->update(SSViewer::class, 'theme_enabled', false);
+ parent::setUp();
+ }
+
+ public function testDisplayColumnsDoesNotIncludePrintingColumns()
+ {
+ $report = Injector::inst()->create(SiteSummary::class);
+ // screen output should not include this summary field added by the extension
+ $this->assertArrayNotHasKey('listSecurityAlertIdentifiers', $report->columns());
+ // default summary fields are still used for print output (e.g. CSV export)
+ $this->assertArrayHasKey('listSecurityAlertIdentifiers', Package::create()->summaryFields());
+ }
+
+ public function testUpdateAlerts()
+ {
+ $report = Injector::inst()->create(SiteSummary::class);
+ $fields = $report->getCMSFields();
+ $alertSummary = $fields->fieldByName('AlertSummary');
+ $this->assertInstanceOf(LiteralField::class, $alertSummary);
+ $content = $alertSummary->getContent();
+ $this->assertContains(
+ 'Sound the alarm!',
+ $content,
+ 'ensure our extension doesn\'t override all others'
+ );
+ $this->assertContains(
+ 'site-summary__security-alerts',
+ $content,
+ 'ensure content from our extension is present'
+ );
+ $this->assertContains(
+ '2',
+ $content,
+ 'ensure we are counting modules with alerts, not the total number of alerts'
+ );
+ }
+}
diff --git a/tests/Stubs/SiteSummaryAlertStub.php b/tests/Stubs/SiteSummaryAlertStub.php
new file mode 100644
index 0000000..a47d4c3
--- /dev/null
+++ b/tests/Stubs/SiteSummaryAlertStub.php
@@ -0,0 +1,14 @@
+Alert! Alert!
Sound the alarm!