5 use InvalidArgumentException;
21 'slot_content_id' => 33,
22 'content_size' =>
'5',
23 'content_sha1' =>
'someHash',
24 'content_address' =>
'tt:456',
27 'slot_revision_id' =>
'2',
29 'role_name' =>
'myRole',
38 $this->assertTrue( $record->hasAddress() );
39 $this->assertTrue( $record->hasContentId() );
40 $this->assertTrue( $record->hasRevision() );
41 $this->assertTrue( $record->isInherited() );
42 $this->assertSame(
'A', $record->getContent()->getNativeData() );
43 $this->assertSame( 5, $record->getSize() );
44 $this->assertSame(
'someHash', $record->getSha1() );
46 $this->assertSame( 2, $record->getRevision() );
47 $this->assertSame( 1, $record->getOrigin() );
48 $this->assertSame(
'tt:456', $record->getAddress() );
49 $this->assertSame( 33, $record->getContentId() );
51 $this->assertSame(
'myRole', $record->getRole() );
56 'content_size' =>
null,
57 'content_sha1' =>
null,
58 'format_name' =>
function () {
61 'slot_revision_id' =>
'2',
63 'slot_content_id' =>
function () {
74 $this->assertTrue( $record->hasAddress() );
75 $this->assertTrue( $record->hasRevision() );
76 $this->assertFalse( $record->hasContentId() );
77 $this->assertFalse( $record->isInherited() );
78 $this->assertSame(
'A', $record->getContent()->getNativeData() );
79 $this->assertSame( 1, $record->getSize() );
80 $this->assertNotNull( $record->getSha1() );
82 $this->assertSame( 2, $record->getRevision() );
83 $this->assertSame( 2, $record->getRevision() );
84 $this->assertSame(
'tt:456', $record->getAddress() );
86 $this->assertSame(
'myRole', $record->getRole() );
92 $this->assertFalse( $record->hasAddress() );
93 $this->assertFalse( $record->hasContentId() );
94 $this->assertFalse( $record->hasRevision() );
95 $this->assertFalse( $record->isInherited() );
96 $this->assertFalse( $record->hasOrigin() );
97 $this->assertSame(
'A', $record->getContent()->getNativeData() );
98 $this->assertSame( 1, $record->getSize() );
99 $this->assertNotNull( $record->getSha1() );
101 $this->assertSame(
'myRole', $record->getRole() );
105 yield
'both null' => [
null, null ];
109 yield
'null content' => [ (
object)[],
null ];
124 $record->getContentId();
131 $record->getAddress();
136 yield
'unsaved' => [ $unsaved ];
140 yield
'inherited' => [ $inherited ];
164 yield [
'',
'phoiac9h4m842xq45sp7s6u21eteeq1' ];
165 yield [
'Lorem ipsum',
'hcr5u40uxr81d3nx89nvwzclfz6r9c5' ];
177 $this->assertSame( $hash, $record->getSha1() );
189 $row = $this->
makeRow( [
'slot_revision_id' => 7,
'slot_origin' => 7 ] );
195 $this->assertSame(
$parent->getContentId(), $inherited->getContentId() );
196 $this->assertSame(
$parent->getAddress(), $inherited->getAddress() );
197 $this->assertSame(
$parent->getContent(), $inherited->getContent() );
198 $this->assertTrue( $inherited->isInherited() );
199 $this->assertTrue( $inherited->hasOrigin() );
200 $this->assertFalse( $inherited->hasRevision() );
203 $this->assertFalse(
$parent->isInherited() );
204 $this->assertSame( 7,
$parent->getRevision() );
210 $inherited->getContentId(),
211 $inherited->getAddress(),
214 $this->assertSame(
$parent->getContentId(), $saved->getContentId() );
215 $this->assertSame(
$parent->getAddress(), $saved->getAddress() );
216 $this->assertSame(
$parent->getContent(), $saved->getContent() );
217 $this->assertTrue( $saved->isInherited() );
218 $this->assertTrue( $saved->hasRevision() );
219 $this->assertSame( 10, $saved->getRevision() );
222 $this->assertSame( 7,
$parent->getRevision() );
223 $this->assertFalse( $inherited->hasRevision() );
233 $this->assertFalse( $saved->isInherited() );
234 $this->assertTrue( $saved->hasOrigin() );
235 $this->assertTrue( $saved->hasRevision() );
236 $this->assertTrue( $saved->hasAddress() );
237 $this->assertTrue( $saved->hasContentId() );
238 $this->assertSame(
'theNewAddress', $saved->getAddress() );
239 $this->assertSame( 20, $saved->getContentId() );
240 $this->assertSame(
'A', $saved->getContent()->getNativeData() );
241 $this->assertSame( 10, $saved->getRevision() );
242 $this->assertSame( 10, $saved->getOrigin() );
245 $this->assertFalse( $unsaved->hasAddress() );
246 $this->assertFalse( $unsaved->hasContentId() );
247 $this->assertFalse( $unsaved->hasRevision() );
253 'content_address' =>
'address:1',
255 'slot_revision_id' => 1,
259 yield
'mismatching address' => [ 1, 10,
'address:BAD', $freshSlot ];
260 yield
'mismatching revision' => [ 5, 10,
'address:1', $freshSlot ];
261 yield
'mismatching content ID' => [ 1, 17,
'address:1', $freshSlot ];
263 $inheritedRow = $this->
makeRow( [
264 'content_id' =>
null,
265 'content_address' =>
null,
267 'slot_revision_id' => 1,
271 yield
'inherited, but no address' => [ 1, 10,
'address:2', $inheritedSlot ];
290 yield
'bad revision id' => [
'xyzzy', 5,
'address', $unsaved ];
291 yield
'bad content id' => [ 7,
'xyzzy',
'address', $unsaved ];
292 yield
'bad content address' => [ 7, 5, 77, $unsaved ];
309 $fail =
function () {
310 self::fail(
'There should be no need to actually load the content.' );
317 'content_size' => 100,
318 'content_sha1' =>
'hash-a',
319 'content_address' =>
'xxx:a1',
328 'content_size' => 100,
329 'content_sha1' =>
'hash-a',
330 'content_address' =>
'xxx:a1',
339 'content_size' => 100,
340 'content_sha1' =>
'hash-a',
341 'content_address' =>
null,
350 'content_size' => 100,
351 'content_sha1' =>
'hash-a',
352 'content_address' =>
'xxx:a2',
361 'content_size' => 100,
362 'content_sha1' =>
'hash-a',
363 'content_address' =>
'xxx:a1',
372 'content_size' => 200,
373 'content_sha1' =>
'hash-a',
374 'content_address' =>
'xxx:a2',
383 'content_size' => 100,
384 'content_sha1' =>
'hash-x',
385 'content_address' =>
'xxx:x1',
391 yield
'same instance' => [ $a100a1, $a100a1,
true ];
392 yield
'no address' => [ $a100a1, $a100null,
true ];
393 yield
'same address' => [ $a100a1, $a100a1b,
true ];
394 yield
'different address' => [ $a100a1, $a100a2,
true ];
395 yield
'different model' => [ $a100a1, $b100a1,
false ];
396 yield
'different size' => [ $a100a1, $a200a1,
false ];
397 yield
'different hash' => [ $a100a1, $a100x1,
false ];