Drupal investigation

testIncompatibleData.php 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Consolidation\OutputFormatters;
  3. use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
  4. use Consolidation\OutputFormatters\StructuredData\PropertyList;
  5. use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
  6. class IncompatibleDataTests extends \PHPUnit_Framework_TestCase
  7. {
  8. protected $formatterManager;
  9. function setup() {
  10. $this->formatterManager = new FormatterManager();
  11. }
  12. protected function assertIncompatibleDataMessage($expected, $formatter, $data)
  13. {
  14. $e = new IncompatibleDataException($formatter, $data, $formatter->validDataTypes());
  15. $this->assertEquals($expected, $e->getMessage());
  16. }
  17. public function testIncompatibleData()
  18. {
  19. $tableFormatter = $this->formatterManager->getFormatter('table');
  20. $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, a string was provided.', $tableFormatter, 'a string');
  21. $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, an instance of Consolidation\OutputFormatters\FormatterManager was provided.', $tableFormatter, $this->formatterManager);
  22. $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, an array was provided.', $tableFormatter, []);
  23. $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, an instance of Consolidation\OutputFormatters\StructuredData\PropertyList was provided.', $tableFormatter, new PropertyList([]));
  24. }
  25. /**
  26. * @expectedException \Exception
  27. * @expectedExceptionMessage Undescribable data error: NULL
  28. */
  29. public function testUndescribableData()
  30. {
  31. $tableFormatter = $this->formatterManager->getFormatter('table');
  32. $data = $tableFormatter->validate(null);
  33. $this->assertEquals('Will throw before comparing.', $data);
  34. }
  35. /**
  36. * @expectedException \Exception
  37. * @expectedExceptionMessage Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, a string was provided.
  38. */
  39. public function testInvalidTableData()
  40. {
  41. $tableFormatter = $this->formatterManager->getFormatter('table');
  42. $data = $tableFormatter->validate('bad data type');
  43. $this->assertEquals('Will throw before comparing.', $data);
  44. }
  45. /**
  46. * @expectedException \Exception
  47. * @expectedExceptionMessage Data provided to Consolidation\OutputFormatters\Formatters\SectionsFormatter must be an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields. Instead, a string was provided.
  48. */
  49. public function testInvalidSectionsData()
  50. {
  51. $tableFormatter = $this->formatterManager->getFormatter('sections');
  52. $data = $tableFormatter->validate('bad data type');
  53. $this->assertEquals('Will throw before comparing.', $data);
  54. }
  55. }