1+ <?php
2+
3+ namespace Test \Spreadsheet \Excel \Writer ;
4+
5+ use Spreadsheet_Excel_Writer_Worksheet ;
6+ use Spreadsheet_Excel_Writer_Workbook ;
7+
8+ class WorksheetTest extends \LegacyPHPUnit \TestCase
9+ {
10+ private $ workbook ;
11+ private $ worksheet ;
12+
13+ public function setUp ()
14+ {
15+ parent ::setUp ();
16+ $ this ->workbook = new Spreadsheet_Excel_Writer_Workbook ('php://memory ' );
17+ $ this ->worksheet = new Spreadsheet_Excel_Writer_Worksheet (0x0500 , 'Test ' , 0 , 0 , $ this ->workbook ->_url_format );
18+ }
19+
20+ public function tearDown ()
21+ {
22+ if ($ this ->workbook ) {
23+ $ this ->workbook ->close ();
24+ }
25+ parent ::tearDown ();
26+ }
27+
28+ /**
29+ * Test that _substituteCellref handles regex with dollar signs correctly
30+ */
31+ public function testSubstituteCellrefWithDollarSigns ()
32+ {
33+ $ method = new \ReflectionMethod ($ this ->worksheet , '_substituteCellref ' );
34+ $ method ->setAccessible (true );
35+
36+ // Test absolute cell reference
37+ $ result = $ method ->invoke ($ this ->worksheet , '$A$1 ' );
38+ $ this ->assertEquals (array (0 , 0 ), $ result );
39+
40+ // Test mixed references
41+ $ result = $ method ->invoke ($ this ->worksheet , 'A$1 ' );
42+ $ this ->assertEquals (array (0 , 0 ), $ result );
43+
44+ $ result = $ method ->invoke ($ this ->worksheet , '$A1 ' );
45+ $ this ->assertEquals (array (0 , 0 ), $ result );
46+
47+ // Test cell range with dollar signs
48+ $ result = $ method ->invoke ($ this ->worksheet , '$A$1:$B$2 ' );
49+ $ this ->assertEquals (array (0 , 0 , 1 , 1 ), $ result );
50+ }
51+
52+ /**
53+ * Test that _cellToRowcol handles regex with dollar signs correctly
54+ */
55+ public function testCellToRowcolWithDollarSigns ()
56+ {
57+ $ method = new \ReflectionMethod ($ this ->worksheet , '_cellToRowcol ' );
58+ $ method ->setAccessible (true );
59+
60+ // Test with absolute reference
61+ $ result = $ method ->invoke ($ this ->worksheet , '$A$1 ' );
62+ $ this ->assertEquals (array (0 , 0 ), $ result );
63+
64+ // Test with relative reference
65+ $ result = $ method ->invoke ($ this ->worksheet , 'B2 ' );
66+ $ this ->assertEquals (array (1 , 1 ), $ result );
67+
68+ // Test with mixed reference
69+ $ result = $ method ->invoke ($ this ->worksheet , '$C3 ' );
70+ $ this ->assertEquals (array (2 , 2 ), $ result );
71+ }
72+
73+ /**
74+ * Test that getData properly handles clearing _data property
75+ */
76+ public function testGetDataClearsDataProperty ()
77+ {
78+ // Access protected property
79+ $ property = new \ReflectionProperty ($ this ->worksheet , '_data ' );
80+ $ property ->setAccessible (true );
81+
82+ // Set some data
83+ $ testData = 'test data ' ;
84+ $ property ->setValue ($ this ->worksheet , $ testData );
85+
86+ // Call getData
87+ $ result = $ this ->worksheet ->getData ();
88+
89+ // Check that data was returned
90+ $ this ->assertEquals ($ testData , $ result );
91+
92+ // Check that _data is now null (not unset)
93+ $ this ->assertNull ($ property ->getValue ($ this ->worksheet ));
94+ }
95+ }
0 commit comments