Here's a version which uses append after command
in the definition of blackcorner
to draw the 4 corners.
The size can be configured using size=<dimension>
in an optional argument to blackcorner
which may also include other options for the corner nodes, if desired. Despite the name, one of the examples below shows how to create blue blackcorner
s.
To increase the margin between text and corners, simply add inner sep=<dimension>
to the options for the node. Note: not as options for blackcorner
- you don't want to change it there. You want to increase the margin for the main node, so the border is further from the text.
The upshot of all this is that
\tikz{%
\node [blackcorner] {test};
\node [blackcorner={size=2.5pt}, inner sep=5pt, blue] at (0,1) {test};
\node [blackcorner={size=2.5pt, blue}, inner sep=5pt, blue] at (0,2) {test};
}
produces three nodes: the bottom node has the default spacing and corner size, all in black; the middle node is blue with larger corners and margin, but the default black is still used for the corners; finally, the top node also changes the corners' colour to blue.

Complete code:
\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikzset{%
blackcorner/.style={%
draw,
append after command={%
let \p1=(\tikzlastnode.south west), \p2=(\tikzlastnode.north west), \p3=(\tikzlastnode.north east), \p4=(\tikzlastnode.south east) in (\p1) node [black corner/.cd, #1, corner, anchor=south west] {} (\p2) node [black corner/.cd, #1, corner, anchor=north west] {} (\p3) node [black corner/.cd, #1, corner, anchor=north east] {} (\p4) node [black corner/.cd, #1, corner, anchor=south east] {}
},
},
black corner/.search also={/tikz},
black corner/.cd,
corner/.style={%
inner sep=0pt, draw, fill, minimum size=\cornersize,
},
size/.store in=\cornersize,
size=1.8pt,
}
\tikz{%
\node [blackcorner] {test};
\node [blackcorner={size=2.5pt}, inner sep=5pt, blue] at (0,1) {test};
\node [blackcorner={size=2.5pt, blue}, inner sep=5pt, blue] at (0,2) {test};
}
\end{document}
inner xsep=10pt