1+ <?php
2+
3+
4+ namespace Wikibase \DataModel \Tests \Statement ;
5+
6+ use DataValues \StringValue ;
7+ use InvalidArgumentException ;
8+ use Wikibase \DataModel \Entity \PropertyId ;
9+ use Wikibase \DataModel \Snak \PropertyNoValueSnak ;
10+ use Wikibase \DataModel \Snak \PropertyValueSnak ;
11+ use Wikibase \DataModel \Statement \Statement ;
12+ use Wikibase \DataModel \Statement \StatementGroup ;
13+
14+ /**
15+ * @covers Wikibase\DataModel\Statement\StatementGroup
16+ *
17+ * @licence GNU GPL v2+
18+ * @author Bene* < benestar.wikimedia@gmail.com >
19+ */
20+ class StatementGroupTest extends \PHPUnit_Framework_TestCase {
21+
22+ public function testConstructor_numericId () {
23+ $ statementGroup = new StatementGroup ( 42 );
24+ $ this ->assertEquals ( new PropertyId ( 'P42 ' ), $ statementGroup ->getPropertyId () );
25+ }
26+
27+ public function testConstructor_propertyId () {
28+ $ statementGroup = new StatementGroup ( new PropertyId ( 'P42 ' ) );
29+ $ this ->assertEquals ( new PropertyId ( 'P42 ' ), $ statementGroup ->getPropertyId () );
30+ }
31+
32+ /**
33+ * @expectedException InvalidArgumentException
34+ */
35+ public function testConstructor_invalidArgument () {
36+ new StatementGroup ( 'foo ' );
37+ }
38+
39+ public function testAddStatement_validPropertyId () {
40+ $ statementGroup = new StatementGroup ( 42 );
41+ $ statement = new Statement ( new PropertyNoValueSnak ( 42 ) );
42+ $ statementGroup ->addStatement ( $ statement );
43+
44+ $ this ->assertEquals ( array ( $ statement ), $ statementGroup ->getByRank ( Statement::RANK_NORMAL ) );
45+ }
46+
47+ /**
48+ * @expectedException InvalidArgumentException
49+ */
50+ public function testAddStatement_invalidPropertyId () {
51+ $ statementGroup = new StatementGroup ( 42 );
52+ $ statement = new Statement ( new PropertyNoValueSnak ( 12 ) );
53+ $ statementGroup ->addStatement ( $ statement );
54+ }
55+
56+ public function testAddStatements () {
57+ $ statementGroup = new StatementGroup ( 42 );
58+ $ foo = new Statement ( new PropertyValueSnak ( 42 , new StringValue ( 'foo ' ) ) );
59+ $ bar = new Statement ( new PropertyValueSnak ( 42 , new StringValue ( 'foo ' ) ) );
60+ $ baz = new Statement ( new PropertyValueSnak ( 42 , new StringValue ( 'foo ' ) ) );
61+ $ baz ->setRank ( Statement::RANK_PREFERRED );
62+ $ statementGroup ->addStatements ( array ( $ foo , $ bar , $ baz ) );
63+
64+ $ this ->assertEquals ( array (), $ statementGroup ->getByRank ( Statement::RANK_DEPRECATED ) );
65+ $ this ->assertEquals ( array ( $ foo , $ bar ), $ statementGroup ->getByRank ( Statement::RANK_NORMAL ) );
66+ $ this ->assertEquals ( array ( $ baz ), $ statementGroup ->getByRank ( Statement::RANK_PREFERRED ) );
67+ }
68+
69+ /**
70+ * @expectedException InvalidArgumentException
71+ */
72+ public function testAddStatements_invalidPropertyIds () {
73+ $ statementGroup = new StatementGroup ( 42 );
74+ $ foo = new Statement ( new PropertyValueSnak ( 42 , new StringValue ( 'foo ' ) ) );
75+ $ bar = new Statement ( new PropertyValueSnak ( 42 , new StringValue ( 'foo ' ) ) );
76+ $ baz = new Statement ( new PropertyValueSnak ( 12 , new StringValue ( 'foo ' ) ) );
77+ $ statementGroup ->addStatements ( array ( $ foo , $ bar , $ baz ) );
78+ }
79+
80+ /**
81+ * @expectedException InvalidArgumentException
82+ */
83+ public function testAddStatements_noStatement () {
84+ $ statementGroup = new StatementGroup ( 42 );
85+ $ statement = new Statement ( new PropertyNoValueSnak ( 12 ) );
86+ $ statementGroup ->addStatements ( array ( $ statement , 'foo ' ) );
87+ }
88+
89+ /**
90+ * @expectedException InvalidArgumentException
91+ */
92+ public function testAddStatements_noArray () {
93+ $ statementGroup = new StatementGroup ( 42 );
94+ $ statementGroup ->addStatements ( 'foo ' );
95+ }
96+
97+ }
0 commit comments