| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SMW\ApprovedRevs\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SMW\ApprovedRevs\PropertyAnnotator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SMW\DIProperty; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SMW\DIWikiPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @covers \SMW\ApprovedRevs\PropertyAnnotator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @group semantic-approved-revs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @license GNU GPL v2+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @since 1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class PropertyAnnotatorTest extends \PHPUnit_Framework_TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	private $servicesFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	private $logger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	protected function setUp() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$approvedByPropertyAnnotator = $this->getMockBuilder( '\SMW\ApprovedRevs\PropertyAnnotators\ApprovedByPropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		$approvedStatusPropertyAnnotator = $this->getMockBuilder( '\SMW\ApprovedRevs\PropertyAnnotators\ApprovedStatusPropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		$approvedDatePropertyAnnotator = $this->getMockBuilder( '\SMW\ApprovedRevs\PropertyAnnotators\ApprovedDatePropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$approvedRevPropertyAnnotator = $this->getMockBuilder( '\SMW\ApprovedRevs\PropertyAnnotators\ApprovedRevPropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		$this->servicesFactory = $this->getMockBuilder( '\SMW\ApprovedRevs\ServicesFactory' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$this->servicesFactory->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			->method( 'newApprovedByPropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			->will( $this->returnValue( $approvedByPropertyAnnotator ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$this->servicesFactory->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			->method( 'newApprovedStatusPropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			->will( $this->returnValue( $approvedStatusPropertyAnnotator ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$this->servicesFactory->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			->method( 'newApprovedDatePropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			->will( $this->returnValue( $approvedDatePropertyAnnotator ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$this->servicesFactory->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			->method( 'newApprovedRevPropertyAnnotator' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			->will( $this->returnValue( $approvedRevPropertyAnnotator ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$this->logger = $this->getMockBuilder( '\Psr\Log\NullLogger' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	public function testCanConstruct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->assertInstanceOf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			PropertyAnnotator::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			new PropertyAnnotator( $this->servicesFactory ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	public function testAddAnnotation() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$this->logger->expects( $this->once() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			->method( 'info' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		$semanticData->expects( $this->once() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			->method( 'getSubject' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			->will( $this->returnValue( DIWikiPage::newFromText( 'Foo' ) ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		$annotator = new PropertyAnnotator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			$this->servicesFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$annotator->setLogger( $this->logger ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$annotator->addAnnotation( $semanticData ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 	public function testCanNotAnnotate() { | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 		$this->logger->expects( $this->never() ) | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 			->method( 'info' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 		$subject = $this->getMockBuilder( '\SMW\DIWikiPage' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 		$semanticData->expects( $this->once() ) | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 			->method( 'getSubject' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 			->will( $this->returnValue( $subject ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  | 		$annotator = new PropertyAnnotator( | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 			$this->servicesFactory | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  | 		$annotator->setLogger( $this->logger ); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 		$annotator->addAnnotation( $semanticData ); | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 119 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |  |