Mercurial > hg > isophonics-drupal-site
comparison core/modules/ban/tests/src/Functional/IpAddressBlockingTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
26 public function testIPAddressValidation() { | 26 public function testIPAddressValidation() { |
27 // Create user. | 27 // Create user. |
28 $admin_user = $this->drupalCreateUser(['ban IP addresses']); | 28 $admin_user = $this->drupalCreateUser(['ban IP addresses']); |
29 $this->drupalLogin($admin_user); | 29 $this->drupalLogin($admin_user); |
30 $this->drupalGet('admin/config/people/ban'); | 30 $this->drupalGet('admin/config/people/ban'); |
31 $connection = Database::getConnection(); | |
31 | 32 |
32 // Ban a valid IP address. | 33 // Ban a valid IP address. |
33 $edit = []; | 34 $edit = []; |
34 $edit['ip'] = '1.2.3.3'; | 35 $edit['ip'] = '1.2.3.3'; |
35 $this->drupalPostForm('admin/config/people/ban', $edit, t('Add')); | 36 $this->drupalPostForm('admin/config/people/ban', $edit, t('Add')); |
76 // $this->drupalPostForm('admin/config/people/ban', $edit, t('Save')); | 77 // $this->drupalPostForm('admin/config/people/ban', $edit, t('Save')); |
77 // $this->assertText(t('You may not ban your own IP address.')); | 78 // $this->assertText(t('You may not ban your own IP address.')); |
78 | 79 |
79 // Test duplicate ip address are not present in the 'blocked_ips' table. | 80 // Test duplicate ip address are not present in the 'blocked_ips' table. |
80 // when they are entered programmatically. | 81 // when they are entered programmatically. |
81 $connection = Database::getConnection(); | |
82 $banIp = new BanIpManager($connection); | 82 $banIp = new BanIpManager($connection); |
83 $ip = '1.0.0.0'; | 83 $ip = '1.0.0.0'; |
84 $banIp->banIp($ip); | 84 $banIp->banIp($ip); |
85 $banIp->banIp($ip); | 85 $banIp->banIp($ip); |
86 $banIp->banIp($ip); | 86 $banIp->banIp($ip); |
87 $query = db_select('ban_ip', 'bip'); | 87 $query = $connection->select('ban_ip', 'bip'); |
88 $query->fields('bip', ['iid']); | 88 $query->fields('bip', ['iid']); |
89 $query->condition('bip.ip', $ip); | 89 $query->condition('bip.ip', $ip); |
90 $ip_count = $query->execute()->fetchAll(); | 90 $ip_count = $query->execute()->fetchAll(); |
91 $this->assertEqual(1, count($ip_count)); | 91 $this->assertEqual(1, count($ip_count)); |
92 $ip = ''; | 92 $ip = ''; |
93 $banIp->banIp($ip); | 93 $banIp->banIp($ip); |
94 $banIp->banIp($ip); | 94 $banIp->banIp($ip); |
95 $query = db_select('ban_ip', 'bip'); | 95 $query = $connection->select('ban_ip', 'bip'); |
96 $query->fields('bip', ['iid']); | 96 $query->fields('bip', ['iid']); |
97 $query->condition('bip.ip', $ip); | 97 $query->condition('bip.ip', $ip); |
98 $ip_count = $query->execute()->fetchAll(); | 98 $ip_count = $query->execute()->fetchAll(); |
99 $this->assertEqual(1, count($ip_count)); | 99 $this->assertEqual(1, count($ip_count)); |
100 } | 100 } |