Delete old draft posts
One of these was causing Sculpin to keep reloading and re-generating the site.
This commit is contained in:
parent
4e8c28c9f3
commit
4d954c75b3
|
@ -1,19 +0,0 @@
|
||||||
---
|
|
||||||
title: 'Building oliverdavies.uk with Sculpin: Part 1 - initial setup and configuration'
|
|
||||||
excerpt: |
|
|
||||||
First part of the "Building oliverdavies.uk" series, covering the initial
|
|
||||||
Sculpin setup and configuration.
|
|
||||||
tags: [sculpin]
|
|
||||||
draft: true
|
|
||||||
date: ~
|
|
||||||
---
|
|
||||||
|
|
||||||
Based on <https://github.com/opdavies/sculpin-skeleton>.
|
|
||||||
|
|
||||||
Uses <https://github.com/opdavies/docker-image-sculpin-serve>.
|
|
||||||
|
|
||||||
`app/config/sculpin_kernel.yml`:
|
|
||||||
|
|
||||||
`app/config/sculpin_site.yml`:
|
|
||||||
|
|
||||||
`app/config/sculpin_site_prod.yml`:
|
|
|
@ -1,70 +0,0 @@
|
||||||
---
|
|
||||||
title: Configuring the Reroute Email Module
|
|
||||||
date: 2014-12-22
|
|
||||||
excerpt:
|
|
||||||
How to configure the Reroute Email module, to prevent sending emails to real
|
|
||||||
users from your pre-production sites!
|
|
||||||
tags:
|
|
||||||
- drupal
|
|
||||||
- drupal-6
|
|
||||||
- drupal-7
|
|
||||||
- drupal-planet
|
|
||||||
- email
|
|
||||||
draft: true
|
|
||||||
---
|
|
||||||
|
|
||||||
[Reroute Email](https://www.drupal.org/project/reroute_email) module uses
|
|
||||||
`hook_mail_alter()` to prevent emails from being sent to users from
|
|
||||||
non-production sites. It allows you to enter one or more email addresses that
|
|
||||||
will receive the emails instead of delivering them to the original user.
|
|
||||||
|
|
||||||
> This is useful in case where you do not want email sent from a Drupal site to
|
|
||||||
> reach the users. For example, if you copy a live site to a test site for the
|
|
||||||
> purpose of development, and you do not want any email sent to real users of
|
|
||||||
> the original site. Or you want to check the emails sent for uniform
|
|
||||||
> formatting, footers, ...etc.
|
|
||||||
|
|
||||||
As we don't need the module configured on production (we don't need to reroute
|
|
||||||
any emails there), it's best to do this in code using settings.local.php (if you
|
|
||||||
have one) or the standard settings.php file.
|
|
||||||
|
|
||||||
The first thing that we need to do is to enable rerouting. Without doing this,
|
|
||||||
nothing will happen.
|
|
||||||
|
|
||||||
```php
|
|
||||||
$conf['reroute_email_enable'] = TRUE;
|
|
||||||
```
|
|
||||||
|
|
||||||
The next option is to whether to show rerouting description in mail body. I
|
|
||||||
usually have this enabled. Set this to TRUE or FALSE depending on your
|
|
||||||
preference.
|
|
||||||
|
|
||||||
```php
|
|
||||||
$conf['reroute_email_enable_message'] = TRUE;
|
|
||||||
```
|
|
||||||
|
|
||||||
The last setting is the email address to use. If you're entering a single
|
|
||||||
address, you can add it as a simple string.
|
|
||||||
|
|
||||||
```php
|
|
||||||
$conf['reroute_email_address'] = 'person1@example.com';
|
|
||||||
```
|
|
||||||
|
|
||||||
In this example, all emails from the site will be rerouted to
|
|
||||||
person1@example.com.
|
|
||||||
|
|
||||||
If you want to add multiple addresses, these should be added in a
|
|
||||||
semicolon-delimited list. Whilst you could add these also as a string, I prefer
|
|
||||||
to use an array of addresses and the `implode()` function.
|
|
||||||
|
|
||||||
```php
|
|
||||||
$conf['reroute_email_address'] = implode(';', array(
|
|
||||||
'person1@example.com',
|
|
||||||
'person2@example.com',
|
|
||||||
'person3@example.com',
|
|
||||||
));
|
|
||||||
```
|
|
||||||
|
|
||||||
In this example, person2@example.com and person3@example.com would receive their
|
|
||||||
emails from the site as normal. Any emails to addresses not in the array would
|
|
||||||
continue to be redirected to person1@example.com.
|
|
|
@ -1,102 +0,0 @@
|
||||||
---
|
|
||||||
title: Debugging PHP in Docker with Xdebug, Neovim and DAP
|
|
||||||
date: ~
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- neovim
|
|
||||||
- dap
|
|
||||||
- xdebug
|
|
||||||
- php
|
|
||||||
- drupal
|
|
||||||
draft: true
|
|
||||||
---
|
|
||||||
|
|
||||||
I've been a full-time Neovim user for a year at the time of writing this post and whilst I was a semi-regular Xdebug user, it's something that I've managed to work around and have mostly resorted to `var_dump()`, `dump()`, or `dd()` instead for debugging.
|
|
||||||
|
|
||||||
This week though, whilst working on some particularly tricky PHP code, I decided to spend some time and get Xdebug working and be able to use a step debugger within Neovim.
|
|
||||||
|
|
||||||
https://gist.githubusercontent.com/opdavies/688a3c8917893bf34a3da32ff69c1837/raw/112e16634930d312cd04c525de42a198c8a32bb9/dap.lua
|
|
||||||
|
|
||||||
## Installing Xdebug
|
|
||||||
|
|
||||||
Installing Xdebug itself within Docker was straight forward. I was able to add two lines to my existing `RUN` command - `pecl install xdebug` to install the extension and `docker-php-ext-enable xdebug` to enable it.
|
|
||||||
|
|
||||||
Now when I run `php -v` inside my container, I can see that it mentions Xdebug.
|
|
||||||
|
|
||||||
## Configuring Xdebug
|
|
||||||
|
|
||||||
https://www.youtube.com/watch?v=ZIGdBSD6zvU
|
|
||||||
|
|
||||||
```
|
|
||||||
xdebug.mode=develop,debug
|
|
||||||
xdebug.client_host=host.docker.internal
|
|
||||||
xdebug.discover_client_host=0
|
|
||||||
xdebug.output_dir=/tmp/xdebug
|
|
||||||
xdebug.log=/tmp/xdebug/xdebug-example.log
|
|
||||||
xdebug.start_with_request=yes
|
|
||||||
```
|
|
||||||
## Installing DAP plugins
|
|
||||||
|
|
||||||
I use [Packer](https://github.com/wbthomason/packer.nvim) for managing my Neovim plugins so I needed to install some additional ones to add the DAP (debug adapter protocol) functionality.
|
|
||||||
|
|
||||||
```lua
|
|
||||||
use "mfussenegger/nvim-dap"
|
|
||||||
use "rcarriga/nvim-dap-ui"
|
|
||||||
use "theHamsta/nvim-dap-virtual-text"
|
|
||||||
use "nvim-telescope/telescope-dap.nvim"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installing DAP dependencies
|
|
||||||
|
|
||||||
[https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#PHP](https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#PHP)
|
|
||||||
|
|
||||||
There's also a prerequisite for install the `vscode-php-debug` adapter.
|
|
||||||
|
|
||||||
I configure my laptop with Ansible, so I added a new `debugger` role that is responsible for cloning this repository and installing its contents:
|
|
||||||
|
|
||||||
[https://github.com/opdavies/dotfiles/blob/7681c535269049556736f1f857c8c9fd800857a3/roles/debugger/tasks/php.yaml](https://github.com/opdavies/dotfiles/blob/7681c535269049556736f1f857c8c9fd800857a3/roles/debugger/tasks/php.yaml)
|
|
||||||
|
|
||||||
## Configuring DAP for Xdebug
|
|
||||||
|
|
||||||
```lua
|
|
||||||
dap.adapters.php = {
|
|
||||||
type = "executable",
|
|
||||||
command = "node",
|
|
||||||
args = { os.getenv("HOME") .. "/build/vscode-php-debug/out/phpDebug.js" }
|
|
||||||
}
|
|
||||||
|
|
||||||
dap.configurations.php = {
|
|
||||||
{
|
|
||||||
type = "php",
|
|
||||||
request = "launch",
|
|
||||||
name = "Listen for Xdebug",
|
|
||||||
port = 9003,
|
|
||||||
pathMappings = {
|
|
||||||
["/var/www/html"] = "${workspaceFolder}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
I first needed to configure the adapter to use `vscode-php-debug` and then add a DAP configuration.
|
|
||||||
|
|
||||||
The default port for the step debugger is now 9003 rather than 9000 so I changed this from the default, and as I'm working with PHP inside a container, I also added a path mapping so that my code could be found.
|
|
||||||
|
|
||||||
## Testing the connection
|
|
||||||
|
|
||||||
> [Step Debug] Creating socket for 'host.docker.internal:9003', getaddrinfo: Invalid argument.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
php:
|
|
||||||
volumes:
|
|
||||||
- "/tmp/xdebug:/tmp/xdebug"
|
|
||||||
extra_hosts:
|
|
||||||
- "host.docker.internal:host-gateway"
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
keymaps:
|
|
||||||
|
|
||||||
https://github.com/opdavies/docker-drupal-example
|
|
|
@ -1,49 +0,0 @@
|
||||||
---
|
|
||||||
title: Finding the last commit that a patch applies to
|
|
||||||
excerpt: How to find the last commit in a Git repository that a patch applies to.
|
|
||||||
date: 2020-03-26
|
|
||||||
tags:
|
|
||||||
- bash
|
|
||||||
- git
|
|
||||||
draft: true
|
|
||||||
---
|
|
||||||
|
|
||||||
```bash
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# https://www.drupal.org/files/issues/2018-08-28/group-configurable-entities-as-group-content-2797793-58.patch
|
|
||||||
|
|
||||||
patch_filename=group-configurable-entities-as-group-content-2797793-58.patch
|
|
||||||
first_commit=6e8c22a
|
|
||||||
last_commit=8.x-1.x
|
|
||||||
|
|
||||||
find_commits_between() {
|
|
||||||
first_commit=$1
|
|
||||||
last_commit=$2
|
|
||||||
|
|
||||||
git rev-list --reverse --ancestry-path $first_commit^...$last_commit
|
|
||||||
}
|
|
||||||
|
|
||||||
reset_repo() {
|
|
||||||
git reset --hard $1 >& /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
apply_patch() {
|
|
||||||
git apply --check $patch_filename >& /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
for sha1 in $(find_commits_between $first_commit $last_commit); do
|
|
||||||
echo "Trying ${sha1}..."
|
|
||||||
|
|
||||||
reset_repo $sha1
|
|
||||||
apply_patch
|
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
echo "Patch applies"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Patch does not apply"
|
|
||||||
exit 1
|
|
||||||
done
|
|
||||||
```
|
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
title: test
|
|
||||||
draft: true
|
|
||||||
date: ~
|
|
||||||
---
|
|
|
@ -1,163 +0,0 @@
|
||||||
---
|
|
||||||
title: Rebuilding Acquia’s Dashboard with Vue.js and Tailwind CSS
|
|
||||||
excerpt: How I rebuilt Acquia’s dashboard using Vue.js and Tailwind CSS.
|
|
||||||
tags:
|
|
||||||
- drupal
|
|
||||||
- tailwind-css
|
|
||||||
- tweet
|
|
||||||
- vuejs
|
|
||||||
draft: true
|
|
||||||
date: ~
|
|
||||||
promoted: true
|
|
||||||
---
|
|
||||||
|
|
||||||
After
|
|
||||||
[rebuilding Drupal’s Bartik theme](/blog/rebuilding-bartik-with-vuejs-tailwind-css),
|
|
||||||
I’ve now used [Vue.js][vue] and [Tailwind CSS][tailwind] to rebuild another
|
|
||||||
Drupal related UI - this time it’s [Acquia’s](https://www.acquia.com) web
|
|
||||||
hosting dashboard. Again, you can [view the site on Netlify][netlify] and [the
|
|
||||||
code on GitHub][github].
|
|
||||||
|
|
||||||
## Why?
|
|
||||||
|
|
||||||
The same as the Bartik rebuild, this was a good opportunity for me to gain more
|
|
||||||
experience with new technologies - Vue in particular - and to provide another
|
|
||||||
demonstration of how Tailwind CSS can be used.
|
|
||||||
|
|
||||||
Like the Bartik clone, this was originally going to be another single page
|
|
||||||
rebuild, however after completing the first page I decided to expand it to
|
|
||||||
include three pages which also gave me the opportunity to use
|
|
||||||
[Vue Router](https://router.vuejs.org) - something that I had not used
|
|
||||||
previously - and to organise a multi-page Vue application.
|
|
||||||
|
|
||||||
## Configuring Vue Router
|
|
||||||
|
|
||||||
`src/router/index.js`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
import Vue from 'vue';
|
|
||||||
import Router from 'vue-router';
|
|
||||||
import Applications from '@/views/Applications';
|
|
||||||
import Environment from '@/views/Environment';
|
|
||||||
import Environments from '@/views/Environments';
|
|
||||||
|
|
||||||
Vue.use(Router);
|
|
||||||
|
|
||||||
export default new Router({
|
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
path: '/',
|
|
||||||
name: 'applications',
|
|
||||||
component: Applications,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/:id/environments',
|
|
||||||
name: 'environments',
|
|
||||||
component: Environments,
|
|
||||||
props: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/:id/environments/:environmentName',
|
|
||||||
name: 'environment',
|
|
||||||
component: Environment,
|
|
||||||
props: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Passing in data
|
|
||||||
|
|
||||||
`src/data.json`
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"applications": {
|
|
||||||
"1": {
|
|
||||||
"id": 1,
|
|
||||||
"name": "Rebuilding Acquia",
|
|
||||||
"machineName": "rebuildingacquia",
|
|
||||||
"type": "Drupal",
|
|
||||||
"level": "Enterprise",
|
|
||||||
"environments": {
|
|
||||||
"dev": {
|
|
||||||
"name": "Dev",
|
|
||||||
"url": "dev.rebuilding-acquia.com",
|
|
||||||
"label": "develop"
|
|
||||||
},
|
|
||||||
"stage": {
|
|
||||||
"name": "Stage",
|
|
||||||
"url": "stg.rebuilding-acquia.com",
|
|
||||||
"label": "master"
|
|
||||||
},
|
|
||||||
"prod": {
|
|
||||||
"name": "Prod",
|
|
||||||
"url": "rebuilding-acquia.com",
|
|
||||||
"label": "tags/2018-12-21"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"text": "Commit: fdac923 Merge branch 'update-password-policy' refs/heads/master",
|
|
||||||
"user": "system",
|
|
||||||
"times": {
|
|
||||||
"display": "Dec 19, 2018 3:48:29 PM UTC +0000",
|
|
||||||
"started": "Dec 19, 2018 3:48:29 PM UTC +0000",
|
|
||||||
"completed": "Dec 19, 2018 3:48:29 PM UTC +0000"
|
|
||||||
},
|
|
||||||
"loading": false,
|
|
||||||
"success": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## The Environments page
|
|
||||||
|
|
||||||
This was the first page that I rebuilt - the Environments page for an
|
|
||||||
application that shows the information of the different configured environments.
|
|
||||||
|
|
||||||
Vue Router is configured to show the
|
|
||||||
|
|
||||||
{% include 'figure' with {
|
|
||||||
image: {
|
|
||||||
src: '/images/blog/rebuilding-acquia-vue-tailwind/3-environments.png',
|
|
||||||
alt: 'A screenshot of the rebuilt Environments page.',
|
|
||||||
},
|
|
||||||
caption: 'The rebuilt Environments page for an application.',
|
|
||||||
} %}
|
|
||||||
|
|
||||||
## The applications page
|
|
||||||
|
|
||||||
{% include 'figure' with {
|
|
||||||
image: {
|
|
||||||
src: '/images/blog/rebuilding-acquia-vue-tailwind/1-applications-grid.png',
|
|
||||||
alt: 'The rebuild Applications page, with applications displayed in a grid.',
|
|
||||||
},
|
|
||||||
caption: 'The rebuilt Applications page - grid view',
|
|
||||||
} %}
|
|
||||||
|
|
||||||
{% include 'figure' with {
|
|
||||||
image: {
|
|
||||||
src: '/images/blog/rebuilding-acquia-vue-tailwind/2-applications-list.png',
|
|
||||||
alt: 'The rebuild Applications page, with applications displayed as a list.',
|
|
||||||
},
|
|
||||||
caption: 'The rebuilt Applications page - list view',
|
|
||||||
} %}
|
|
||||||
|
|
||||||
## An environment page
|
|
||||||
|
|
||||||
{% include 'figure' with {
|
|
||||||
image: {
|
|
||||||
src: '/images/blog/rebuilding-acquia-vue-tailwind/4-environment.png',
|
|
||||||
alt: 'A screenshot of the rebuilt Environment page.',
|
|
||||||
},
|
|
||||||
caption: 'The rebuilt page for an environment within an application.',
|
|
||||||
} %}
|
|
||||||
|
|
||||||
[github]: https://github.com/opdavies/rebuilding-acquia
|
|
||||||
[netlify]: https://rebuilding-acquia.oliverdavies.uk
|
|
||||||
[tailwind]: https://tailwindcss.com
|
|
||||||
[vue]: https://vuejs.org
|
|
|
@ -1,239 +0,0 @@
|
||||||
---
|
|
||||||
title: Updating Override Node Options Tests
|
|
||||||
date: 2017-05-05
|
|
||||||
excerpt: ~
|
|
||||||
tags:
|
|
||||||
- drupal
|
|
||||||
- drupal-modules
|
|
||||||
- drupal-planet
|
|
||||||
- testing
|
|
||||||
draft: true
|
|
||||||
---
|
|
||||||
|
|
||||||
Recently, I reviewed [a patch][1] in the [Override Node Options][2] module issue
|
|
||||||
queue. For those not familiar with it, the module adds extra permissions for
|
|
||||||
node options like "authored by" and "published on" which are normally only
|
|
||||||
available to users with the `administer nodes` permission. What the patch does
|
|
||||||
is to optionally add another set of permissions that enable options for all
|
|
||||||
content types - e.g. "override published option for all node types", in addition
|
|
||||||
to or instead of the content type specific ones.
|
|
||||||
|
|
||||||
It was quite an old issue and the latest patch needed to be re-rolled due to
|
|
||||||
merge conflicts, but the existing tests still passed. Though as no new tests
|
|
||||||
were added for the new functionality, these needed to be added before I
|
|
||||||
committed it.
|
|
||||||
|
|
||||||
## Reviewing the Existing Tests
|
|
||||||
|
|
||||||
The first thing to do was to run the existing tests and check that they still
|
|
||||||
passed. I do this on the command line by typing
|
|
||||||
`php scripts/run-tests.sh --class OverrideNodeOptionsTestCase`.
|
|
||||||
|
|
||||||
```
|
|
||||||
Drupal test run
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Tests to be run:
|
|
||||||
- Override node options (OverrideNodeOptionsTestCase)
|
|
||||||
|
|
||||||
Test run started:
|
|
||||||
Saturday, April 29, 2017 - 14:44
|
|
||||||
|
|
||||||
Test summary
|
|
||||||
------------
|
|
||||||
|
|
||||||
Override node options 142 passes, 0 fails, 0 exceptions, and 38 debug messages
|
|
||||||
|
|
||||||
Test run duration: 32 sec
|
|
||||||
```
|
|
||||||
|
|
||||||
After confirming that the existing tests still passed, I reviewed them to see
|
|
||||||
what could be re-used.
|
|
||||||
|
|
||||||
This is one of the original tests:
|
|
||||||
|
|
||||||
```php
|
|
||||||
/**
|
|
||||||
* Test the 'Authoring information' fieldset.
|
|
||||||
*/
|
|
||||||
protected function testNodeOptions() {
|
|
||||||
$this->adminUser = $this->drupalCreateUser(array(
|
|
||||||
'create page content',
|
|
||||||
'edit any page content',
|
|
||||||
'override page published option',
|
|
||||||
'override page promote to front page option',
|
|
||||||
'override page sticky option',
|
|
||||||
'override page comment setting option',
|
|
||||||
));
|
|
||||||
$this->drupalLogin($this->adminUser);
|
|
||||||
|
|
||||||
$fields = array(
|
|
||||||
'status' => (bool) !$this->node->status,
|
|
||||||
'promote' => (bool) !$this->node->promote,
|
|
||||||
'sticky' => (bool) !$this->node->sticky,
|
|
||||||
'comment' => COMMENT_NODE_OPEN,
|
|
||||||
);
|
|
||||||
$this->drupalPost('node/' . $this->node->nid . '/edit', $fields, t('Save'));
|
|
||||||
$this->assertNodeFieldsUpdated($this->node, $fields);
|
|
||||||
|
|
||||||
$this->drupalLogin($this->normalUser);
|
|
||||||
$this->assertNodeFieldsNoAccess($this->node, array_keys($fields));
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The first part of the test is creating and logging in a user with some content
|
|
||||||
type specific override permissions (`$this->adminUser`), and then testing that
|
|
||||||
the fields were updated when the node is saved. The second part is testing that
|
|
||||||
the fields are not visible for a normal user without the extra permissions
|
|
||||||
(`$this->normalUser`), which is created in the `setUp()` class' method.
|
|
||||||
|
|
||||||
To test the new "all types" permissions, I created another user to test against
|
|
||||||
called `$generalUser` and run the first part of the tests in a loop.
|
|
||||||
|
|
||||||
## Beginning to Refactor the Tests
|
|
||||||
|
|
||||||
With the tests passing, I was able to start refactoring.
|
|
||||||
|
|
||||||
```php
|
|
||||||
// Create a new user with content type specific permissions.
|
|
||||||
$specificUser = $this->drupalCreateUser(array(
|
|
||||||
'create page content',
|
|
||||||
'edit any page content',
|
|
||||||
'override page published option',
|
|
||||||
'override page promote to front page option',
|
|
||||||
'override page sticky option',
|
|
||||||
'override page comment setting option',
|
|
||||||
));
|
|
||||||
|
|
||||||
foreach (array($specificUser) as $account) {
|
|
||||||
$this->drupalLogin($account);
|
|
||||||
|
|
||||||
// Test all the things.
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
I started with a small change, renaming `$this->adminUser` to `$specificUser` to
|
|
||||||
make it clearer what permissions it had, and moving the tests into a loop so
|
|
||||||
that the tests can be repeated for both users.
|
|
||||||
|
|
||||||
After that change, I ran the tests again to check that everything still worked.
|
|
||||||
|
|
||||||
## Adding Failing Tests
|
|
||||||
|
|
||||||
The next step is to start testing the new permissions.
|
|
||||||
|
|
||||||
```php
|
|
||||||
...
|
|
||||||
|
|
||||||
$generalUser = $this->drupalCreateUser(array());
|
|
||||||
|
|
||||||
foreach (array($specificUser, $generalUser) as $account) {
|
|
||||||
$this->drupalLogin($account);
|
|
||||||
|
|
||||||
// Test all the things.
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
I added a new `$generalUser` to test the general permissions and added to the
|
|
||||||
loop, but in order to see the tests failing intially I assigned it no
|
|
||||||
permissions. When running the tests again, 6 tests have failed.
|
|
||||||
|
|
||||||
```
|
|
||||||
Test summary
|
|
||||||
------------
|
|
||||||
|
|
||||||
Override node options 183 passes, 6 fails, 0 exceptions, and 49 debug messages
|
|
||||||
|
|
||||||
Test run duration: 28 sec
|
|
||||||
```
|
|
||||||
|
|
||||||
Then it was a case of re-adding more permissions to the user and seeing the
|
|
||||||
number of failures decrease, confirming that the functionality was working
|
|
||||||
correctly.
|
|
||||||
|
|
||||||
TODO: Add another example.
|
|
||||||
|
|
||||||
## Gotchas
|
|
||||||
|
|
||||||
There was a bug that I found where a permission was added, but wasn't used
|
|
||||||
within the implementation code. After initially expecting the test to pass after
|
|
||||||
adding the permission to `$generalUser` and the test still failed, I noticed
|
|
||||||
that the
|
|
||||||
|
|
||||||
This was fixed by adding the extra code into `override_node_options.module`.
|
|
||||||
|
|
||||||
```diff
|
|
||||||
- $form['comment_settings']['#access'] |= user_access('override ' . $node->type . ' comment setting option');
|
|
||||||
+ $form['comment_settings']['#access'] |= user_access('override ' . $node->type . ' comment setting option') || user_access('override all comment setting option');
|
|
||||||
```
|
|
||||||
|
|
||||||
The other issue that I found was within `testNodeRevisions`.
|
|
||||||
`assertNodeFieldsUpdated()` was failing after being put in a loop as the `vid`
|
|
||||||
was not the same as what was expected.
|
|
||||||
|
|
||||||
Note: You can get more verbose output from `run-tests.sh` by adding the
|
|
||||||
`--verbose` option.
|
|
||||||
|
|
||||||
> Node vid was updated to '3', expected 2.
|
|
||||||
|
|
||||||
```diff
|
|
||||||
- $fields = array(
|
|
||||||
- 'revision' => TRUE,
|
|
||||||
- );
|
|
||||||
- $this->drupalPost('node/' . $this->node->nid . '/edit', $fields, t('Save'));
|
|
||||||
- $this->assertNodeFieldsUpdated($this->node, array('vid' => $this->node->vid + 1));
|
|
||||||
+ $generalUser = $this->drupalCreateUser(array(
|
|
||||||
+ 'create page content',
|
|
||||||
+ 'edit any page content',
|
|
||||||
+ 'override all revision option',
|
|
||||||
+ ));
|
|
||||||
+
|
|
||||||
+ foreach (array($specificUser, $generalUser) as $account) {
|
|
||||||
+ $this->drupalLogin($account);
|
|
||||||
+
|
|
||||||
+ // Ensure that we have the latest node data.
|
|
||||||
+ $node = node_load($this->node->nid, NULL, TRUE);
|
|
||||||
+
|
|
||||||
+ $fields = array(
|
|
||||||
+ 'revision' => TRUE,
|
|
||||||
+ );
|
|
||||||
+ $this->drupalPost('node/' . $node->nid . '/edit', $fields, t('Save'));
|
|
||||||
+ $this->assertNodeFieldsUpdated($node, array('vid' => $node->vid + 1));
|
|
||||||
+ }
|
|
||||||
```
|
|
||||||
|
|
||||||
The crucial part of this change was the addition of
|
|
||||||
`$node = node_load($this->node->nid, NULL, TRUE);` to ensure that the latest
|
|
||||||
version of the node was loaded during each loop.
|
|
||||||
|
|
||||||
## Conclusion
|
|
||||||
|
|
||||||
- Ensure that the existing tests were passing before starting to refactor.
|
|
||||||
- Start with small changes and continue to run the tests to ensure that nothing
|
|
||||||
has broken.
|
|
||||||
- After the first change, I committed it as `WIP: Refactoring tests`, and used
|
|
||||||
`git commit --amend --no-edit` to amend that commit each time I had refactored
|
|
||||||
another test. After the last refactor, I updated the commit message.
|
|
||||||
- It’s important to see tests failing before making them pass. This was achieved
|
|
||||||
by initially assigning no permissions to `$generalUser` so that the fails
|
|
||||||
failed and then added permissions and re-run the tests to ensure that the
|
|
||||||
failure count decreased with each new permission.
|
|
||||||
|
|
||||||
With the refactoring complete, the number of passing tests increased from 142
|
|
||||||
to 213.
|
|
||||||
|
|
||||||
```
|
|
||||||
Override node options 213 passes, 0 fails, 0 exceptions, and 60 debug messages
|
|
||||||
|
|
||||||
Test run duration: 25 sec
|
|
||||||
```
|
|
||||||
|
|
||||||
<img src="/images/blog/override-node-options-refactor-tests-new-passing.png" alt="">
|
|
||||||
|
|
||||||
[Here][3] are my full changes from the previous patch, where I added the new
|
|
||||||
tests as well as some small refactors.
|
|
||||||
|
|
||||||
[1]: https://www.drupal.org/node/974730
|
|
||||||
[2]: https://www.drupal.org/project/override_node_options
|
|
||||||
[3]: https://www.drupal.org/files/issues/interdiff_25712.txt
|
|
|
@ -1,13 +0,0 @@
|
||||||
---
|
|
||||||
title: Using feature flags in Drupal development
|
|
||||||
excerpt: Different ways of using feature flags witin Drupal development
|
|
||||||
date: 2020-03-31
|
|
||||||
tags:
|
|
||||||
- drupal
|
|
||||||
- drupal-7
|
|
||||||
- drupal-8
|
|
||||||
- php
|
|
||||||
draft: true
|
|
||||||
---
|
|
||||||
|
|
||||||
TODO.
|
|
|
@ -1,64 +0,0 @@
|
||||||
---
|
|
||||||
title: Using Traefik as a local proxy with Sculpin
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- sculpin
|
|
||||||
draft: true
|
|
||||||
date: ~
|
|
||||||
---
|
|
||||||
|
|
||||||
<https://github.com/opdavies/oliverdavies.uk/commit/17626df722408f32c2153e485296092675e23024#diff-3fde9d1a396e140fefc7676e1bd237d67b6864552b6f45af1ebcc27bcd0bb6e9>
|
|
||||||
|
|
||||||
## Before
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: tools/docker/images/Dockerfile
|
|
||||||
target: app
|
|
||||||
volumes:
|
|
||||||
- assets:/app/source/build
|
|
||||||
- /app/output_dev
|
|
||||||
- .:/app
|
|
||||||
ports:
|
|
||||||
- 8000:8000
|
|
||||||
```
|
|
||||||
|
|
||||||
## Adding the proxy service
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
proxy:
|
|
||||||
image: traefik:v2.0-alpine
|
|
||||||
command:
|
|
||||||
- --api.insecure=true
|
|
||||||
- --providers.docker
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
ports:
|
|
||||||
- 80:80
|
|
||||||
- 8080:8080
|
|
||||||
labels:
|
|
||||||
- "traefik.enable=false"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Updating the app service
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
app:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: tools/docker/images/Dockerfile
|
|
||||||
target: app
|
|
||||||
expose:
|
|
||||||
- 80
|
|
||||||
command: [generate, --server, --watch, --port, '80', --url, http://oliverdavies.localhost]
|
|
||||||
volumes:
|
|
||||||
- assets:/app/source/build
|
|
||||||
- /app/output_dev
|
|
||||||
- .:/app
|
|
||||||
labels:
|
|
||||||
- "traefik.http.routers.oliverdavies.rule=Host(`oliverdavies.localhost`)"
|
|
||||||
```
|
|
|
@ -1,32 +0,0 @@
|
||||||
---
|
|
||||||
title: 'Weeknotes: August 6th'
|
|
||||||
excerpt: TODO
|
|
||||||
tags:
|
|
||||||
- personal
|
|
||||||
- week-notes
|
|
||||||
draft: true
|
|
||||||
date: ~
|
|
||||||
---
|
|
||||||
|
|
||||||
## Vim
|
|
||||||
|
|
||||||
- https://gist.github.com/opdavies/f944261b54f70b43f2297cab6779cf59
|
|
||||||
- surround.vim - https://github.com/tpope/vim-surround
|
|
||||||
- https://towardsdatascience.com/how-i-learned-to-enjoy-vim-e310e53e8d56
|
|
||||||
|
|
||||||
## Re-watching invoice.space streams
|
|
||||||
|
|
||||||
https://www.youtube.com/playlist?list=PLasJXc7CbyYfsdXu6t0406-kGwDN8aUG9
|
|
||||||
|
|
||||||
## Trialing Conventional Commits
|
|
||||||
|
|
||||||
https://nitayneeman.com/posts/understanding-semantic-commit-messages-using-git-and-angular
|
|
||||||
|
|
||||||
https://www.conventionalcommits.org/en/v1.0.0-beta.2
|
|
||||||
|
|
||||||
https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines
|
|
||||||
|
|
||||||
https://github.com/vuejs/vue/commits/dev
|
|
||||||
https://github.com/vuejs/vue-cli/commits/dev
|
|
||||||
|
|
||||||
https://github.com/pestphp/pest-intellij/commits/main
|
|
Loading…
Reference in a new issue