| 
									
										
										
										
											2017-09-22 05:49:38 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace PhpOffice\PhpSpreadsheetTests\Reader; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-10 14:44:55 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Document\Properties; | 
					
						
							| 
									
										
										
										
											2017-12-17 07:34:40 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Reader\Xlsx; | 
					
						
							| 
									
										
										
										
											2019-05-30 08:38:04 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Shared\File; | 
					
						
							| 
									
										
										
										
											2017-11-08 15:48:01 +00:00
										 |  |  | use PHPUnit\Framework\TestCase; | 
					
						
							| 
									
										
										
										
											2017-09-22 05:49:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 15:48:01 +00:00
										 |  |  | class XlsxTest extends TestCase | 
					
						
							| 
									
										
										
										
											2017-09-22 05:49:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-10 14:44:55 +00:00
										 |  |  |     public function testLoadWorkbookProperties() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $filename = './data/Reader/XLSX/propertyTest.xlsx'; | 
					
						
							|  |  |  |         $reader = new Xlsx(); | 
					
						
							|  |  |  |         $spreadsheet = $reader->load($filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $properties = $spreadsheet->getProperties(); | 
					
						
							|  |  |  |         // Core Properties
 | 
					
						
							|  |  |  |         $this->assertEquals('Mark Baker', $properties->getCreator()); | 
					
						
							|  |  |  |         $this->assertEquals('Unit Testing', $properties->getTitle()); | 
					
						
							|  |  |  |         $this->assertEquals('Property Test', $properties->getSubject()); | 
					
						
							|  |  |  |         // Extended Properties
 | 
					
						
							|  |  |  |         $this->assertEquals('PHPOffice', $properties->getCompany()); | 
					
						
							|  |  |  |         $this->assertEquals('The Big Boss', $properties->getManager()); | 
					
						
							|  |  |  |         // Custom Properties
 | 
					
						
							|  |  |  |         $customProperties = $properties->getCustomProperties(); | 
					
						
							|  |  |  |         $this->assertInternalType('array', $customProperties); | 
					
						
							|  |  |  |         $customProperties = array_flip($customProperties); | 
					
						
							|  |  |  |         $this->assertArrayHasKey('Publisher', $customProperties); | 
					
						
							|  |  |  |         $this->assertTrue($properties->isCustomPropertySet('Publisher')); | 
					
						
							|  |  |  |         $this->assertEquals(Properties::PROPERTY_TYPE_STRING, $properties->getCustomPropertyType('Publisher')); | 
					
						
							|  |  |  |         $this->assertEquals('PHPOffice Suite', $properties->getCustomPropertyValue('Publisher')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 05:49:38 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Test load Xlsx file without cell reference. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testLoadXlsxWithoutCellReference() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $filename = './data/Reader/XLSX/without_cell_reference.xlsx'; | 
					
						
							| 
									
										
										
										
											2017-12-17 07:34:40 +00:00
										 |  |  |         $reader = new Xlsx(); | 
					
						
							| 
									
										
										
										
											2017-09-22 05:49:38 +00:00
										 |  |  |         $reader->load($filename); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-11-19 13:48:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Test load Xlsx file and use a read filter. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testLoadWithReadFilter() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $filename = './data/Reader/XLSX/without_cell_reference.xlsx'; | 
					
						
							|  |  |  |         $reader = new Xlsx(); | 
					
						
							|  |  |  |         $reader->setReadFilter(new OddColumnReadFilter()); | 
					
						
							|  |  |  |         $data = $reader->load($filename)->getActiveSheet()->toArray(); | 
					
						
							|  |  |  |         $ref = [1.0, null, 3.0, null, 5.0, null, 7.0, null, 9.0, null]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for ($i = 0; $i < 10; ++$i) { | 
					
						
							|  |  |  |             $this->assertEquals($ref, \array_slice($data[$i], 0, 10, true)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-30 10:23:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-30 09:42:00 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Test load Xlsx file with drawing having double attributes. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testLoadXlsxWithDoubleAttrDrawing() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-30 10:11:49 +00:00
										 |  |  |         if (version_compare(PHP_VERSION, '7.0.0', '<')) { | 
					
						
							|  |  |  |             $this->markTestSkipped('Only handled in PHP version >= 7.0.0'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-30 09:42:00 +00:00
										 |  |  |         $filename = './data/Reader/XLSX/double_attr_drawing.xlsx'; | 
					
						
							|  |  |  |         $reader = new Xlsx(); | 
					
						
							|  |  |  |         $reader->load($filename); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-30 08:38:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Test correct save and load xlsx files with empty drawings. | 
					
						
							|  |  |  |      * Such files can be generated by Google Sheets. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testLoadSaveWithEmptyDrawings() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $filename = __DIR__ . '/../../data/Reader/XLSX/empty_drawing.xlsx'; | 
					
						
							|  |  |  |         $reader = new Xlsx(); | 
					
						
							|  |  |  |         $excel = $reader->load($filename); | 
					
						
							|  |  |  |         $resultFilename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test'); | 
					
						
							|  |  |  |         $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($excel); | 
					
						
							|  |  |  |         $writer->save($resultFilename); | 
					
						
							|  |  |  |         $excel = $reader->load($resultFilename); | 
					
						
							|  |  |  |         // Fake assert. The only thing we need is to ensure the file is loaded without exception
 | 
					
						
							|  |  |  |         $this->assertNotNull($excel); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-22 05:49:38 +00:00
										 |  |  | } |