class RestProcessorTest in Radioactivity 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/RestProcessorTest.php \Drupal\Tests\radioactivity\Unit\RestProcessorTest
@coversDefaultClass \Drupal\radioactivity\RestProcessor @group radioactivity
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\radioactivity\Unit\RestProcessorTest
Expanded class hierarchy of RestProcessorTest
File
- tests/
src/ Unit/ RestProcessorTest.php, line 13
Namespace
Drupal\Tests\radioactivity\UnitView source
class RestProcessorTest extends UnitTestCase {
/**
* The Rest Processor under test.
*
* @var \Drupal\radioactivity\RestProcessor
*/
private $sut;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$workDirectory = vfsStream::setup('radioactivity');
$this->sut = new RestProcessor([
'payload_file' => $workDirectory
->url() . '/radioactivity-payload.json',
]);
}
/**
* @covers ::processData
*/
public function testProcessData() {
$data = '[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}]';
$response = $this->sut
->processData($data);
$this
->assertEquals('{"status":"ok","message":"Inserted."}', $response);
}
/**
* @covers ::processData
*/
public function testProcessFaultyData() {
$data = '[{"fn":"field_ra","et":"node","id":"66","e":10}]';
$response = $this->sut
->processData($data);
$this
->assertEquals('{"status":"error","message":"Invalid json."}', $response);
}
/**
* @covers ::getData
*/
public function testGetData() {
$data = '[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}]';
$this->sut
->processData($data);
$response = $this->sut
->getData();
$this
->assertEquals('[[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}]]', $response);
}
/**
* @covers ::getData
*/
public function testGetMultiData() {
$data = '[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}]';
$this->sut
->processData($data);
$data = '[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"87654321"}]';
$this->sut
->processData($data);
$response = $this->sut
->getData();
$this
->assertEquals('[[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}],' . PHP_EOL . '[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"87654321"}]]', $response);
}
/**
* @covers ::getData
*/
public function testGetEmptyData() {
$response = $this->sut
->getData();
$this
->assertEquals('[]', $response);
}
/**
* @covers ::clearData
*/
public function testClearData() {
$data = '[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}]';
$this->sut
->processData($data);
$response = $this->sut
->getData();
$this
->assertEquals('[[{"fn":"field_ra","et":"node","id":"66","e":10,"h":"12345678"}]]', $response);
$response = $this->sut
->clearData();
$this
->assertEquals('{"status":"ok","message":"Cleared."}', $response);
$response = $this->sut
->getData();
$this
->assertEquals('[]', $response);
}
/**
* @covers ::error
*/
public function testErrorResponse() {
$response = $this->sut
->error();
$this
->assertEquals('{"status":"error","message":"Nothing to do."}', $response);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RestProcessorTest:: |
private | property | The Rest Processor under test. | |
RestProcessorTest:: |
protected | function |
Overrides UnitTestCase:: |
|
RestProcessorTest:: |
public | function | @covers ::clearData | |
RestProcessorTest:: |
public | function | @covers ::error | |
RestProcessorTest:: |
public | function | @covers ::getData | |
RestProcessorTest:: |
public | function | @covers ::getData | |
RestProcessorTest:: |
public | function | @covers ::getData | |
RestProcessorTest:: |
public | function | @covers ::processData | |
RestProcessorTest:: |
public | function | @covers ::processData | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |