| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SRF\Tests\vCard; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SRF\vCard\vCardFileExportPrinter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SRF\Tests\ResultPrinterReflector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @covers \SRF\vCard\vCardFileExportPrinter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @group semantic-result-formats | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license GNU GPL v2+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @since 3.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @author mwjames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class vCardFileExportPrinterTest extends \PHPUnit_Framework_TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	private $queryResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	private $resultPrinterReflector; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 	protected function setUp() { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 		parent::setUp(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 		$this->resultPrinterReflector = new ResultPrinterReflector(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 		$this->queryResult = $this->getMockBuilder( '\SMWQueryResult' ) | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 			->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 			->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	public function testCanConstruct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$this->assertInstanceOf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 			vCardFileExportPrinter::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			new vCardFileExportPrinter( 'vcard' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * @dataProvider filenameProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	public function testGetFileName( $filename, $searchlabel, $expected ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		$parameters = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			'filename' => $filename, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			'searchlabel' => $searchlabel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$instance = new vCardFileExportPrinter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			'vcard' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		$this->resultPrinterReflector->addParameters( $instance, $parameters ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			$expected, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			$instance->getFileName( $this->queryResult ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	public function testGetMimeType() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$instance = new vCardFileExportPrinter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			'vcard' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			'text/x-vcard', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			$instance->getMimeType( $this->queryResult ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	public function testGetResult_LinkOnNonFileOutput() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$link = $this->getMockBuilder( '\SMWInfolink' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		$link->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			->method( 'getText' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			->will( $this->returnValue( 'foo_link' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$this->queryResult->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			->method( 'getErrors' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			->will( $this->returnValue( [] ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$this->queryResult->expects( $this->any() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			->method( 'getCount' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			->will( $this->returnValue( 1 ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$this->queryResult->expects( $this->once() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			->method( 'getQueryLink' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			->will( $this->returnValue( $link ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$instance = new vCardFileExportPrinter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			'vcard' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			'foo_link', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			$instance->getResult( $this->queryResult, [], SMW_OUTPUT_HTML ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	public function filenameProvider() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		yield[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 			'', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 			'foo bar', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 			'foo_bar.vcf' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		yield[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 			'', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 			'foo.vcf' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		yield[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 			'foo.vcf', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 			'', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			'foo.vcf' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		yield[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			'foo bar.vcf', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 			'', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			'foo_bar.vcf' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 133 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 134 |  |  |  |