Source of file BlockLinkFieldTest.php
Size: 2,884 Bytes - Last Modified: 2021-12-23T10:29:57+00:00
/var/www/docs.ssmods.com/process/src/tests/Form/BlockLinkFieldTest.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | <?php namespace SilverStripe\ElementalBlocks\Tests\Form; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\SapphireTest; use SilverStripe\ElementalBlocks\Form\BlockLinkField; use SilverStripe\View\ArrayData; class BlockLinkFieldTest extends SapphireTest { protected static $fixture_file = 'BlockLinkFieldTest.yml'; /** * @var BlockLinkField */ protected $field; protected function setUp() { parent::setUp(); $this->field = new BlockLinkField('test'); } public function testHasUniqueFormFieldSelector() { $this->assertContains('block-link-field', $this->field->Type()); } public function testGetParsedValue() { $this->field->setValue(json_encode(['foo' => 'bar', 'bar' => 'baz'])); $result = $this->field->getParsedValue(); $this->assertInstanceOf(ArrayData::class, $result); $this->assertSame('bar', $result->foo); } public function testParsedValueIsResetWhenSettingNewValue() { $this->field->setValue(json_encode(['foo' => 'bar'])); $result1 = $this->field->getParsedValue(); $this->field->setValue(json_encode(['foo' => 'baz'])); $result2 = $this->field->getParsedValue(); $this->assertNotSame($result1, $result2); $this->assertSame('baz', $result2->foo); } public function testGetLinkMethods() { $this->assertFalse($this->field->getLinkDefined()); $this->field->setValue(json_encode([ 'PageID' => $this->idFromFixture(SiteTree::class, 'a_page'), 'Text' => 'My link', 'Description' => 'Click here to see what happens next', 'TargetBlank' => true, ])); $this->assertTrue($this->field->getLinkDefined()); $this->assertSame('/my-page', $this->field->getLinkRelativeUrl()); $this->assertSame('My link', $this->field->getLinkText()); $this->assertSame('Click here to see what happens next', $this->field->getLinkDescription()); $this->assertTrue($this->field->getLinkTargetBlank()); } public function testGetLinkRelativeUrlReturnsEmptyStringOnInvalidPage() { $this->field->setValue(json_encode([ 'PageID' => 12345678 ])); $this->assertSame('', $this->field->getLinkRelativeUrl()); } public function testGetLinkTextIsTrimmed() { $this->field->setValue(json_encode([ 'Text' => ' My text ', ])); $this->assertSame('My text', $this->field->getLinkText()); } public function testGetSetShowLinkText() { $this->assertTrue($this->field->getShowLinkText(), 'Default to showing the link text field'); $this->field->setShowLinkText(false); $this->assertFalse($this->field->getShowLinkText(), 'Link text field can be disabled'); } } |