Add tests

parent 0157384f
<phpunit bootstrap="./tests/FndTestBase.php">
<testsuites>
<testsuite>
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
<?hh
class ColTest extends FndTestBase {
public function testCompose(): void {
$col = <fnd:col />;
$rendered = $this->render($col);
$this->assertHasClass($rendered, 'column');
}
public function testSizing(): void {
$col = <fnd:col small={3} medium={5} large={1} />;
$rendered = $this->render($col);
$this->assertHasClass($rendered, 'small-3');
$this->assertHasClass($rendered, 'medium-5');
$this->assertHasClass($rendered, 'large-1');
}
public function testInvalidSizing(): void {
$col = <fnd:col small={0} />;
try {
$this->render($col);
$this->fail('Rendered with invalid column size');
} catch(InvariantException $e) {
$this->assertEquals(
'Small column size must be in the range 1-12',
$e->getMessage(),
);
}
$col->setAttribute('small', 13);
try {
$this->render($col);
$this->fail('Rendered with invalid column size');
} catch(InvariantException $e) {
$this->assertEquals(
'Small column size must be in the range 1-12',
$e->getMessage(),
);
}
$col = <fnd:col medium={0} />;
try {
$this->render($col);
$this->fail('Rendered with invalid column size');
} catch(InvariantException $e) {
$this->assertEquals(
'Medium column size must be in the range 1-12',
$e->getMessage(),
);
}
$col->setAttribute('medium', 13);
try {
$this->render($col);
$this->fail('Rendered with invalid column size');
} catch(InvariantException $e) {
$this->assertEquals(
'Medium column size must be in the range 1-12',
$e->getMessage(),
);
}
$col = <fnd:col large={0} />;
try {
$this->render($col);
$this->fail('Rendered with invalid column size');
} catch(InvariantException $e) {
$this->assertEquals(
'Large column size must be in the range 1-12',
$e->getMessage(),
);
}
$col->setAttribute('large', 13);
try {
$this->render($col);
$this->fail('Rendered with invalid column size');
} catch(InvariantException $e) {
$this->assertEquals(
'Large column size must be in the range 1-12',
$e->getMessage(),
);
}
}
public function testOffset(): void {
$col = <fnd:col small-offset={2} medium-offset={3} large-offset={4} />;
$rendered = $this->render($col);
$this->assertHasClass($rendered, 'small-offset-2');
$this->assertHasClass($rendered, 'medium-offset-3');
$this->assertHasClass($rendered, 'large-offset-4');
}
public function testInvalidOffset(): void {
$col = <fnd:col small-offset={0} />;
try {
$this->render($col);
$this->fail('Rendered with invalid offset size');
} catch(InvariantException $e) {
$this->assertEquals(
'Small offset size must be in the range 1-11',
$e->getMessage(),
);
}
$col->setAttribute('small-offset', 12);
try {
$this->render($col);
$this->fail('Rendered with invalid offset size');
} catch(InvariantException $e) {
$this->assertEquals(
'Small offset size must be in the range 1-11',
$e->getMessage(),
);
}
$col = <fnd:col medium-offset={0} />;
try {
$this->render($col);
$this->fail('Rendered with invalid offset size');
} catch(InvariantException $e) {
$this->assertEquals(
'Medium offset size must be in the range 1-11',
$e->getMessage(),
);
}
$col->setAttribute('medium-offset', 12);
try {
$this->render($col);
$this->fail('Rendered with invalid offset size');
} catch(InvariantException $e) {
$this->assertEquals(
'Medium offset size must be in the range 1-11',
$e->getMessage(),
);
}
$col = <fnd:col large-offset={0} />;
try {
$this->render($col);
$this->fail('Rendered with invalid offset size');
} catch(InvariantException $e) {
$this->assertEquals(
'Large offset size must be in the range 1-11',
$e->getMessage(),
);
}
$col->setAttribute('large-offset', 12);
try {
$this->render($col);
$this->fail('Rendered with invalid offset size');
} catch(InvariantException $e) {
$this->assertEquals(
'Large offset size must be in the range 1-11',
$e->getMessage(),
);
}
}
public function testEnd(): void {
$col = <fnd:col />;
$rendered = $this->render($col);
$this->assertNotHasClass($rendered, 'end');
$col = <fnd:col end={false} />;
$rendered = $this->render($col);
$this->assertNotHasClass($rendered, 'end');
$col = <fnd:col end={true} />;
$rendered = $this->render($col);
$this->assertHasClass($rendered, 'end');
}
}
<?hh
class FndTestBase extends PHPUnit_Framework_TestCase {
public function assertHasClass(XHPRoot $xhp, string $class) {
/* HH_FIXME[4053] Need union types */
$classes = $xhp->:class;
$classes = explode(' ', $classes);
$this->assertContains($class, $classes);
}
public function assertNotHasClass(XHPRoot $xhp, string $class) {
/* HH_FIXME[4053] Need union types */
$classes = $xhp->:class;
$classes = explode(' ', $classes);
$this->assertNotContains($class, $classes);
}
public function render(XHPRoot $xhp) {
$reflect = new ReflectionMethod($xhp, 'render');
$reflect->setAccessible(true);
return $reflect->invoke($xhp);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment