| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare( strict_types = 1 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace ModernTimeline\Tests\Unit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use ModernTimeline\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use ModernTimeline\EventExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use ModernTimeline\ResultFacade\PropertyValueCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use ModernTimeline\ResultFacade\Subject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use ModernTimeline\ResultFacade\SubjectCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use SMW\DIWikiPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use SMW\Query\PrintRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use SMWDITime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @covers \ModernTimeline\EventExtractor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class EventExtractorTest extends TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	public function testEmptySubjectCollection() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$this->assertExtractsEvents( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			[], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			new SubjectCollection() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	private function assertExtractsEvents( array $expectedEvents, SubjectCollection $subjects ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 			$expectedEvents, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			( new EventExtractor( [ 'image property' => '' ] ) )->extractEvents( $subjects ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 	public function testOnlySubjectsWithNoValues() { | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		$this->assertExtractsEvents( | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 			[], | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 			new SubjectCollection( | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 				new Subject( | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 					$this->newDiWikiPage(), | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 					[] | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 				) | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 			) | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	private function newDiWikiPage( string $pageName = 'Some page' ): DIWikiPage { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$page = $this->createMock( DIWikiPage::class ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$page->method( 'getTitle' )->willReturn( Title::newFromText( $pageName ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		return $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	public function testSingleSubjectWithStartDate() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$subject = new Subject( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			$this->newDiWikiPage(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 				$this->newStartDateValueCollection() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$this->assertExtractsEvents( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 				new Event( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 					$subject, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 					$this->newStartDate(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 					null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 				) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			new SubjectCollection( $subject ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	private function newStartDateValueCollection(): PropertyValueCollection { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		return new PropertyValueCollection( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			$this->newDatePrintRequestWithLabel( 'Has date' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 				$this->newStartDate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	private function newDatePrintRequestWithLabel( string $label ): PrintRequest { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		$pr = $this->createMock( PrintRequest::class ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$pr->method( 'getLabel' )->willReturn( $label ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$pr->method( 'getTypeID' )->willReturn( '_dat' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		return $pr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	private function newStartDate(): SMWDITime { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		return new SMWDITime( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			SMWDITime::CM_GREGORIAN, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			2019, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			8, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			2, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			16, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			7, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			42 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 105 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |  |