|
1 | 1 | <?php |
2 | 2 |
|
3 | | -// require_once dirname( __FILE__ ) . '/IntegrationTestCase.php'; |
4 | | -// |
5 | | -// use Facebook\WebDriver\WebDriverBy; |
6 | | -// use Facebook\WebDriver\WebDriverExpectedCondition; |
7 | | -// |
8 | | -// class SettingsIntegrationTest extends IntegrationTestCase { |
9 | | -// public function set_up() { |
10 | | -// parent::set_up(); |
11 | | -// self::$driver->get( wordpress( '/wp-admin/options-media.php' ) ); |
12 | | -// } |
13 | | -// |
14 | | -// public function tear_down() { |
15 | | -// parent::tear_down(); |
16 | | -// clear_settings(); |
17 | | -// } |
18 | | -// |
19 | | -// public function test_title_presence() |
20 | | -// { |
21 | | -// $headings = self::$driver->findElements( WebDriverBy::cssSelector( 'h1, h2, h3, h4' ) ); |
22 | | -// $texts = array_map( 'innerText', $headings ); |
23 | | -// $this->assertContains( 'PNG and JPEG optimization', $texts ); |
24 | | -// } |
25 | | -// |
| 3 | +require_once dirname( __FILE__ ) . '/IntegrationTestCase.php'; |
| 4 | + |
| 5 | +class SettingsIntegrationTest extends IntegrationTestCase { |
| 6 | + public function tear_down() { |
| 7 | + parent::tear_down(); |
| 8 | + clear_settings(); |
| 9 | + clear_uploads(); |
| 10 | + } |
| 11 | + |
| 12 | + protected function get_enabled_sizes() { |
| 13 | + return array_map( function($checkbox) { |
| 14 | + return $checkbox->getAttribute( 'name' ); |
| 15 | + }, $this->find_all( 'input[type=checkbox][checked][name^=tinypng_sizes]' ) ); |
| 16 | + } |
| 17 | + |
| 18 | + public function test_settings_should_contain_title() { |
| 19 | + $this->visit( '/wp-admin/options-media.php' ); |
| 20 | + |
| 21 | + $headings = array_map( function($heading) { |
| 22 | + return $heading->getText(); |
| 23 | + }, $this->find_all( 'h2, h3' ) ); |
| 24 | + |
| 25 | + $this->assertContains( 'JPEG and PNG optimization', $headings ); |
| 26 | + } |
| 27 | + |
| 28 | + public function test_settings_should_show_notice_if_key_is_missing() { |
| 29 | + $this->visit( '/wp-admin/options-media.php' ); |
| 30 | + |
| 31 | + $this->assertStringEndsWith( |
| 32 | + 'options-media.php#tiny-compress-images', |
| 33 | + $this->find( '.error a' )->getAttribute( 'href' ) |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + public function test_settings_should_not_show_notice_if_key_is_set() { |
| 38 | + $this->set_api_key( 'PNG123' ); |
| 39 | + $this->visit( '/wp-admin/options-media.php' ); |
| 40 | + |
| 41 | + $this->assertEquals( 0, count( $this->find_all( '.error a' ) ) ); |
| 42 | + } |
| 43 | + |
| 44 | + public function test_settings_should_enable_all_sizes_by_default() { |
| 45 | + $enabled_sizes = $this->get_enabled_sizes(); |
| 46 | + |
| 47 | + $this->assertContains( 'tinypng_sizes[0]', $enabled_sizes ); |
| 48 | + $this->assertContains( 'tinypng_sizes[thumbnail]', $enabled_sizes ); |
| 49 | + $this->assertContains( 'tinypng_sizes[medium]', $enabled_sizes ); |
| 50 | + $this->assertContains( 'tinypng_sizes[large]', $enabled_sizes ); |
| 51 | + } |
| 52 | + |
| 53 | + public function test_settings_should_persist_enabled_sizes() { |
| 54 | + $this->find( '#tinypng_sizes_medium' )->click(); |
| 55 | + $this->find( '#tinypng_sizes_0' )->click(); |
| 56 | + $this->find( 'form' )->submit(); |
| 57 | + |
| 58 | + $enabled_sizes = $this->get_enabled_sizes(); |
| 59 | + |
| 60 | + $this->assertNotContains( 'tinypng_sizes[0]', $enabled_sizes ); |
| 61 | + $this->assertContains( 'tinypng_sizes[thumbnail]', $enabled_sizes ); |
| 62 | + $this->assertNotContains( 'tinypng_sizes[medium]', $enabled_sizes ); |
| 63 | + $this->assertContains( 'tinypng_sizes[large]', $enabled_sizes ); |
| 64 | + } |
| 65 | + |
| 66 | + public function test_settings_should_persist_all_disabled_sizes() { |
| 67 | + $checkboxes = $this->find_all( |
| 68 | + 'input[type=checkbox][checked][name^=tinypng_sizes]' |
| 69 | + ); |
| 70 | + |
| 71 | + foreach ( $checkboxes as $checkbox ) { |
| 72 | + $checkbox->click(); |
| 73 | + } |
| 74 | + |
| 75 | + $this->find( 'form' )->submit(); |
| 76 | + |
| 77 | + $enabled_sizes = $this->get_enabled_sizes(); |
| 78 | + $this->assertEquals( 0, count( $enabled_sizes ) ); |
| 79 | + } |
| 80 | + |
26 | 81 | // public function test_api_key_input_presence() { |
27 | 82 | // $elements = self::$driver->findElements( WebDriverBy::name( 'tinypng_api_key' ) ); |
28 | 83 | // $this->assertEquals( 1, count( $elements ) ); |
29 | 84 | // } |
30 | | -// |
31 | | -// public function test_should_show_notice_if_no_api_key_is_set() { |
32 | | -// $element = self::$driver->findElement( WebDriverBy::cssSelector( '.error a' ) ); |
33 | | -// $this->assertStringEndsWith( 'options-media.php#tiny-compress-images', $element->getAttribute( 'href' ) ); |
34 | | -// } |
35 | | -// |
36 | | -// public function test_should_show_no_notice_if_api_key_is_set() { |
37 | | -// $this->set_api_key( 'PNG123' ); |
38 | | -// self::$driver->navigate()->refresh(); /* Reload first. */ |
39 | | -// $elements = self::$driver->findElements( WebDriverBy::cssSelector( '.error a' ) ); |
40 | | -// $this->assertEquals( 0, count( $elements ) ); |
41 | | -// } |
42 | | -// |
43 | | -// public function test_no_api_key_notice_should_link_to_settings() { |
44 | | -// self::$driver->findElement( WebDriverBy::cssSelector( '.error a' ) )->click(); |
45 | | -// $this->assertStringEndsWith( 'options-media.php#tiny-compress-images', self::$driver->getCurrentURL() ); |
46 | | -// } |
47 | | -// |
48 | | -// public function test_default_sizes_being_compressed() { |
49 | | -// $elements = self::$driver->findElements( |
50 | | -// WebDriverBy::xpath( '//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]' )); |
51 | | -// $size_ids = array_map( 'elementName', $elements ); |
52 | | -// $this->assertContains( 'tinypng_sizes[0]', $size_ids ); |
53 | | -// $this->assertContains( 'tinypng_sizes[thumbnail]', $size_ids ); |
54 | | -// $this->assertContains( 'tinypng_sizes[medium]', $size_ids ); |
55 | | -// $this->assertContains( 'tinypng_sizes[large]', $size_ids ); |
56 | | -// } |
57 | | -// |
58 | | -// public function test_should_persist_sizes() { |
59 | | -// $element = self::$driver->findElement( WebDriverBy::id( 'tinypng_sizes_medium' ) ); |
60 | | -// $element->click(); |
61 | | -// $element = self::$driver->findElement( WebDriverBy::id( 'tinypng_sizes_0' ) ); |
62 | | -// $element->click(); |
63 | | -// self::$driver->findElement( WebDriverBy::tagName( 'form' ) )->submit(); |
64 | | -// |
65 | | -// $elements = self::$driver->findElements( |
66 | | -// WebDriverBy::xpath( '//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]' )); |
67 | | -// $size_ids = array_map( 'elementName', $elements ); |
68 | | -// $this->assertNotContains( 'tinypng_sizes[0]', $size_ids ); |
69 | | -// $this->assertContains( 'tinypng_sizes[thumbnail]', $size_ids ); |
70 | | -// $this->assertNotContains( 'tinypng_sizes[medium]', $size_ids ); |
71 | | -// $this->assertContains( 'tinypng_sizes[large]', $size_ids ); |
72 | | -// } |
73 | | -// |
74 | | -// public function test_should_persist_no_sizes() { |
75 | | -// $elements = self::$driver->findElements( |
76 | | -// WebDriverBy::xpath( '//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]' )); |
77 | | -// foreach ( $elements as $element ) { |
78 | | -// $element->click(); |
79 | | -// } |
80 | | -// self::$driver->findElement( WebDriverBy::tagName( 'form' ) )->submit(); |
81 | | -// |
82 | | -// $elements = self::$driver->findElements( |
83 | | -// WebDriverBy::xpath( '//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]' )); |
84 | | -// $this->assertEquals( 0, count( array_map( 'elementName', $elements ) ) ); |
85 | | -// } |
86 | | -// |
| 85 | + |
87 | 86 | // public function test_should_show_total_images_info() { |
88 | 87 | // $this->enable_compression_sizes( array( '0', 'thumbnail', 'medium', 'large') ); |
89 | 88 | // $element = self::$driver->findElement( WebDriverBy::id( 'tiny-image-sizes-notice' ) ); |
|
166 | 165 | // WebDriverBy::cssSelector( '#tiny-compress-status p.tiny-update-account-message' ), |
167 | 166 | // 'The key that you have entered is not valid')); |
168 | 167 | // } |
169 | | -// } |
| 168 | +} |
0 commit comments