Skip to content

Commit

Permalink
Fix unit tests for badge trait
Browse files Browse the repository at this point in the history
  • Loading branch information
tractorcow committed Feb 9, 2020
1 parent 9f6d6ec commit 44cbe21
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
node_modules/
vendor/
resources/
public/
app/
index.php
install*
web.config
assets
.env
.htaccess
composer.lock

4 changes: 3 additions & 1 deletion src/Extension/FluentGridFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace TractorCow\Fluent\Extension;

use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Versioned\VersionedGridFieldItemRequest;
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait;
Expand Down Expand Up @@ -43,7 +45,7 @@ public function updateFormActions(FieldList $actions)
/**
* @param Form $form
* @param string $message
* @return mixed
* @return HTTPResponse|string|DBHTMLText
*/
public function actionComplete($form, $message)
{
Expand Down
14 changes: 9 additions & 5 deletions src/Extension/FluentLeftAndMainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace TractorCow\Fluent\Extension;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\Form;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\Requirements;
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait;
use TractorCow\Fluent\Extension\Traits\FluentBadgeTrait;
Expand All @@ -24,8 +28,8 @@ public function init()
}

/**
* @see CMSMain::Breadcrumbs()
* @param ArrayList $breadcrumbs
* @see CMSMain::Breadcrumbs()
*/
public function updateBreadcrumbs(ArrayList $breadcrumbs)
{
Expand All @@ -43,10 +47,10 @@ public function updateBreadcrumbs(ArrayList $breadcrumbs)
}

/**
* @param $form
* @param $message
* @return \SilverStripe\Control\HTTPResponse
* @throws \SilverStripe\Control\HTTPResponse_Exception
* @param Form $form
* @param string $message
* @return HTTPResponse|string|DBHTMLText
* @throws HTTPResponse_Exception
*/
public function actionComplete($form, $message)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Extension/FluentSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait;
use TractorCow\Fluent\Model\Locale;
use TractorCow\Fluent\State\FluentState;
Expand Down Expand Up @@ -343,8 +346,14 @@ protected function updateSavePublishActions(FieldList $actions)
}
}

/**
* @param Form $form
* @param string $message
* @return HTTPResponse|string|DBHTMLText
*/
public function actionComplete($form, $message)
{
// noop
return null;
}
}
7 changes: 7 additions & 0 deletions src/Extension/Traits/FluentAdminTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace TractorCow\Fluent\Extension\Traits;

use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Versioned\Versioned;
use TractorCow\Fluent\Extension\FluentExtension;
Expand All @@ -24,6 +26,11 @@
*/
trait FluentAdminTrait
{
/**
* @param Form $form
* @param string $message
* @return HTTPResponse|string|DBHTMLText
*/
abstract public function actionComplete($form, $message);


Expand Down
5 changes: 2 additions & 3 deletions tests/php/Extension/FluentBadgeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use SilverStripe\Control\Controller;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBHTMLText;
use TractorCow\Fluent\Extension\FluentBadgeExtension;
use TractorCow\Fluent\Extension\FluentLeftAndMainExtension;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
use TractorCow\Fluent\Model\Locale;
Expand Down Expand Up @@ -65,7 +64,7 @@ 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('Published in', $result->getValue());
$this->assertContains('NZ', $result->getValue(), 'Badge shows owner locale');
});
}
Expand All @@ -80,7 +79,7 @@ public function testInvisibleLocaleBadgeWasAdded()
$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->assertContains('de_DE', $result->getValue(), 'Badge shows owner locale');
});
}
}

0 comments on commit 44cbe21

Please sign in to comment.