2016-09-23 01:05:33 +02:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Admin\Tests;
|
|
|
|
|
2016-09-23 01:05:33 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Admin\CampaignAdmin;
|
2016-10-14 03:30:05 +02:00
|
|
|
use ReflectionClass;
|
|
|
|
|
2016-09-23 01:05:33 +02:00
|
|
|
class CampaignAdminTest extends SapphireTest
|
|
|
|
{
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $extraDataObjects = [
|
|
|
|
CampaignAdminTest\InvalidChangeSet::class,
|
|
|
|
];
|
2016-09-23 01:05:33 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Call a protected method on an object via reflection
|
|
|
|
*
|
|
|
|
* @param object $object The object to call the method on
|
|
|
|
* @param string $method The name of the method
|
|
|
|
* @param array $args The arguments to pass to the method
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
protected function callProtectedMethod($object, $method, $args = [])
|
|
|
|
{
|
|
|
|
$class = new ReflectionClass(get_class($object));
|
|
|
|
$methodObj = $class->getMethod($method);
|
|
|
|
$methodObj->setAccessible(true);
|
|
|
|
return $methodObj->invokeArgs($object, $args);
|
|
|
|
}
|
2016-09-23 01:05:33 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testInvalidDataHandling()
|
|
|
|
{
|
|
|
|
$changeset = new CampaignAdminTest\InvalidChangeSet();
|
|
|
|
$admin = new CampaignAdmin();
|
2016-09-23 01:05:33 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$result = $this->callProtectedMethod($admin, 'getChangeSetResource', [$changeset]);
|
|
|
|
$this->assertEquals('Corrupt database! bad data', $result['Description']);
|
|
|
|
}
|
2016-09-23 01:05:33 +02:00
|
|
|
}
|