silverstripe-framework/admin/tests/CampaignAdminTest.php

38 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2016-10-14 03:30:05 +02:00
namespace SilverStripe\Admin\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Admin\CampaignAdmin;
2016-10-14 03:30:05 +02:00
use ReflectionClass;
class CampaignAdminTest extends SapphireTest
{
2016-11-13 08:35:43 +01:00
protected $extraDataObjects = [
CampaignAdminTest\InvalidChangeSet::class,
];
/**
* 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
2016-11-13 08:35:43 +01:00
* @return mixed
*/
2016-11-13 08:35:43 +01:00
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-11-13 08:35:43 +01:00
public function testInvalidDataHandling() {
$changeset = new CampaignAdminTest\InvalidChangeSet();
$admin = new CampaignAdmin();
$result = $this->callProtectedMethod($admin, 'getChangeSetResource', [$changeset] );
$this->assertEquals('Corrupt database! bad data' , $result['Description']);
}
}