function testTableWithWordWrapping()
{
$options = new FormatterOptions();
- $options->setWidth(42);
$data = [
[
$data = new RowsOfFields($data);
$expected = <<<EOT
- ------------------- --------------------
- First Second
- ------------------- --------------------
- This is a really This is the second
- long cell that column of the same
- contains a lot of table. It is also
- data. When it is very long, and
- rendered, it should be wrapped
- should be wrapped across multiple
- across multiple lines, just like
- lines. the first column.
- ------------------- --------------------
+ ------------------ --------------------
+ First Second
+ ------------------ --------------------
+ This is a really This is the second
+ long cell that column of the same
+ contains a lot table. It is also
+ of data. When it very long, and
+ is rendered, it should be wrapped
+ should be across multiple
+ wrapped across lines, just like
+ multiple lines. the first column.
+ ------------------ --------------------
+EOT;
+ $options->setWidth(42);
+ $this->assertFormattedOutputMatches($expected, 'table', $data, $options);
+
+ $expected = <<<EOT
+ ----------------------------------- ---------------------------------------
+ First Second
+ ----------------------------------- ---------------------------------------
+ This is a really long cell that This is the second column of the same
+ contains a lot of data. When it table. It is also very long, and
+ is rendered, it should be wrapped should be wrapped across multiple
+ across multiple lines. lines, just like the first column.
+ ----------------------------------- ---------------------------------------
+EOT;
+ $options->setWidth(78);
+ $this->assertFormattedOutputMatches($expected, 'table', $data, $options);
+ }
+
+ function testWrappingLotsOfColumns()
+ {
+ $options = new FormatterOptions();
+
+ $data = [
+ [
+ 'id' => '4d87b545-b4c3-4ece-9908-20c5c5e67e81',
+ 'name' => '123456781234567812345678123456781234567812345678',
+ 'service_level' => 'business',
+ 'framework' => 'wordpress-network',
+ 'owner' => '8558a08d-8059-45f6-9c4b-908299a025ee',
+ 'created' => '2017-05-24 19:28:45',
+ 'memberships' => 'b3a42ba5-755d-42ca-9109-21bde32809d0: Team,9bfaaf50-ece3-4460-acb8-dc1b8dd536e8: pantheon-engineering-canary-sites',
+ 'frozen' => 'false',
+ ],
+ [
+ 'id' => '3d87b545-b4c3-4ece-9908-20c5c5e67e80',
+ 'name' => 'build-tools-136',
+ 'service_level' => 'free',
+ 'framework' => 'drupal8',
+ 'owner' => '7558a08d-8059-45f6-9c4b-908299a025ef',
+ 'created' => '2017-05-24 19:28:45',
+ 'memberships' => '5ae1fa30-8cc4-4894-8ca9-d50628dcba17: ci-for-drupal-8-composer',
+ 'frozen' => 'false',
+ ]
+ ];
+ $data = new RowsOfFields($data);
+
+ $expected = <<<EOT
+ ------------- ---------------- --------------- ----------- ------------- --------- ------------------------------------ --------
+ Id Name Service_level Framework Owner Created Memberships Frozen
+ ------------- ---------------- --------------- ----------- ------------- --------- ------------------------------------ --------
+ 4d87b545-b4 12345678123456 business wordp 8558a08d-80 2017-0 b3a42ba5-755d-42ca-9109-21bde32809 false
+ c3-4ece-990 78123456781234 ress- 59-45f6-9c4 5-24 d0:
+ 8-20c5c5e67 56781234567812 netwo b-908299a02 19:28: Team,9bfaaf50-ece3-4460-acb8-dc1b8
+ e81 345678 rk 5ee 45 dd536e8:
+ pantheon-engineering-canary-sites
+ 3d87b545-b4 build-tools-13 free drupa 7558a08d-80 2017-0 5ae1fa30-8cc4-4894-8ca9-d50628dcba false
+ c3-4ece-990 6 l8 59-45f6-9c4 5-24 17: ci-for-drupal-8-composer
+ 8-20c5c5e67 b-908299a02 19:28:
+ e80 5ef 45
+ ------------- ---------------- --------------- ----------- ------------- --------- ------------------------------------ --------
+EOT;
+
+ $options->setWidth(125);
+ $this->assertFormattedOutputMatches($expected, 'table', $data, $options);
+ }
+
+ function testTableWithWordWrapping2()
+ {
+ $options = new FormatterOptions();
+
+ $data = [
+ [
+ 'id' => 42,
+ 'vid' => 321,
+ 'description' => 'Life, the Universe and Everything.',
+ ],
+ [
+ 'id' => 13,
+ 'vid' => 789,
+ 'description' => 'Why is six afraid of seven?',
+ ],
+ ];
+ $data = new RowsOfFields($data);
+ $expected = <<<EOT
+ ---- ----- -----------------------------
+ Id Vid Description
+ ---- ----- -----------------------------
+ 42 321 Life, the Universe and
+ Everything.
+ 13 789 Why is six afraid of seven?
+ ---- ----- -----------------------------
+EOT;
+ $options->setWidth(42);
+ $this->assertFormattedOutputMatches($expected, 'table', $data, $options);
+ }
+
+ function testTableWithWordWrapping3()
+ {
+ $options = new FormatterOptions();
+ $data = [
+ 'name' => 'Rex',
+ 'species' => 'dog',
+ 'food' => 'kibble',
+ 'legs' => '4',
+ 'description' => 'Rex is a very good dog, Brett. He likes kibble, and has four legs.',
+ ];
+ $data = new PropertyList($data);
+
+ $expected = <<<EOT
+ ------------- -------------------------
+ Name Rex
+ Species dog
+ Food kibble
+ Legs 4
+ Description Rex is a very good dog,
+ Brett. He likes kibble,
+ and has four legs.
+ ------------- -------------------------
+EOT;
+ $options->setWidth(42);
+ $this->assertFormattedOutputMatches($expected, 'table', $data, $options);
+ }
+
+ function testTableWithWordWrapping4()
+ {
+ $options = new FormatterOptions();
+
+ $data = [
+ 'name' => ['label' => 'Name', 'sep' => ':', 'value' => 'Rex', ],
+ 'species' => ['label' => 'Species', 'sep' => ':', 'value' => 'dog', ],
+ 'food' => ['label' => 'Food', 'sep' => ':', 'value' => 'kibble', ],
+ 'legs' => ['label' => 'Legs', 'sep' => ':', 'value' => '4', ],
+ 'description' => ['label' => 'Description', 'sep' => ':', 'value' => 'Rex is a very good dog, Brett. He likes kibble, and has four legs.', ],
+ ];
+ $data = new RowsOfFields($data);
+ $expected = <<<EOT
+ ------------- ----- -----------------------------------------------------
+ Label Sep Value
+ ------------- ----- -----------------------------------------------------
+ Name : Rex
+ Species : dog
+ Food : kibble
+ Legs : 4
+ Description : Rex is a very good dog, Brett. He likes kibble, and
+ has four legs.
+ ------------- ----- -----------------------------------------------------
+EOT;
+ $options->setWidth(78);
+ $this->assertFormattedOutputMatches($expected, 'table', $data, $options);
+ }
+
+ function testTableWithWordWrapping5()
+ {
+ $options = new FormatterOptions();
+ $data = [
+ 'name' => ['Name', ':', 'Rex', ],
+ 'species' => ['Species', ':', 'dog', ],
+ 'food' => ['Food', ':', 'kibble', ],
+ 'legs' => ['Legs', ':', '4', ],
+ 'description' => ['Description', ':', 'Rex is a very good dog, Brett. He likes kibble, and has four legs.', ],
+ ];
+ $data = new RowsOfFields($data);
+ $expected = <<<EOT
+ Name : Rex
+ Species : dog
+ Food : kibble
+ Legs : 4
+ Description : Rex is a very good dog, Brett. He likes kibble, and has
+ four legs.
EOT;
+ $options->setWidth(78);
+ $options->setIncludeFieldLables(false);
+ $options->setTableStyle('compact');
$this->assertFormattedOutputMatches($expected, 'table', $data, $options);
}