| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Wikibase\DataModel\Tests\Entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Wikibase\DataModel\Entity\EntityRedirect; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Wikibase\DataModel\Entity\ItemId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Wikibase\DataModel\Entity\PropertyId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @covers Wikibase\DataModel\Entity\EntityRedirect | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @group Wikibase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @group WikibaseDataModel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @licence GNU GPL v2+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @author Daniel Kinzler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class EntityRedirectTest extends \PHPUnit_Framework_TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	public function testConstruction() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$entityId = new ItemId( 'Q123' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		$targetId = new ItemId( 'Q345' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$redirect = new EntityRedirect( $entityId, $targetId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		$this->assertEquals( $entityId, $redirect->getEntityId(), '$redirect->getEntityId()' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		$this->assertEquals( $targetId, $redirect->getTargetId(), '$redirect->getTargetId()' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	public function testConstruction_baseType() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		$this->setExpectedException( 'InvalidArgumentException' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		$entityId = new ItemId( 'Q123' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$targetId = new PropertyId( 'P345' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		new EntityRedirect( $entityId, $targetId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 	public function equalsProvider() { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 		$q123 = new ItemId( 'Q123' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 		$q345 = new ItemId( 'Q345' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 		$q567 = new ItemId( 'Q567' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		$q123_345 = new EntityRedirect( $q123, $q345 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 		$p123 = new PropertyId( 'P123' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 		$p345 = new PropertyId( 'P345' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 		$p123_345 = new EntityRedirect( $p123, $p345 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 		return array( | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 			'same' => array( $q123_345, $q123_345, true ), | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 			'equal' => array( $q123_345, new EntityRedirect( $q123, $q345 ), true ), | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 			'different base' => array( $q123_345, new EntityRedirect( $q567, $q345 ), false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 			'different target' => array( $q123_345, new EntityRedirect( $q123, $q567 ), false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 			'different entity type' => array( $q123_345, $p123_345, false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 			'different number' => array( $q123_345, new EntityRedirect( $q345, $q123 ), false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 			'null' => array( $q123_345, null, false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 			'string' => array( $q123_345, 'foo', false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 			'id' => array( $q123_345, $q123, false ), | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * @dataProvider equalsProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @param EntityRedirect $a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * @param mixed $b | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * @param bool $expected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	public function testEquals( $a, $b, $expected ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$this->assertEquals( $expected, $a->equals( $b ), '$a->equals( $b )' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		if ( $b instanceof EntityRedirect ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			$this->assertEquals( $expected, $b->equals( $a ), '$b->equals( $a )' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  |