Skip to content

Commit

Permalink
Complete uncompleted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ejdamm committed Mar 10, 2018
1 parent dbdc52c commit 1caa5f9
Showing 1 changed file with 45 additions and 29 deletions.
74 changes: 45 additions & 29 deletions tests/ChartJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class ChartJsTest extends \PHPUnit_Framework_TestCase
*/
const HTML_TAG_PATTERN = '/^<canvas ("[^"]*"|\'[^\']*\'|[^\'">])*><\/canvas>$/';

/**
* @var string
*/
const HTML_ATTRIBUTES_PATTERN = '/class="([^"]+)"/';

/**
* @var string
*/
const HTML_ID_PATTERN = '/id="chartjs_([^"]+)"/';

/**
* @var string
*/
Expand All @@ -25,6 +35,11 @@ class ChartJsTest extends \PHPUnit_Framework_TestCase
*/
const DATA_TYPE_PATTERN = '/data\-chartjs=\'([^ ]+)\'/';

/**
* @var string
*/
const DATA_DATA_PATTERN = '/data\-data=\'([^ ]+)\'/';

/**
* @return void
*/
Expand All @@ -41,7 +56,7 @@ public function testRenderCanvasReturnsValidHtml()
{
$chart = new ChartJS();
$html = $chart->renderCanvas();
$this->assertNotFalse(preg_match(self::HTML_TAG_PATTERN,$html));
$this->assertNotFalse(preg_match(self::HTML_TAG_PATTERN, $html));
}

/**
Expand All @@ -67,13 +82,29 @@ public function testEchoChartEqualsRendering()
* @depends testRenderCanvasReturnsValidHtml
*/
public function testCanvasContainsAttributes()
{
$expected = 'test_id';
$chart = new ChartJS(null, null, null, ['class' => $expected]);
$html = $chart->renderCanvas();
$matches = [];
$this->assertNotFalse(preg_match(self::HTML_ATTRIBUTES_PATTERN, $html ,$matches));
$result = isset($matches[1]) ? $matches[1] : null;
$this->assertEquals($expected, $result);
}

/**
* @covers ::renderCanvas
* @covers ::renderAttributes
* @depends testConstruct
* @depends testRenderCanvasReturnsValidHtml
*/
public function testCanvasAutogenerateId()
{
$chart = new ChartJS();
$html = $chart->renderCanvas();
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$matches = [];
$this->assertNotFalse(preg_match(self::HTML_ID_PATTERN, $html ,$matches));
$this->assertCount(2, $matches);
}

/**
Expand All @@ -88,7 +119,7 @@ public function testCanvasContainsOptions()
$chart = new ChartJS(null, null, $expected);
$html = $chart->renderCanvas();
$matches = [];
$this->assertNotFalse(preg_match(self::DATA_OPTIONS_PATTERN,$html ,$matches));
$this->assertNotFalse(preg_match(self::DATA_OPTIONS_PATTERN, $html ,$matches));
$result = isset($matches[1]) ? json_decode($matches[1]) : null;
$this->assertEquals($expected, $result);
}
Expand All @@ -104,7 +135,7 @@ public function testCanvasContainsType()
$chart = new ChartJS($expected);
$html = $chart->renderCanvas();
$matches = [];
$this->assertNotFalse(preg_match(self::DATA_TYPE_PATTERN,$html ,$matches));
$this->assertNotFalse(preg_match(self::DATA_TYPE_PATTERN, $html ,$matches));
$result = isset($matches[1]) ? $matches[1] : null;
$this->assertEquals($expected, $result);
}
Expand All @@ -115,30 +146,15 @@ public function testCanvasContainsType()
* @depends testConstruct
* @depends testRenderCanvasReturnsValidHtml
*/
public function testCanvasContainsLabels()
public function testCanvasContainsData()
{
$chart = new ChartJS();
$html = $chart->renderCanvas();
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers ::renderCanvas
* @covers ::renderData
* @depends testConstruct
* @depends testRenderCanvasReturnsValidHtml
*/
public function testCanvasContainsDatasets()
{
$chart = new ChartJS();
$expected = 'test';
$chart = new ChartJS(null, $expected);
$html = $chart->renderCanvas();
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$matches = [];
$this->assertNotFalse(preg_match(self::DATA_DATA_PATTERN, $html ,$matches));
$result = isset($matches[1]) ? json_decode($matches[1]) : null;
$this->assertEquals($expected, $result);
}

}

0 comments on commit 1caa5f9

Please sign in to comment.