Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Add tests for default and required attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Mar 5, 2015
1 parent 5a21102 commit 8ad7d2c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/AttributesTest.php
Expand Up @@ -17,6 +17,24 @@ protected function render(): XHPRoot {
}
}

class :test:required-attributes extends :x:element {
attribute
string mystring @required;

protected function render(): XHPRoot {
return <div>{$this->:mystring}</div>;
}
}

class :test:default-attributes extends :x:element {
attribute
string mystring = 'mydefault';

protected function render(): XHPRoot {
return <div>{$this->:mystring}</div>;
}
}

class EmptyTestClass {}
class StringableTestClass { public function __toString() { return __CLASS__; } }

Expand Down Expand Up @@ -194,4 +212,30 @@ public function testIncompatibleObjectAsObject(): void {
public function testPassingArrayAsVector(): void {
$x = <test:attribute-types myvector={[1,2,3]} />;
}

public function testProvidingRequiredAttributes(): void {
$x = <test:required-attributes mystring="herp" />;
$this->assertSame('herp', $x->:mystring);
$this->assertSame('<div>herp</div>', $x->toString());
}

/**
* @expectedException XHPAttributeRequiredException
*/
public function testOmittingRequiredAttributes(): void {
$x = <test:required-attributes />;
$this->assertNull($x->:mystring);
}

public function testProvidingDefaultAttributes(): void {
$x = <test:default-attributes mystring="herp" />;
$this->assertSame('herp', $x->:mystring);
$this->assertSame('<div>herp</div>', $x->toString());
}

public function testOmittingDefaultAttributes(): void {
$x = <test:default-attributes />;
$this->assertSame('mydefault', $x->:mystring);
$this->assertSame('<div>mydefault</div>', $x->toString());
}
}

0 comments on commit 8ad7d2c

Please sign in to comment.