silverstripe-framework/tests/php/View/SSViewerTest/TestFixture.php

71 lines
1.9 KiB
PHP
Raw Normal View History

2016-10-14 03:30:05 +02:00
<?php
namespace SilverStripe\View\Tests\SSViewerTest;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ViewableData;
/**
* A test fixture that will echo back the template item
*/
class TestFixture extends ViewableData
{
protected $name;
2016-10-14 03:30:05 +02:00
public function __construct($name = null)
{
$this->name = $name;
parent::__construct();
}
2016-10-14 03:30:05 +02:00
private function argedName($fieldName, $arguments)
{
$childName = $this->name ? "$this->name.$fieldName" : $fieldName;
if ($arguments) {
return $childName . '(' . implode(',', $arguments) . ')';
} else {
return $childName;
}
}
2016-10-14 03:30:05 +02:00
public function obj($fieldName, $arguments = null, $cache = false, $cacheName = null)
{
$childName = $this->argedName($fieldName, $arguments);
2016-10-14 03:30:05 +02:00
// Special field name Loop### to create a list
2022-04-14 03:12:59 +02:00
if (preg_match('/^Loop([0-9]+)$/', $fieldName ?? '', $matches)) {
$output = new ArrayList();
for ($i = 0; $i < $matches[1]; $i++) {
$output->push(new TestFixture($childName));
}
return $output;
} else {
2022-04-14 03:12:59 +02:00
if (preg_match('/NotSet/i', $fieldName ?? '')) {
return new ViewableData();
} else {
return new TestFixture($childName);
}
}
}
2016-10-14 03:30:05 +02:00
public function XML_val($fieldName, $arguments = null, $cache = false)
{
2022-04-14 03:12:59 +02:00
if (preg_match('/NotSet/i', $fieldName ?? '')) {
return '';
} else {
2022-04-14 03:12:59 +02:00
if (preg_match('/Raw/i', $fieldName ?? '')) {
return $fieldName;
} else {
return '[out:' . $this->argedName($fieldName, $arguments) . ']';
}
}
}
2016-10-14 03:30:05 +02:00
public function hasValue($fieldName, $arguments = null, $cache = true)
{
return (bool)$this->XML_val($fieldName, $arguments);
}
2016-10-14 03:30:05 +02:00
}